Skip to content

Commit 9d09e4d

Browse files
committed
Add some basic tests
1 parent a95dfbb commit 9d09e4d

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

bower.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"dependencies": {
1212
"purescript-eff": "~0.1.0",
1313
"purescript-maybe": "~0.3.1"
14+
},
15+
"devDependencies": {
16+
"purescript-assert": "~0.1.1"
1417
}
1518
}

test/Main.purs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,49 @@ module Test.Main where
22

33
import Prelude
44
import Control.Monad.Eff
5+
import Control.Monad.Eff.Console (log)
6+
import Test.Assert
57

6-
-- TODO
7-
main :: forall e. Eff e Unit
8-
main = return unit
8+
import Node.Buffer
9+
10+
main :: Eff _ Unit
11+
main = do
12+
log "Testing..."
13+
log "Reading and writing"
14+
testReadWrite
15+
log "fromArray"
16+
testFromArray
17+
log "toArray"
18+
testToArray
19+
20+
testReadWrite :: Eff _ Unit
21+
testReadWrite = do
22+
buf <- create 1
23+
let val = 42
24+
write UInt8 val 0 buf
25+
readVal <- read UInt8 0 buf
26+
27+
assertEq val readVal
28+
29+
testFromArray :: Eff _ Unit
30+
testFromArray = do
31+
buf <- fromArray [1,2,3,4,5]
32+
readVal <- read UInt8 2 buf
33+
34+
assertEq 3 readVal
35+
36+
testToArray :: Eff _ Unit
37+
testToArray = do
38+
let val = [1,2,67,3,3,7,8,3,4,237]
39+
40+
buf <- fromArray val
41+
valOut <- toArray buf
42+
43+
assertEq val valOut
44+
45+
assertEq :: forall a. (Eq a, Show a) => a -> a -> Eff _ Unit
46+
assertEq x y =
47+
if x == y
48+
then return unit
49+
else let msg = show x ++ " and " ++ show y ++ " were not equal."
50+
in assert' msg false

0 commit comments

Comments
 (0)