Skip to content

Commit 0eaafc0

Browse files
Merge pull request #15 from nsaunders/tests
Add decode and encode tests.
2 parents acccb8a + 41c0525 commit 0eaafc0

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install:
1212
- npm install -g bower
1313
- npm install
1414
script:
15-
- bower install --production
15+
- bower install
1616
- npm run -s build
1717
- npm run -s test
1818
after_success:

bower.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"purescript-strings": "^4.0.0",
2222
"purescript-tuples": "^5.0.0",
2323
"purescript-foldable-traversable": "^4.1.1"
24+
},
25+
"devDependencies": {
26+
"purescript-assert": "^4.1.0"
2427
}
2528
}

test/Main.purs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,51 @@ module Test.Main where
22

33
import Prelude
44

5+
import Data.FormURLEncoded (FormURLEncoded(..), decode, encode)
6+
import Data.Maybe (Maybe(..))
7+
import Data.Tuple (Tuple(..))
58
import Effect (Effect)
9+
import Effect.Console (log)
10+
import Test.Assert (assert)
611

712
main :: Effect Unit
8-
main = pure unit
13+
main = do
14+
15+
testDecode "a=aa&b=bb" (Just $ FormURLEncoded [ Tuple "a" $ Just "aa", Tuple "b" $ Just "bb" ])
16+
17+
testDecode "this=this%3Dthis" (Just $ FormURLEncoded [ Tuple "this" $ Just "this=this" ])
18+
19+
testDecode "&x=x&&y=y&z=" $
20+
Just $ FormURLEncoded
21+
[ Tuple "" Nothing
22+
, Tuple "x" $ Just "x"
23+
, Tuple "" Nothing
24+
, Tuple "y" $ Just "y"
25+
, Tuple "z" $ Just ""
26+
]
27+
28+
testDecode "a=b&%8A=c" Nothing
29+
30+
testEncode (FormURLEncoded [ Tuple "a" $ Just "aa", Tuple "b" $ Just "bb" ]) $ Just "a=aa&b=bb"
31+
32+
testEncode (FormURLEncoded [ Tuple "this" $ Just "this=this" ]) $ Just "this=this%3Dthis"
33+
34+
testEncode
35+
(FormURLEncoded
36+
[ Tuple "" Nothing
37+
, Tuple "x" $ Just "x"
38+
, Tuple "" Nothing
39+
, Tuple "y" $ Just "y"
40+
, Tuple "z" $ Just ""
41+
])
42+
(Just "&x=x&&y=y&z=")
43+
44+
where
45+
46+
testDecode :: String -> Maybe FormURLEncoded -> Effect Unit
47+
testDecode input expected =
48+
(log $ "decode \"" <> input <> "\" == " <> show expected) *> assert (decode input == expected)
49+
50+
testEncode :: FormURLEncoded -> Maybe String -> Effect Unit
51+
testEncode input expected =
52+
(log $ "encode " <> show input <> " == \"" <> show expected <> "\"") *> assert (encode input == expected)

0 commit comments

Comments
 (0)