-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
47 lines (37 loc) · 891 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { test } from "uvu";
import { equal } from "uvu/assert";
import "./index.js";
import { compile } from "json-logic-js-jit";
test("log", () => {
const fn = compile({ log: [1, 2] });
fn(3);
});
test("var object", () => {
const fn = compile({ var: ["fruit"] });
equal(fn({ fruit: "apple" }), "apple");
});
test("var array", () => {
const fn = compile({ var: [1] });
equal(fn(["apple", "banana"]), "banana");
});
test("var void", () => {
const fn = compile({ var: [0] });
equal(fn([]), void 0);
});
test("if true", () => {
const fn = compile({ if: [true, 1, 0] });
equal(fn(), 1);
});
test("if false", () => {
const fn = compile({ if: [false, 1, 0] });
equal(fn(), 0);
});
test("max", () => {
const fn = compile({ max: [0, 2, 1] });
equal(fn(), 2);
});
test("min", () => {
const fn = compile({ min: [-1, 2, 1] });
equal(fn(), -1);
});
test.run();