Skip to content

Commit ff50250

Browse files
committed
Add tests for Inject
1 parent 9d1f4a8 commit ff50250

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ install:
1111
- chmod a+x $HOME/purescript
1212
- npm install -g bower
1313
- npm install
14-
- bower install
14+
- bower install --production
1515
script:
1616
- npm run -s build
17+
- bower install
18+
- npm run -s test
1719
after_success:
1820
- >-
1921
test $TRAVIS_TAG &&

bower.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@
2222
"purescript-invariant": "^4.0.0",
2323
"purescript-maybe": "^4.0.0",
2424
"purescript-prelude": "^4.0.0"
25+
},
26+
"devDependencies": {
27+
"purescript-assert": "^4.0.0",
28+
"purescript-console": "^4.0.0",
29+
"purescript-effect": "^2.0.0"
2530
}
2631
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build -- --censor-lib --strict"
5+
"build": "pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
67
},
78
"devDependencies": {
89
"pulp": "^12.2.0",

test/Main.purs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Test.Main where
2+
3+
import Prelude
4+
5+
import Data.Either.Inject (inj, prj)
6+
import Data.Either.Nested (Either3, in1, in2, in3)
7+
import Data.Maybe (Maybe(..))
8+
import Effect (Effect)
9+
import Effect.Console (log)
10+
import Test.Assert (assertEqual)
11+
12+
type MySum = Either3 Boolean String Int
13+
14+
main :: Effect Unit
15+
main = do
16+
log "Test injection"
17+
assertEqual
18+
{ actual: inj true :: MySum
19+
, expected: in1 true
20+
}
21+
assertEqual
22+
{ actual: inj "hello" :: MySum
23+
, expected: in2 "hello"
24+
}
25+
assertEqual
26+
{ actual: inj 100 :: MySum
27+
, expected: in3 100
28+
}
29+
log "Test projection"
30+
assertEqual
31+
{ actual: prj (in1 true :: MySum)
32+
, expected: Just true
33+
}
34+
assertEqual
35+
{ actual: prj (in2 "hello" :: MySum)
36+
, expected: Just "hello"
37+
}
38+
assertEqual
39+
{ actual: prj (in3 100 :: MySum)
40+
, expected: Just 100
41+
}
42+
assertEqual
43+
{ actual: prj (in1 true :: MySum)
44+
, expected: Nothing :: Maybe String
45+
}
46+
assertEqual
47+
{ actual: prj (in2 "hello" :: MySum)
48+
, expected: Nothing :: Maybe Int
49+
}
50+
assertEqual
51+
{ actual: prj (in3 100 :: MySum)
52+
, expected: Nothing :: Maybe Boolean
53+
}

0 commit comments

Comments
 (0)