on master help sign in
Merge branch 'master' into canonicalize
3902049Evan Czaplicki
Elm.cabal+8−5
@@ -1,5 +1,5 @@
1Name: Elm
1Name: Elm
2−Version: 0.12
2+Version: 0.12.1
3Synopsis: The Elm language module.
3Synopsis: The Elm language module.
4Description: Elm aims to make client-side web-development more pleasant.
4Description: Elm aims to make client-side web-development more pleasant.
5 It is a statically/strongly typed, functional reactive
5 It is a statically/strongly typed, functional reactive
@@ -27,7 +27,7 @@ Cabal-version: >=1.9
27
27
28source-repository head
28source-repository head
29 type: git
29 type: git
30− location: git://github.com/evancz/Elm.git
30+ location: git://github.com/elm-lang/Elm.git
31
31
32Library
32Library
33 exposed-modules: Elm.Internal.Dependencies,
33 exposed-modules: Elm.Internal.Dependencies,
@@ -96,6 +96,7 @@ Library
96 Paths_Elm
96 Paths_Elm
97
97
98 Build-depends: aeson,
98 Build-depends: aeson,
99+ aeson-pretty,
99 base >=4.2 && <5,
100 base >=4.2 && <5,
100 binary >= 0.7.0.0,
101 binary >= 0.7.0.0,
101 blaze-html >= 0.5 && < 0.8,
102 blaze-html >= 0.5 && < 0.8,
@@ -180,6 +181,7 @@ Executable elm
180 Paths_Elm
181 Paths_Elm
181
182
182 Build-depends: aeson,
183 Build-depends: aeson,
184+ aeson-pretty,
183 base >=4.2 && <5,
185 base >=4.2 && <5,
184 binary >= 0.7.0.0,
186 binary >= 0.7.0.0,
185 blaze-html >= 0.5 && < 0.8,
187 blaze-html >= 0.5 && < 0.8,
@@ -257,10 +259,11 @@ Test-Suite compiler-tests
257 HUnit,
259 HUnit,
258 QuickCheck >= 2 && < 3,
260 QuickCheck >= 2 && < 3,
259 aeson,
261 aeson,
262+ aeson-pretty,
260 base >=4.2 && <5,
263 base >=4.2 && <5,
261 binary >= 0.7.0.0,
264 binary >= 0.7.0.0,
262− blaze-html == 0.5.* || == 0.6.*,
265+ blaze-html,
263− blaze-markup == 0.5.1.*,
266+ blaze-markup,
264 bytestring,
267 bytestring,
265 cmdargs,
268 cmdargs,
266 containers >= 0.3,
269 containers >= 0.3,
@@ -288,4 +291,4 @@ Test-Suite lib-tests
288 directory,
291 directory,
289 Elm,
292 Elm,
290 filepath,
293 filepath,
291− process >= 1.2
294+ process
changelog.md+8−6
@@ -1,5 +1,12 @@
1
1
2−## 0.13
2+## 0.12.1
3+
4+## Improvements:
5+
6+ * New Array library (thanks entirely to @Xashili)
7+ * Json.Value can flow through ports
8+ * Improve speed and stack usage in List library (thanks to @maxsnew)
9+ * Add Dict.filter and Dict.partition (thanks to @hdgarrood)
3
10
4#### Breaking Changes:
11#### Breaking Changes:
5
12
@@ -7,11 +14,6 @@
7 * Revamp JavaScript.Experimental library to have slightly better names
14 * Revamp JavaScript.Experimental library to have slightly better names
8 * Remove JavaScript library which was made redundant by ports
15 * Remove JavaScript library which was made redundant by ports
9
16
10−## Improvements:
11−
12− * Json.Value can flow through ports, so you can bring in values even
13− if they don't conform to a consistent type.
14−
15## 0.12
17## 0.12
16
18
17#### Breaking Changes:
19#### Breaking Changes:
compiler/Elm/Internal/Dependencies.hs+41−4
@@ -5,9 +5,12 @@ import Control.Applicative
5import Control.Monad.Error
5import Control.Monad.Error
6import qualified Control.Exception as E
6import qualified Control.Exception as E
7import Data.Aeson
7import Data.Aeson
8+import Data.Aeson.Encode.Pretty
8import qualified Data.List as List
9import qualified Data.List as List
9import qualified Data.ByteString.Lazy as BS
10import qualified Data.ByteString.Lazy as BS
10import qualified Data.HashMap.Strict as Map
11import qualified Data.HashMap.Strict as Map
12+import qualified Data.Text as T
13+
11import qualified Elm.Internal.Name as N
14import qualified Elm.Internal.Name as N
12import qualified Elm.Internal.Version as V
15import qualified Elm.Internal.Version as V
13import qualified Elm.Internal.Paths as Path
16import qualified Elm.Internal.Paths as Path
@@ -22,14 +25,32 @@ data Deps = Deps
22 , exposed :: [String]
25 , exposed :: [String]
23 , elmVersion :: V.Version
26 , elmVersion :: V.Version
24 , dependencies :: [(N.Name,V.Version)]
27 , dependencies :: [(N.Name,V.Version)]
25− } deriving Show
28+ } deriving (Show, Eq, Ord)
26
29
27data MiniDeps = Mini [(N.Name,V.Version)]
30data MiniDeps = Mini [(N.Name,V.Version)]
31+ deriving (Show, Eq, Ord)
32+
33+instance ToJSON MiniDeps where
34+ toJSON (Mini m) = toJSON m
28
35
29instance FromJSON MiniDeps where
36instance FromJSON MiniDeps where
30 parseJSON (Object obj) = Mini <$> getDependencies obj
37 parseJSON (Object obj) = Mini <$> getDependencies obj
31 parseJSON _ = mzero
38 parseJSON _ = mzero
32
39
40+instance ToJSON Deps where
41+ toJSON d = object [
42+ "version" .= version d,
43+ "summary" .= summary d,
44+ "description" .= description d,
45+ "license" .= license d,
46+ "repository" .= repo d,
47+ "exposed-modules" .= exposed d,
48+ "elm-version" .= elmVersion d,
49+ "dependencies" .= (jsonDeps . dependencies $ d)
50+ ]
51+ where jsonDeps = Map.fromList . map (mapFst (T.pack . show))
52+ mapFst f (a,b) = (f a, b)
53+
33instance FromJSON Deps where
54instance FromJSON Deps where
34 parseJSON (Object obj) =
55 parseJSON (Object obj) =
35 do version <- get obj "version" "your projects version number"
56 do version <- get obj "version" "your projects version number"
@@ -110,8 +131,24 @@ withDeps handle path =
110 case result of
131 case result of
111 Right bytes -> return bytes
132 Right bytes -> return bytes
112 Left _ -> throwError $
133 Left _ -> throwError $
113− "could not find file " ++ path ++
134+ "could not find " ++ path ++ " file. You may need to create one.\n" ++
114− "\n You may need to create a dependency file for your project."
135+ " For an example of how to fill in the dependencies file, check out\n" ++
136+ " <https://github.com/evancz/automaton/blob/master/elm_dependencies.json>"
115
137
116depsAt :: FilePath -> ErrorT String IO Deps
138depsAt :: FilePath -> ErrorT String IO Deps
117−depsAt = withDeps id
139+depsAt = withDeps id
140+
141+-- | Encode dependencies in a canonical JSON format
142+prettyJSON :: Deps -> BS.ByteString
143+prettyJSON = encodePretty' config
144+ where config = defConfig { confCompare = order }
145+ order = keyOrder [ "name",
146+ "version",
147+ "summary",
148+ "description",
149+ "license",
150+ "repo",
151+ "exposed-modules",
152+ "elm-version",
153+ "dependencies"
154+ ]
compiler/Elm/Internal/Name.hs+2−2
@@ -10,7 +10,7 @@ import qualified Data.Maybe as Maybe
10import Data.Typeable
10import Data.Typeable
11
11
12data Name = Name { user :: String, project :: String }
12data Name = Name { user :: String, project :: String }
13− deriving (Typeable,Eq)
13+ deriving (Typeable,Eq, Ord)
14
14
15instance Binary Name where
15instance Binary Name where
16 get = Name <$> get <*> get
16 get = Name <$> get <*> get
@@ -48,4 +48,4 @@ errorMsg string =
48 unlines
48 unlines
49 [ "Dependency file has an invalid name: " ++ string
49 [ "Dependency file has an invalid name: " ++ string
50 , "Must have format user/project and match a public github project."
50 , "Must have format user/project and match a public github project."
51− ]
51+ ]
compiler/Type/Unify.hs+5−1
@@ -86,6 +86,10 @@ actuallyUnify region variable1 variable2 = do
86 TS.addError region (Just $ Maybe.fromMaybe msg maybe) variable1 variable2
86 TS.addError region (Just $ Maybe.fromMaybe msg maybe) variable1 variable2
87 where msg = "A comparable must be an Int, Float, Char, String, list, or tuple."
87 where msg = "A comparable must be an Int, Float, Char, String, list, or tuple."
88
88
89+ appendableError maybe =
90+ TS.addError region (Just $ Maybe.fromMaybe msg maybe) variable1 variable2
91+ where msg = "An appendable must be of type String, List, or Text."
92+
89 unifyComparable var name
93 unifyComparable var name
90 | name `elem` ["Int","Float","Char","String","comparable"] = flexAndUnify var
94 | name `elem` ["Int","Float","Char","String","comparable"] = flexAndUnify var
91 | otherwise = comparableError Nothing
95 | otherwise = comparableError Nothing
@@ -108,7 +112,7 @@ actuallyUnify region variable1 variable2 = do
108 do struct <- liftIO $ collectApps varFlex
112 do struct <- liftIO $ collectApps varFlex
109 case struct of
113 case struct of
110 List _ -> flexAndUnify varSuper
114 List _ -> flexAndUnify varSuper
111− _ -> comparableError Nothing
115+ _ -> appendableError Nothing
112
116
113 rigidError variable = TS.addError region (Just hint) variable1 variable2
117 rigidError variable = TS.addError region (Just hint) variable1 variable2
114 where
118 where
libraries/Array.elm+12−12
@@ -11,7 +11,7 @@ reads, updates, and appends.
11@docs length, push, append
11@docs length, push, append
12
12
13# Get and Set
13# Get and Set
14−@docs get, getSafe, getUnsafe, set
14+@docs get, getOrElse, getOrFail, set
15
15
16# Taking Arrays Apart
16# Taking Arrays Apart
17@docs toList, toIndexedList, slice
17@docs toList, toIndexedList, slice
@@ -122,14 +122,14 @@ push = Native.Array.push
122
122
123{-| Get the element at a particular index.
123{-| Get the element at a particular index.
124
124
125− getUnsafe 2 (A.fromList [3,2,1]) == 1
125+ getOrFail 2 (A.fromList [3,2,1]) == 1
126
126
127Warning: this function will result in a runtime error if the index is not found,
127Warning: this function will result in a runtime error if the index is not found,
128−so it is best to use `get` or `getSafe` unless you are very confident the index
128+so it is best to use `get` or `getOrElse` unless you are sure the index will be
129−will be found.
129+found.
130-}
130-}
131−getUnsafe : Int -> Array a -> a
131+getOrFail : Int -> Array a -> a
132−getUnsafe = Native.Array.get
132+getOrFail = Native.Array.get
133
133
134{-| Return Just the element at the index or Nothing if the index is out of range.
134{-| Return Just the element at the index or Nothing if the index is out of range.
135
135
@@ -143,14 +143,14 @@ get i array =
143 then Just (Native.Array.get i array)
143 then Just (Native.Array.get i array)
144 else Nothing
144 else Nothing
145
145
146−{-| Get the element at the index. If the index is out of range, the given default
146+{-| Get the element at the index. Or if the index is out of range, a default
147−element is returned.
147+value is returned.
148
148
149− getSafe 0 2 (fromList [3,2,1]) == 1
149+ getOrElse 0 2 (fromList [3,2,1]) == 1
150− getSafe 0 5 (fromList [3,2,1]) == 0
150+ getOrElse 0 5 (fromList [3,2,1]) == 0
151-}
151-}
152−getSafe : a -> Int -> Array a -> a
152+getOrElse : a -> Int -> Array a -> a
153−getSafe default i array =
153+getOrElse default i array =
154 if 0 <= i && i < Native.Array.length array
154 if 0 <= i && i < Native.Array.length array
155 then Native.Array.get i array
155 then Native.Array.get i array
156 else default
156 else default
libraries/Dict.elm+20−20
@@ -1,5 +1,5 @@
1module Dict (empty,singleton,insert,update
1module Dict (empty,singleton,insert,update
2− ,get,getSafe,getUnsafe
2+ ,get,getOrElse,getOrFail
3 ,remove,member
3 ,remove,member
4 ,filter
4 ,filter
5 ,partition
5 ,partition
@@ -19,7 +19,7 @@ Insert, remove, and query operations all take *O(log n)* time.
19@docs empty, singleton, insert, update, remove
19@docs empty, singleton, insert, update, remove
20
20
21# Query
21# Query
22−@docs member, get, getMaybe, getWithDefault
22+@docs member, get, getOrElse, getOrFail
23
23
24# Combine
24# Combine
25@docs union, intersect, diff
25@docs union, intersect, diff
@@ -96,7 +96,7 @@ dictionary.
96 get "Mouse" animals == Just Mouse
96 get "Mouse" animals == Just Mouse
97 get "Spike" animals == Nothing
97 get "Spike" animals == Nothing
98
98
99−The `getSafe` and `getUnsafe` are built-in ways to handle common ways of
99+The `getOrElse` and `getOrFail` are built-in ways to handle common ways of
100using the resulting `Maybe`.
100using the resulting `Maybe`.
101-}
101-}
102get : comparable -> Dict comparable v -> Maybe v
102get : comparable -> Dict comparable v -> Maybe v
@@ -114,41 +114,41 @@ return a default value.
114
114
115 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
115 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
116
116
117− getSafe Dog "Tom" animals == Cat
117+ getOrElse Dog "Tom" animals == Cat
118− getSafe Dog "Mouse" animals == Mouse
118+ getOrElse Dog "Mouse" animals == Mouse
119− getSafe Dog "Spike" animals == Dog
119+ getOrElse Dog "Spike" animals == Dog
120-}
120-}
121−getSafe : v -> comparable -> Dict comparable v -> v
121+getOrElse : v -> comparable -> Dict comparable v -> v
122−getSafe base k t =
122+getOrElse base k t =
123 case t of
123 case t of
124 RBEmpty LBlack -> base
124 RBEmpty LBlack -> base
125 RBNode _ k' v l r ->
125 RBNode _ k' v l r ->
126 case Native.Utils.compare k k' of
126 case Native.Utils.compare k k' of
127− LT -> getSafe base k l
127+ LT -> getOrElse base k l
128 EQ -> v
128 EQ -> v
129− GT -> getSafe base k r
129+ GT -> getOrElse base k r
130
130
131{-| Get the value associated with a key.
131{-| Get the value associated with a key.
132
132
133 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
133 animals = fromList [ ("Tom", Cat), ("Jerry", Mouse) ]
134
134
135− get "Tom" animals == Cat
135+ getOrFail "Tom" animals == Cat
136− get "Mouse" animals == Mouse
136+ getOrFail "Mouse" animals == Mouse
137− get "Spike" animals == -- Runtime Error!
137+ getOrFail "Spike" animals == -- Runtime Error!
138
138
139Warning: this function will result in a runtime error if the key is not found,
139Warning: this function will result in a runtime error if the key is not found,
140−so it is best to use `get` or `getSafe` unless you are very confident the key
140+so it is best to use `get` or `getOrElse` unless you are sure the key will be
141−will be found.
141+found.
142-}
142-}
143−getUnsafe : comparable -> Dict comparable v -> v
143+getOrFail : comparable -> Dict comparable v -> v
144−getUnsafe k t =
144+getOrFail k t =
145 case t of
145 case t of
146− RBEmpty LBlack -> Native.Error.raise "key not found when using 'getUnsafe'"
146+ RBEmpty LBlack -> Native.Error.raise "key not found when using 'getOrFail'"
147 RBNode _ k' v l r ->
147 RBNode _ k' v l r ->
148 case Native.Utils.compare k k' of
148 case Native.Utils.compare k k' of
149− LT -> getUnsafe k l
149+ LT -> getOrFail k l
150 EQ -> v
150 EQ -> v
151− GT -> getUnsafe k r
151+ GT -> getOrFail k r
152
152
153{-| Determine if a key is in a dictionary. -}
153{-| Determine if a key is in a dictionary. -}
154member : comparable -> Dict comparable v -> Bool
154member : comparable -> Dict comparable v -> Bool
libraries/elm_dependencies.json+6−5
@@ -1,12 +1,13 @@
1−{ "version": "0.12"
1+{ "version": "0.12.1"
2, "summary": "Elm's standard libraries"
2, "summary": "Elm's standard libraries"
3−, "description": "The full set of standard libraries for Elm. This library is pegged to the version number of the compiler, so if you are using Elm 0.12, you should be using version 0.12 of the standard libraries."
3+, "description": "The full set of standard libraries for Elm. This library is pegged to the version number of the compiler, so if you are using Elm 0.12.1, you should be using version 0.12.1 of the standard libraries."
4, "license": "BSD3"
4, "license": "BSD3"
5−, "repository": "http://github.com/evancz/Elm.git"
5+, "repository": "http://github.com/elm-lang/Elm.git"
6−, "elm-version": "0.12"
6+, "elm-version": "0.12.1"
7, "dependencies": {}
7, "dependencies": {}
8, "exposed-modules":
8, "exposed-modules":
9+ [ "Array"
9− [ "Basics"
10+ , "Basics"
10 , "Bitwise"
11 , "Bitwise"
11 , "Char"
12 , "Char"
12 , "Color"
13 , "Color"
tests/elm/Test.elm+8−2
@@ -16,8 +16,14 @@ import Test.Set as Set
16import Test.String as String
16import Test.String as String
17import Test.Trampoline as Trampoline
17import Test.Trampoline as Trampoline
18
18
19−tests : [Test]
19+tests : Test
20−tests = String.tests ++ Trampoline.tests ++ Array.tests ++ Dict.tests ++ Set.tests ++ List.tests
20+tests = suite "Elm Standard Library Tests" [ List.tests,
21+ String.tests,
22+ Trampoline.tests,
23+ Array.tests,
24+ Dict.tests,
25+ Set.tests
26+ ]
21
27
22console : IO ()
28console : IO ()
23console = runDisplay tests
29console = runDisplay tests
tests/elm/Test/Array.elm+10−10
@@ -6,9 +6,9 @@ import Array
6import ElmTest.Assertion (..)
6import ElmTest.Assertion (..)
7import ElmTest.Test (..)
7import ElmTest.Test (..)
8
8
9−tests : [Test]
9+tests : Test
10tests =
10tests =
11− let creationTests =
11+ let creationTests = suite "Creation"
12 [ test "empty" <| assertEqual Array.empty (Array.fromList [])
12 [ test "empty" <| assertEqual Array.empty (Array.fromList [])
13 , test "initialize" <| assertEqual (Array.initialize 4 id) (Array.fromList [0,1,2,3])
13 , test "initialize" <| assertEqual (Array.initialize 4 id) (Array.fromList [0,1,2,3])
14 , test "initialize 2" <| assertEqual (Array.initialize 4 (\n -> n*n)) (Array.fromList [0,1,4,9])
14 , test "initialize 2" <| assertEqual (Array.initialize 4 (\n -> n*n)) (Array.fromList [0,1,4,9])
@@ -20,29 +20,29 @@ tests =
20 , test "repeat 3" <| assertEqual (Array.repeat 3 "cat") (Array.fromList ["cat","cat","cat"])
20 , test "repeat 3" <| assertEqual (Array.repeat 3 "cat") (Array.fromList ["cat","cat","cat"])
21 , test "fromList" <| assertEqual (Array.fromList []) Array.empty
21 , test "fromList" <| assertEqual (Array.fromList []) Array.empty
22 ]
22 ]
23− basicsTests =
23+ basicsTests = suite "Basics"
24 [ test "length" <| assertEqual (Array.length (Array.fromList [1,2,3])) 3
24 [ test "length" <| assertEqual (Array.length (Array.fromList [1,2,3])) 3
25 , test "length - Long" <| assertEqual (Array.length (Array.repeat 10000 0)) 10000
25 , test "length - Long" <| assertEqual (Array.length (Array.repeat 10000 0)) 10000
26 , test "push" <| assertEqual (Array.push 3 (Array.fromList [1,2])) (Array.fromList [1,2,3])
26 , test "push" <| assertEqual (Array.push 3 (Array.fromList [1,2])) (Array.fromList [1,2,3])
27 , test "append" <| assertEqual (Array.toList <| Array.append (Array.repeat 2 42) (Array.repeat 3 81)) ([42,42,81,81,81])
27 , test "append" <| assertEqual (Array.toList <| Array.append (Array.repeat 2 42) (Array.repeat 3 81)) ([42,42,81,81,81])
28 ]
28 ]
29− getAndSetTests =
29+ getAndSetTests = suite "Get and Set"
30 [ test "get" <| assertEqual (Array.get 1 (Array.fromList [3,2,1])) (Just 2)
30 [ test "get" <| assertEqual (Array.get 1 (Array.fromList [3,2,1])) (Just 2)
31 , test "get 2" <| assertEqual (Array.get 5 (Array.fromList [3,2,1])) Nothing
31 , test "get 2" <| assertEqual (Array.get 5 (Array.fromList [3,2,1])) Nothing
32 , test "get 3" <| assertEqual (Array.get -1 (Array.fromList [3,2,1])) Nothing
32 , test "get 3" <| assertEqual (Array.get -1 (Array.fromList [3,2,1])) Nothing
33− , test "getSafe 1" <| assertEqual (Array.getSafe 0 2 (Array.fromList [3,2,1])) 1
33+ , test "getOrElse 1" <| assertEqual (Array.getOrElse 0 2 (Array.fromList [3,2,1])) 1
34− , test "getSafe 2" <| assertEqual (Array.getSafe 0 5 (Array.fromList [3,2,1])) 0
34+ , test "getOrElse 2" <| assertEqual (Array.getOrElse 0 5 (Array.fromList [3,2,1])) 0
35− , test "getUnsafe" <| assertEqual (Array.getUnsafe 2 (Array.fromList [3,2,1])) 1
35+ , test "getOrFail" <| assertEqual (Array.getOrFail 2 (Array.fromList [3,2,1])) 1
36 , test "set" <| assertEqual (Array.set 1 7 (Array.fromList [1,2,3])) (Array.fromList [1,7,3])
36 , test "set" <| assertEqual (Array.set 1 7 (Array.fromList [1,2,3])) (Array.fromList [1,7,3])
37 ]
37 ]
38− takingArraysApartTests =
38+ takingArraysApartTests = suite "Taking Arrays Apart"
39 [ test "toList" <| assertEqual (Array.toList (Array.fromList [3,5,8])) [3,5,8]
39 [ test "toList" <| assertEqual (Array.toList (Array.fromList [3,5,8])) [3,5,8]
40 , test "toIndexedList" <| assertEqual (Array.toIndexedList (Array.fromList ["cat","dog"])) [(0,"cat"), (1,"dog")]
40 , test "toIndexedList" <| assertEqual (Array.toIndexedList (Array.fromList ["cat","dog"])) [(0,"cat"), (1,"dog")]
41 , test "slice" <| assertEqual (Array.slice 1 2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2])
41 , test "slice" <| assertEqual (Array.slice 1 2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2])
42 , test "slice 2" <| assertEqual (Array.slice 1 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2,3])
42 , test "slice 2" <| assertEqual (Array.slice 1 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [1,2,3])
43 , test "slice 3" <| assertEqual (Array.slice -3 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [2,3])
43 , test "slice 3" <| assertEqual (Array.slice -3 -2 (Array.fromList [0,1,2,3,4])) (Array.fromList [2,3])
44 ]
44 ]
45− mappingAndFoldingTests =
45+ mappingAndFoldingTests = suite "Mapping and Folding"
46 [ test "map" <| assertEqual (Array.map sqrt (Array.fromList [1,4,9])) (Array.fromList [1,2,3])
46 [ test "map" <| assertEqual (Array.map sqrt (Array.fromList [1,4,9])) (Array.fromList [1,2,3])
47 , test "indexedMap" <| assertEqual (Array.indexedMap (*) (Array.fromList [5,5,5])) (Array.fromList [0,5,10])
47 , test "indexedMap" <| assertEqual (Array.indexedMap (*) (Array.fromList [5,5,5])) (Array.fromList [0,5,10])
48 , test "foldl" <| assertEqual (Array.foldl (::) [] (Array.fromList [1,2,3])) [3,2,1]
48 , test "foldl" <| assertEqual (Array.foldl (::) [] (Array.fromList [1,2,3])) [3,2,1]
@@ -51,4 +51,4 @@ tests =
51 , test "filter" <| assertEqual (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6])) (Array.fromList [2,4,6])
51 , test "filter" <| assertEqual (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6])) (Array.fromList [2,4,6])
52 ]
52 ]
53 in
53 in
54− List.concat [creationTests, basicsTests, getAndSetTests, takingArraysApartTests, mappingAndFoldingTests]
54+ suite "Array Tests" [creationTests, basicsTests, getAndSetTests, takingArraysApartTests, mappingAndFoldingTests]
tests/elm/Test/Dict.elm+5−5
@@ -9,18 +9,18 @@ import ElmTest.Test (..)
9animals : Dict.Dict String String
9animals : Dict.Dict String String
10animals = Dict.fromList [ ("Tom", "cat"), ("Jerry", "mouse") ]
10animals = Dict.fromList [ ("Tom", "cat"), ("Jerry", "mouse") ]
11
11
12−tests : [Test]
12+tests : Test
13tests =
13tests =
14 let getTests =
14 let getTests =
15 [ test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
15 [ test "get 1" <| assertEqual (Just "cat") (Dict.get "Tom" animals)
16 , test "get 2" <| assertEqual Nothing (Dict.get "Spike" animals)
16 , test "get 2" <| assertEqual Nothing (Dict.get "Spike" animals)
17− , test "getSafe 1" <| assertEqual "mouse" (Dict.getSafe "dog" "Jerry" animals)
17+ , test "getOrElse 1" <| assertEqual "mouse" (Dict.getOrElse "dog" "Jerry" animals)
18− , test "getSafe 2" <| assertEqual "dog" (Dict.getSafe "dog" "Spike" animals)
18+ , test "getOrElse 2" <| assertEqual "dog" (Dict.getOrElse "dog" "Spike" animals)
19− , test "getUnsafe" <| assertEqual "cat" (Dict.getUnsafe "Tom" animals)
19+ , test "getOrFail" <| assertEqual "cat" (Dict.getOrFail "Tom" animals)
20 ]
20 ]
21 filterTests =
21 filterTests =
22 [ test "filter" <| assertEqual (Dict.singleton "Tom" "cat") (Dict.filter (\k v -> k == "Tom") animals)
22 [ test "filter" <| assertEqual (Dict.singleton "Tom" "cat") (Dict.filter (\k v -> k == "Tom") animals)
23 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
23 , test "partition" <| assertEqual (Dict.singleton "Tom" "cat", Dict.singleton "Jerry" "mouse") (Dict.partition (\k v -> k == "Tom") animals)
24 ]
24 ]
25 in
25 in
26− List.concat [ getTests, filterTests ]
26+ suite "Dict Tests" <| List.concat [ getTests, filterTests ]
tests/elm/Test/List.elm+5−5
@@ -5,13 +5,13 @@ import List
5import ElmTest.Assertion (..)
5import ElmTest.Assertion (..)
6import ElmTest.Test (..)
6import ElmTest.Test (..)
7
7
8−tests : [Test]
8+tests : Test
9tests =
9tests =
10 let partitionTests =
10 let partitionTests =
11 let p1 = id
11 let p1 = id
12 p2 x = x < 3
12 p2 x = x < 3
13 isEven n = n `mod` 2 == 0
13 isEven n = n `mod` 2 == 0
14− in [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
14+ in suite "partition Tests" [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
15 test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
15 test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
16 test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),
16 test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),
17 test "partition doc check 2" <| assertEqual ([0,2,4], [1,3,5]) (partition isEven [0..5]),
17 test "partition doc check 2" <| assertEqual ([0,2,4], [1,3,5]) (partition isEven [0..5]),
@@ -20,14 +20,14 @@ tests =
20 fs = repeat n False
20 fs = repeat n False
21 in test "partition stress test" <| assertEqual (ts, fs) (partition p1 (fs++ts))
21 in test "partition stress test" <| assertEqual (ts, fs) (partition p1 (fs++ts))
22 ]
22 ]
23− unzipTests = [
23+ unzipTests = suite "unzip Tests" [
24 test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)]),
24 test "unzip doc check" <| assertEqual ([0,17,1337],[True,False,True]) (unzip [(0, True), (17, False), (1337, True)]),
25 let n = 100000
25 let n = 100000
26 ts = repeat n True
26 ts = repeat n True
27 fs = repeat n False
27 fs = repeat n False
28 in test "unzip stress test" <| assertEqual (ts, fs) (unzip (zip ts fs))
28 in test "unzip stress test" <| assertEqual (ts, fs) (unzip (zip ts fs))
29 ]
29 ]
30− intersperseTests = [
30+ intersperseTests = suite "intersperse Tests" [
31 test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"]),
31 test "intersperse doc check" <| assertEqual ["turtles","on","turtles","on","turtles"] (intersperse "on" ["turtles","turtles","turtles"]),
32 let n = 100000
32 let n = 100000
33 ts = repeat n True
33 ts = repeat n True
@@ -35,4 +35,4 @@ tests =
35 in test "intersperse stress test" <| assertEqual (tail . List.concat <| zipWith (\x y -> [x,y]) fs ts)
35 in test "intersperse stress test" <| assertEqual (tail . List.concat <| zipWith (\x y -> [x,y]) fs ts)
36 (intersperse False ts)
36 (intersperse False ts)
37 ]
37 ]
38− in List.concat [partitionTests, unzipTests, intersperseTests]
38+ in suite "List Tests" [partitionTests, unzipTests, intersperseTests]
tests/elm/Test/Set.elm+4−4
@@ -19,9 +19,9 @@ setPart2 = Set.fromList [51..100]
19pred : Int -> Bool
19pred : Int -> Bool
20pred x = x <= 50
20pred x = x <= 50
21
21
22−tests : [Test]
22+tests : Test
23tests =
23tests =
24 let
24 let
25− filterTests = [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
25+ filterTests = suite "filter Tests" [test "Simple filter" <| assertEqual setPart1 <| Set.filter pred set]
26− partitionTests = [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
26+ partitionTests = suite "partition Tests" [test "Simple partition" <| assertEqual (setPart1, setPart2) <| Set.partition pred set]
27− in List.concat [partitionTests, filterTests]
27+ in suite "Set Tests" [partitionTests, filterTests]
tests/elm/Test/String.elm+18−10
@@ -6,21 +6,29 @@ import String (..)
6import ElmTest.Assertion (..)
6import ElmTest.Assertion (..)
7import ElmTest.Test (..)
7import ElmTest.Test (..)
8
8
9−tests : [Test]
9+tests : Test
10tests =
10tests =
11+ let isEmptyTests = suite "isEmpty Tests" [
11− let isEmptyTests = [test "empty is empty" <| assert <| isEmpty "",
12+ test "empty is empty" <| assert <| isEmpty "",
12− test "not empty" <| assert <| not . isEmpty <| "the world"]
13+ test "not empty" <| assert <| not . isEmpty <| "the world"
14+ ]
13 lengthTest = test "length of innumerable" <| assertEqual 11 (length "innumerable")
15 lengthTest = test "length of innumerable" <| assertEqual 11 (length "innumerable")
14 reverseTest = test "reverse test" <| assertEqual "desserts" (reverse "stressed")
16 reverseTest = test "reverse test" <| assertEqual "desserts" (reverse "stressed")
15 repeatTest = test "repeat test" <| assertEqual "hahaha" (repeat 3 "ha")
17 repeatTest = test "repeat test" <| assertEqual "hahaha" (repeat 3 "ha")
18+ unconsTests = suite "uncons Tests" [
16− unconsTests = [test "nonempty uncons" <| assertEqual (Just ('a',"bc")) (uncons "abc"),
19+ test "nonempty uncons" <| assertEqual (Just ('a',"bc")) (uncons "abc"),
17− test "empty uncons" <| assertEqual Nothing (uncons "")]
20+ test "empty uncons" <| assertEqual Nothing (uncons "")
21+ ]
18 appendTest = test "append test" <| assertEqual "butterfly" (append "butter" "fly")
22 appendTest = test "append test" <| assertEqual "butterfly" (append "butter" "fly")
19 concatTest = test "concat test" <| assertEqual "nevertheless" (concat ["never","the","less"])
23 concatTest = test "concat test" <| assertEqual "nevertheless" (concat ["never","the","less"])
24+ splitTests = suite "split Tests" [
20− splitTests = [test "split commas" <| assertEqual ["cat","dog","cow"] (split "," "cat,dog,cow"),
25+ test "split commas" <| assertEqual ["cat","dog","cow"] (split "," "cat,dog,cow"),
21− test "split slashes"<| assertEqual ["home","evan","Desktop", ""] (split "/" "home/evan/Desktop/")]
26+ test "split slashes"<| assertEqual ["home","evan","Desktop", ""] (split "/" "home/evan/Desktop/")
27+ ]
28+ joinTests = suite "join Tests" [
22− joinTests = [test "join spaces" <| assertEqual "cat dog cow" (join " " ["cat","dog","cow"]),
29+ test "join spaces" <| assertEqual "cat dog cow" (join " " ["cat","dog","cow"]),
23− test "join slashes" <| assertEqual "home/evan/Desktop" (join "/" ["home","evan","Desktop"])]
30+ test "join slashes" <| assertEqual "home/evan/Desktop" (join "/" ["home","evan","Desktop"])
31+ ]
24
32
25 endsWithTest = test "endsWith Check" (assert <| endsWith "h" "th")
33 endsWithTest = test "endsWith Check" (assert <| endsWith "h" "th")
26− in List.concat [isEmptyTests, [lengthTest, reverseTest, repeatTest], unconsTests, [appendTest, concatTest], splitTests, joinTests, [endsWithTest]]
34+ in suite "String Tests" [isEmptyTests, lengthTest, reverseTest, repeatTest, unconsTests, appendTest, concatTest, splitTests, joinTests, endsWithTest]
tests/elm/Test/Trampoline.elm+3−3
@@ -21,9 +21,9 @@ goodSum n =
21 _ -> Continue (\_ -> sumT (x-1) (acc+x))
21 _ -> Continue (\_ -> sumT (x-1) (acc+x))
22 in trampoline <| sumT n 0
22 in trampoline <| sumT n 0
23
23
24−tests : [Test]
24+tests : Test
25tests =
25tests =
26 let mkLoopCheck n = test ("Equivalent Loop Check #"++ show n) (assertEqual (badSum n) (goodSum n))
26 let mkLoopCheck n = test ("Equivalent Loop Check #"++ show n) (assertEqual (badSum n) (goodSum n))
27− loopChecks = map mkLoopCheck [0..25]
27+ loopChecks = suite "Equivalent to untrampolined Tests" <| map mkLoopCheck [0..25]
28 noStackOverflow = test "Trampoline Deep Recursion Test" (assertEqual 500000500000 (goodSum 1000000))
28 noStackOverflow = test "Trampoline Deep Recursion Test" (assertEqual 500000500000 (goodSum 1000000))
29− in noStackOverflow :: loopChecks
29+ in suite "Trampoline Tests" [noStackOverflow, loopChecks]