Fix list equality in JS

This commit is contained in:
Louis Pilfold 2021-07-18 16:35:34 +01:00
parent 1a7ea97df3
commit 996bb2993c
2 changed files with 35 additions and 0 deletions

View file

@ -20,6 +20,7 @@ function $equal(x, y) {
let b = toCheck.pop();
if (a === b) return true;
if (!$is_object(a) || !$is_object(b)) return false;
if (a.length !== b.length) return false;
for (let k of Object.keys(a)) {
toCheck.push(a[k], b[k]);
}

View file

@ -12,6 +12,7 @@ pub fn main() -> Int {
suite("floats", float_tests()),
suite("prelude", prelude_tests()),
suite("strings", strings_tests()),
suite("equality", equality_tests()),
suite("constants", constants_tests()),
suite("clause guards", clause_guard_tests()),
suite("imported custom types", imported_custom_types_test()),
@ -886,3 +887,36 @@ fn multiple_case_subjects() -> List(Test) {
}),
]
}
fn equality_tests() -> List(Test) {
[
"[] == []"
|> example(fn() { assert_equal(True, [] == []) }),
"[] == [0]"
|> example(fn() { assert_equal(False, [] == [0]) }),
"[0] == []"
|> example(fn() { assert_equal(False, [0] == []) }),
"[0] == [0]"
|> example(fn() { assert_equal(True, [0] == [0]) }),
"[] != []"
|> example(fn() { assert_equal(False, [] != []) }),
"[] != [0]"
|> example(fn() { assert_equal(True, [] != [0]) }),
"[0] != []"
|> example(fn() { assert_equal(True, [0] != []) }),
"[0] != [0]"
|> example(fn() { assert_equal(False, [0] != [0]) }),
"0 == 0"
|> example(fn() { assert_equal(True, 0 == 0) }),
"0 != 0"
|> example(fn() { assert_equal(False, 0 != 0) }),
"1 == 0"
|> example(fn() { assert_equal(False, 1 == 0) }),
"1 != 0"
|> example(fn() { assert_equal(True, 1 != 0) }),
"1 == 1"
|> example(fn() { assert_equal(True, 1 == 1) }),
"1 != 1"
|> example(fn() { assert_equal(False, 1 != 1) }),
]
}