Skip to content

Commit

Permalink
Merge pull request #27 from passy/psc-074-upgrade
Browse files Browse the repository at this point in the history
Upgrade for psc 0.7.4
  • Loading branch information
jdegoes committed Sep 8, 2015
2 parents dab77ed + 5718360 commit 5ae17cb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
language: node_js
sudo: false
node_js:
- 0.10
env:
- TAG=v0.7.0
install:
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- sudo tar zxvf $HOME/purescript.tar.gz -C /usr/local/bin purescript/psc{,i,-docs,-bundle} --strip-components=1
- sudo chmod a+x /usr/local/bin/psc{,i,-docs,-bundle}
- npm install bower gulp -g
- npm install -g bower gulp purescript
- npm install && bower install
script:
- gulp test-make
- gulp test
11 changes: 6 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
],
"license": "MIT",
"dependencies": {
"purescript-argonaut-traversals": "^0.1.0",
"purescript-argonaut-core": "^0.1.0",
"purescript-argonaut-codecs": "^0.1.0"
"purescript-argonaut-traversals": "^0.2.0",
"purescript-argonaut-core": "^0.2.0",
"purescript-argonaut-codecs": "^0.3.0"
},
"devDependencies": {
"purescript-console": "^0.1.0",
"purescript-strongcheck": "^0.10.0"
"purescript-strongcheck": "^0.12.0"
},
"resolutions": {
"purescript-lens": "^0.8.0"
"purescript-lens": "^0.8.0",
"purescript-argonaut-codecs": "^0.3.0"
}
}
49 changes: 29 additions & 20 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import Data.Argonaut.Core (Json())
import Data.Either
import Data.Tuple
import Data.Maybe
import Data.Array
import Data.Array
import Data.List (toList)
import Control.Monad.Eff.Console
import qualified Data.StrMap as M

import Test.StrongCheck
import Test.StrongCheck.Gen

newtype TestJson = TestJson Json

genJNull :: Gen Json
genJNull = pure jsonNull

Expand Down Expand Up @@ -48,30 +50,38 @@ genJson n = frequency (Tuple 1.0 genJNull) rest where
Tuple 1.0 (genJArray n),
Tuple 1.0 (genJObject n)]

instance arbitraryJson :: Arbitrary Json where
arbitrary = sized genJson

prop_encode_then_decode :: Json -> Boolean
prop_encode_then_decode json =
instance arbitraryJson :: Arbitrary TestJson where
arbitrary = TestJson <$> sized genJson

prop_encode_then_decode :: TestJson -> Boolean
prop_encode_then_decode (TestJson json) =
Right json == (decodeJson $ encodeJson $ json)

prop_decode_then_encode :: Json -> Boolean
prop_decode_then_encode json =
prop_decode_then_encode :: TestJson -> Boolean
prop_decode_then_encode (TestJson json) =
let decoded = (decodeJson json) :: Either String Json in
Right json == (decoded >>= (encodeJson >>> pure))

prop_toPrims_fromPrims :: Json -> Result
prop_toPrims_fromPrims j = Just j == fromPrims (toPrims j) <?> "fromPrims.toPrims: " ++ show (toPrims j) ++ "\n\n" ++ show (fromPrims (toPrims j))
prop_toPrims_fromPrims :: TestJson -> Result
prop_toPrims_fromPrims (TestJson j) =
Just j == fromPrims (toPrims j) <?> "fromPrims.toPrims: " ++ show (toPrims j) ++ "\n\n" ++ show (fromPrims (toPrims j))

newtype TestJCursor = TestJCursor JCursor

instance arbJCursor :: Arbitrary JCursor where
arbitrary = do i <- chooseInt 0.0 2.0
r <- if i == 0 then pure JCursorTop
else if i == 1 then JField <$> arbitrary <*> arbitrary
else JIndex <$> arbitrary <*> arbitrary
return r
runTestJCursor :: TestJCursor -> JCursor
runTestJCursor (TestJCursor j) = j

prop_jcursor_serialization :: JCursor -> Result
prop_jcursor_serialization c =
instance arbJCursor :: Arbitrary TestJCursor where
arbitrary = do
i <- chooseInt 0.0 2.0
r <- if i == 0 then pure JCursorTop
else if i == 1 then JField <$> arbitrary <*> (runTestJCursor <$> arbitrary)
else JIndex <$> arbitrary <*> (runTestJCursor <$> arbitrary)
return $ TestJCursor r

prop_jcursor_serialization :: TestJCursor -> Result
prop_jcursor_serialization (TestJCursor c) =
(decodeJson (encodeJson c) == Right c) <?> "JCursor: " ++ show c

main = do
Expand All @@ -91,6 +101,5 @@ main = do
quickCheck' 20 prop_jcursor_serialization

log "Testing .? combinator"
assert $ let bar = fromString "bar"
in (M.singleton "foo" bar) .? "foo" == Right bar

assert $ let bar = fromString "bar"
in (M.singleton "foo" bar) .? "foo" == Right bar

0 comments on commit 5ae17cb

Please sign in to comment.