on master help sign in
Merge pull request #619 from maxsnew/eq

Fix Equality Test

commit24ab294f507c2a93a58ca61b6bc495785283c000 authorEvan Czaplicki <info@elm-lang.org> dateTue 6 May 2014, 12:16 (12 years ago) parent271a6110691082
3 files changed+34−1
libraries/Native/Utils.js+10−1 tests/elm/Test.elm+2 tests/elm/Test/Eq.elm+22
libraries/Native/Utils.js+10−1
@@ -16,7 +16,16 @@ Elm.Native.Utils.make = function(elm) {
1616 var c = 0;
1717 for (var i in x) {
1818 ++c;
19− stack.push({ 'x': x[i], 'y': y[i] });
19+ if (i in y) {
20+ if (i !== 'ctor') {
21+ stack.push({ 'x': x[i], 'y': y[i] });
22+ }
23+ } else {
24+ return false;
25+ }
26+ }
27+ if ('ctor' in x) {
28+ stack.push({'x': x.ctor, 'y': y.ctor});
2029 }
2130 if (c !== Object.keys(y).length) {
2231 return false;
tests/elm/Test.elm+2
@@ -11,6 +11,7 @@ import IO.Runner as Run
1111
1212import Test.Array as Array
1313import Test.Dict as Dict
14+import Test.Eq as Eq
1415import Test.List as List
1516import Test.Set as Set
1617import Test.String as String
@@ -18,6 +19,7 @@ import Test.Trampoline as Trampoline
1819
1920tests : Test
2021tests = suite "Elm Standard Library Tests" [ List.tests,
22+ Eq.tests,
2123 String.tests,
2224 Trampoline.tests,
2325 Array.tests,
tests/elm/Test/Eq.elmnew file+22
@@ -0,0 +1,22 @@
1+module Test.Eq (tests) where
2+
3+import ElmTest.Assertion (..)
4+import ElmTest.Test (..)
5+
6+data Different = A String
7+ | B [Int]
8+
9+tests : Test
10+tests =
11+ let diff_tests = suite "sum type eq"
12+ [ test "As eq" <| assert (A "a" == A "a")
13+ , test "Bs eq" <| assert (B [1] == B [1])
14+ , test "A left neq" <| assert . not <| (A "a" == B [1])
15+ , test "A left neq" <| assert . not <| (B [1] == A "a")
16+ ]
17+ record_tests = suite "record type eq"
18+ [ test "empty same" <| assert ({} == {})
19+ , test "ctor same" <| assert ({ctor = Just 3} == {ctor = Just 3})
20+ , test "ctor diff" . assert . not <| ({ctor = Just 3} == {ctor = Nothing})
21+ ]
22+ in suite "Equality Tests" [diff_tests, record_tests]