add basic tests for replacments

This commit is contained in:
Matthew Griffith 2022-02-09 09:21:14 -05:00
parent 9b173b8650
commit f270cefaee
2 changed files with 103 additions and 0 deletions

28
elm.json Normal file
View File

@ -0,0 +1,28 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.2.2"
},
"indirect": {
"elm/random": "1.0.0"
}
}
}

75
tests/Replacements.elm Normal file
View File

@ -0,0 +1,75 @@
module Replacements exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Test exposing (..)
suite : Test
suite =
describe "Tests for js code replacements"
[ list
, string
]
list : Test
list =
describe "List"
[ test "List.all" <|
\_ ->
Expect.equal True
(List.all (\i -> i == 1) [ 1, 1, 1, 1 ])
, test "List.append" <|
\_ ->
Expect.equal [ 1, 2, 3, 4, 5, 6 ]
(List.append [ 1, 2, 3 ] [ 4, 5, 6 ])
, test "List.concat" <|
\_ ->
Expect.equal [ 1, 2, 3, 4, 5, 6 ]
(List.concat [ [ 1, 2, 3 ], [ 4, 5, 6 ] ])
, test "List.concatMap" <|
\_ ->
Expect.equal [ 1, 2, 3, 4, 5, 6 ]
(List.concatMap identity [ [ 1, 2, 3 ], [ 4, 5, 6 ] ])
, test "List.filter" <|
\_ ->
Expect.equal [ 1, 2, 3, 4, 5, 6 ]
(List.filter (\_ -> True) [ 1, 2, 3, 4, 5, 6 ])
, test "List.filter (only even)" <|
\_ ->
Expect.equal [ 2, 4, 6 ]
(List.filter (\i -> modBy 2 i == 0) [ 1, 2, 3, 4, 5, 6 ])
, test "List.indexedMap" <|
\_ ->
Expect.equal [ 0, 1, 2, 3, 4, 5 ]
(List.indexedMap (\i n -> i) [ 1, 2, 3, 4, 5, 6 ])
, test "List.intersperse" <|
\_ ->
Expect.equal [ 1, 10, 2, 10, 3, 10, 4, 10, 5, 10, 6 ]
(List.intersperse 10 [ 1, 2, 3, 4, 5, 6 ])
, test "List.take" <|
\_ ->
Expect.equal [ 1, 2 ]
(List.take 2 [ 1, 2, 3, 4, 5, 6 ])
, test "List.unzip" <|
\_ ->
Expect.equal ( [ 1, 2 ], [ 3, 4 ] )
(List.unzip [ ( 1, 3 ), ( 2, 4 ) ])
]
string : Test
string =
describe "String"
[ test "String.repeat 4" <|
\_ ->
Expect.equal
"nananana"
(String.repeat 4 "na")
, test "String.repeat 10" <|
\_ ->
Expect.equal
"nananananananananana"
(String.repeat 10 "na")
]