mirror of
https://github.com/gleam-lang/gleam.git
synced 2025-12-23 09:47:08 +00:00
Fix list equality in JS
This commit is contained in:
parent
1a7ea97df3
commit
996bb2993c
2 changed files with 35 additions and 0 deletions
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) }),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue