mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
130 lines
1.6 KiB
Plaintext
130 lines
1.6 KiB
Plaintext
// Simple Comparisons
|
|
let one = 1;
|
|
let two = 2;
|
|
let foo = "foo";
|
|
let bar = "bar";
|
|
let tpl1 = {
|
|
foo = "bar",
|
|
one = 1
|
|
};
|
|
let tpl2 = tpl1{};
|
|
let tpl3 = {
|
|
bar = "foo",
|
|
two = 1
|
|
};
|
|
let list = [1, 2, 3];
|
|
let list2 = list;
|
|
let list3 = [1, 2];
|
|
|
|
assert |
|
|
one == one;
|
|
|;
|
|
assert |
|
|
one == one;
|
|
|;
|
|
assert |
|
|
one >= one;
|
|
|;
|
|
assert |
|
|
two > one;
|
|
|;
|
|
assert |
|
|
two >= two;
|
|
|;
|
|
assert |
|
|
tpl1 == tpl2;
|
|
|;
|
|
assert |
|
|
tpl1 != tpl3;
|
|
|;
|
|
assert |
|
|
list == list2;
|
|
|;
|
|
assert |
|
|
list != list3;
|
|
|;
|
|
|
|
// Deep Comparisons
|
|
let tpl4 = {
|
|
foo = "bar",
|
|
lst = [1, 2, 3],
|
|
inner = {
|
|
fld = "value",
|
|
}
|
|
};
|
|
let copy = tpl4;
|
|
let extra = tpl4{one = 1};
|
|
let less = {
|
|
foo = "bar"
|
|
};
|
|
|
|
assert |
|
|
tpl4.inner == copy.inner;
|
|
|;
|
|
assert |
|
|
tpl4.inner.fld == copy.inner.fld;
|
|
|;
|
|
assert |
|
|
tpl4.lst == copy.lst;
|
|
|;
|
|
assert |
|
|
tpl4.foo == copy.foo;
|
|
|;
|
|
assert |
|
|
tpl4 == copy;
|
|
|;
|
|
assert |
|
|
tpl4 != extra;
|
|
|;
|
|
assert |
|
|
tpl4 != less;
|
|
|;
|
|
|
|
assert |
|
|
[[1, 2, [3]], 4] == [[1, 2, [3]], 4];
|
|
|;
|
|
|
|
assert |
|
|
[[1, 2, [3]], 4] != [[1, 2, [6]], 4];
|
|
|;
|
|
|
|
// Expression comparisons
|
|
assert |2 == 1+1;|;
|
|
assert |(1+1) == 2;|;
|
|
assert |(1+1) == (1+1);|;
|
|
let want = "foo";
|
|
assert |
|
|
select want, 1, { foo=2, } == 2;
|
|
|;
|
|
|
|
// Contains comparison operators.
|
|
assert |
|
|
"foo" in {
|
|
foo = "bar",
|
|
};
|
|
|;
|
|
assert |
|
|
foo in {
|
|
foo = "bar",
|
|
};
|
|
|;
|
|
assert |
|
|
"foo" in ["foo", "bar"];
|
|
|;
|
|
assert |
|
|
"foo" in ["bar", "foo", "bar"];
|
|
|;
|
|
assert |
|
|
{ foo = 1 } in ["foo", { foo = 1 }];
|
|
|;
|
|
assert |
|
|
true in [ "foo" in {foo = 1}, false ];
|
|
|;
|
|
|
|
assert |
|
|
"foo" ~ "o+";
|
|
|;
|
|
|
|
assert |
|
|
"foo" !~ "bar";
|
|
|; |