Skip to content

Add decode and encode tests. #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ install:
- npm install -g bower
- npm install
script:
- bower install --production
- bower install
- npm run -s build
- npm run -s test
after_success:
Expand Down
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"purescript-strings": "^4.0.0",
"purescript-tuples": "^5.0.0",
"purescript-foldable-traversable": "^4.1.1"
},
"devDependencies": {
"purescript-assert": "^4.1.0"
}
}
46 changes: 45 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,51 @@ module Test.Main where

import Prelude

import Data.FormURLEncoded (FormURLEncoded(..), decode, encode)
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Console (log)
import Test.Assert (assert)

main :: Effect Unit
main = pure unit
main = do

testDecode "a=aa&b=bb" (Just $ FormURLEncoded [ Tuple "a" $ Just "aa", Tuple "b" $ Just "bb" ])

testDecode "this=this%3Dthis" (Just $ FormURLEncoded [ Tuple "this" $ Just "this=this" ])

testDecode "&x=x&&y=y&z=" $
Just $ FormURLEncoded
[ Tuple "" Nothing
, Tuple "x" $ Just "x"
, Tuple "" Nothing
, Tuple "y" $ Just "y"
, Tuple "z" $ Just ""
]

testDecode "a=b&%8A=c" Nothing

testEncode (FormURLEncoded [ Tuple "a" $ Just "aa", Tuple "b" $ Just "bb" ]) $ Just "a=aa&b=bb"

testEncode (FormURLEncoded [ Tuple "this" $ Just "this=this" ]) $ Just "this=this%3Dthis"

testEncode
(FormURLEncoded
[ Tuple "" Nothing
, Tuple "x" $ Just "x"
, Tuple "" Nothing
, Tuple "y" $ Just "y"
, Tuple "z" $ Just ""
])
(Just "&x=x&&y=y&z=")

where

testDecode :: String -> Maybe FormURLEncoded -> Effect Unit
testDecode input expected =
(log $ "decode \"" <> input <> "\" == " <> show expected) *> assert (decode input == expected)

testEncode :: FormURLEncoded -> Maybe String -> Effect Unit
testEncode input expected =
(log $ "encode " <> show input <> " == \"" <> show expected <> "\"") *> assert (encode input == expected)