@@ -2,22 +2,37 @@ module Test.Main where
22
33import Prelude
44import Control.Monad.Eff
5- import Control.Monad.Eff.Console (log )
5+ import Control.Monad.Eff.Console (log , CONSOLE () )
66import Test.Assert
77
88import Node.Buffer
9+ import Node.Encoding
910
10- main :: Eff _ Unit
11+ type Test = forall e . Eff (assert :: ASSERT , buffer :: BUFFER , console :: CONSOLE | e ) Unit
12+
13+ main :: Test
1114main = do
1215 log " Testing..."
16+
1317 log " Reading and writing"
1418 testReadWrite
19+
1520 log " fromArray"
1621 testFromArray
22+
1723 log " toArray"
1824 testToArray
1925
20- testReadWrite :: Eff _ Unit
26+ log " fromString"
27+ testFromString
28+
29+ log " toString"
30+ testToString
31+
32+ log " readString"
33+ testReadString
34+
35+ testReadWrite :: Test
2136testReadWrite = do
2237 buf <- create 1
2338 let val = 42
@@ -26,14 +41,14 @@ testReadWrite = do
2641
2742 assertEq val readVal
2843
29- testFromArray :: Eff _ Unit
44+ testFromArray :: Test
3045testFromArray = do
3146 buf <- fromArray [1 ,2 ,3 ,4 ,5 ]
3247 readVal <- read UInt8 2 buf
3348
3449 assertEq 3 readVal
3550
36- testToArray :: Eff _ Unit
51+ testToArray :: Test
3752testToArray = do
3853 let val = [1 ,2 ,67 ,3 ,3 ,7 ,8 ,3 ,4 ,237 ]
3954
@@ -42,7 +57,34 @@ testToArray = do
4257
4358 assertEq val valOut
4459
45- assertEq :: forall a . (Eq a , Show a ) => a -> a -> Eff _ Unit
60+ testFromString :: Test
61+ testFromString = do
62+ let str = " hello, world"
63+
64+ buf <- fromString str ASCII
65+ val <- read UInt8 6 buf
66+
67+ assertEq val 32 -- ASCII space
68+
69+ testToString :: Test
70+ testToString = do
71+ let str = " hello, world"
72+
73+ buf <- fromString str ASCII
74+ strOut <- toString ASCII buf
75+
76+ assertEq str strOut
77+
78+ testReadString :: Test
79+ testReadString = do
80+ let str = " hello, world"
81+
82+ buf <- fromString str ASCII
83+ strOut <- readString ASCII 7 12 buf
84+
85+ assertEq " world" strOut
86+
87+ assertEq :: forall a . (Eq a , Show a ) => a -> a -> Test
4688assertEq x y =
4789 if x == y
4890 then return unit
0 commit comments