on master help sign in
Merge branch 'master' into webgl
commit1887c65b68ed70ee9efe9d81fe2d0dddb0978a46 authorEvan Czaplicki <info@elm-lang.org> dateTue 6 May 2014, 16:09 (12 years ago) parent9026039b80c904
6 files changed+74−6
.travis.yml+31−3 libraries/Native/Array.js+7−1 libraries/Native/Utils.js+10−1 tests/elm/Test/Eq.elm+22 tests/libraries/Test.elm+2 tests/libraries/Test/Array.elm+2−1
.travis.yml+31−3
@@ -1,3 +1,31 @@
1−language: haskell
2−ghc:
3− - 7.6
1+# Based on https://github.com/hvr/multi-ghc-travis and https://github.com/ekmett/lens/blob/master/.travis.yml
2+
3+# NB: don't set `language: haskell` here
4+
5+# The following enables several GHC versions to be tested; often it's enough to test only against the last release in a major GHC version. Feel free to omit lines listings versions you don't need/want testing for.
6+env:
7+ - GHCVER=7.6.3
8+ - GHCVER=7.8.2
9+
10+# Note: the distinction between `before_install` and `install` is not important.
11+before_install:
12+ - travis_retry sudo add-apt-repository -y ppa:hvr/ghc
13+ - travis_retry sudo apt-get update
14+ - travis_retry sudo apt-get install cabal-install-1.18 ghc-$GHCVER happy alex # see note about happy/alex
15+ - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/1.18/bin:$PATH
16+ - cabal update
17+ # Update happy when building with GHC 7.8 or head
18+ - |
19+ if [ $GHCVER = "head" ] || [ $GHCVER = "7.8.2" ]; then
20+ cabal install happy alex
21+ export PATH=$HOME/.cabal/bin:$PATH
22+ fi
23+
24+install:
25+ - cabal install --only-dependencies --enable-tests --enable-benchmarks
26+
27+# Here starts the actual work to be performed for the package under test; any command which exits with a non-zero exit code causes the build to fail.
28+script:
29+ - cabal configure --enable-tests
30+ - cabal build
31+ - cabal test
libraries/Native/Array.js+7−1
@@ -240,10 +240,16 @@ Elm.Native.Array.make = function(elm) {
240240
241241 // Maps a function over the elements with their index as first argument.
242242 function indexedMap(f, a) {
243+ return indexedMap_(f, a, 0);
244+ }
245+
246+ function indexedMap_(f, a, from) {
243247 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
244248 if (a.height > 0) { newA.lengths = a.lengths; }
245249 for (var i = 0; i < a.table.length; i++) {
246− newA.table[i] = a.height == 0 ? A2(f, i, a.table[i]) : indexedMap(f, a.table[i]);
250+ newA.table[i] = a.height == 0 ? A2(f, from + i, a.table[i])
251+ : indexedMap_( f, a.table[i]
252+ , i == 0 ? 0 : a.lengths[i - 1]);
247253 }
248254 return newA;
249255 }
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/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]
tests/libraries/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/libraries/Test/Array.elm+2−1
@@ -46,7 +46,8 @@ tests =
4646 ]
4747 mappingAndFoldingTests = suite "Mapping and Folding"
4848 [ test "map" <| assertEqual (Array.fromList [1,2,3]) (Array.map sqrt (Array.fromList [1,4,9]))
49− , test "indexedMap" <| assertEqual (Array.fromList [0,5,10]) (Array.indexedMap (*) (Array.fromList [5,5,5]))
49+ , test "indexedMap 1" <| assertEqual (Array.fromList [0,5,10]) (Array.indexedMap (*) (Array.fromList [5,5,5]))
50+ , test "indexedMap 2" <| assertEqual [0..99] (Array.toList (Array.indexedMap always (Array.repeat 100 0)))
5051 , test "foldl" <| assertEqual [3,2,1] (Array.foldl (::) [] (Array.fromList [1,2,3]))
5152 , test "foldr 1" <| assertEqual 15 (Array.foldr (+) 0 (Array.repeat 3 5))
5253 , test "foldr 2" <| assertEqual [1,2,3] (Array.foldr (::) [] (Array.fromList [1,2,3]))