Skip to content

Commit c7c1161

Browse files
authored
Merge pull request #40 from purescript-contrib/compiler/0.12
Compiler/0.12
2 parents 448d1dd + cb7c83e commit c7c1161

File tree

4 files changed

+38
-63
lines changed

4 files changed

+38
-63
lines changed

bower.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
},
1212
"license": "MIT",
1313
"dependencies": {
14-
"purescript-argonaut-codecs": "^3.0.0",
15-
"purescript-argonaut-core": "^3.1.0",
16-
"purescript-argonaut-traversals": "^3.0.0"
14+
"purescript-argonaut-codecs": "^4.0.0",
15+
"purescript-argonaut-core": "^4.0.0",
16+
"purescript-argonaut-traversals": "^4.0.0"
1717
},
1818
"devDependencies": {
19-
"purescript-console": "^3.0.0",
20-
"purescript-strongcheck": "^3.1.0"
19+
"purescript-console": "^4.0.0",
20+
"purescript-quickcheck": "^5.0.0"
2121
}
2222
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"test": "pulp build --include examples -- --censor-lib --strict && pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^11.0.2",
10-
"purescript-psa": "^0.5.1",
11-
"purescript": "^0.11.6",
9+
"pulp": "^12.0.0",
10+
"purescript-psa": "^0.6.0",
11+
"purescript": "^0.12.0",
1212
"rimraf": "^2.6.2"
1313
}
1414
}

src/Data/Argonaut.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Data.Argonaut
88
, module Data.Argonaut.Traversals
99
) where
1010

11-
import Data.Argonaut.Core (JArray, JAssoc, JBoolean, JNull, JNumber, JObject, JString, Json, foldJson, foldJsonArray, foldJsonBoolean, foldJsonNull, foldJsonNumber, foldJsonObject, foldJsonString, fromArray, fromBoolean, fromNull, fromNumber, fromObject, fromString, isArray, isBoolean, isNull, isNumber, isObject, isString, jNull, jsonEmptyArray, jsonEmptyObject, jsonEmptyString, jsonFalse, jsonNull, jsonSingletonArray, jsonSingletonObject, jsonTrue, jsonZero, stringify, toArray, toBoolean, toNull, toNumber, toObject, toString)
11+
import Data.Argonaut.Core (Json, caseJson, caseJsonArray, caseJsonBoolean, caseJsonNull, caseJsonNumber, caseJsonObject, caseJsonString, fromArray, fromBoolean, fromNumber, fromObject, fromString, isArray, isBoolean, isNull, isNumber, isObject, isString, jsonEmptyArray, jsonEmptyObject, jsonEmptyString, jsonFalse, jsonNull, jsonSingletonArray, jsonSingletonObject, jsonTrue, jsonZero, stringify, toArray, toBoolean, toNull, toNumber, toObject, toString)
1212
import Data.Argonaut.Decode (class DecodeJson, decodeJson, defaultField, getField, getFieldOptional, (.?), (.?=), (.??))
1313
import Data.Argonaut.Encode (class EncodeJson, assoc, encodeJson, extend, (:=), (~>))
1414
import Data.Argonaut.JCursor (JCursor(..), JsonPrim(..), cursorGet, cursorSet, downField, downIndex, fail, fromPrims, inferEmpty, insideOut, primBool, primNull, primNum, primStr, primToJson, runJsonPrim, toPrims)

test/Test/Main.purs

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,43 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Monad.Eff.Console (log)
6-
7-
import Data.Argonaut (Json, decodeJson, encodeJson, fromString, (.?))
8-
import Data.Argonaut.JCursor (JCursor(..), toPrims, fromPrims)
5+
import Data.Argonaut (Json, decodeJson, encodeJson, stringify)
96
import Data.Argonaut.Gen (genJson)
7+
import Data.Argonaut.JCursor (JCursor(..), toPrims, fromPrims)
108
import Data.Either (Either(..))
9+
import Data.Foldable (foldMap)
1110
import Data.Maybe (Maybe(..))
12-
import Data.StrMap as M
13-
14-
import Test.StrongCheck (SC, Result, assert, quickCheck', (<?>))
15-
import Test.StrongCheck.Arbitrary (class Arbitrary, arbitrary)
16-
import Test.StrongCheck.Gen (chooseInt, resize)
17-
18-
newtype TestJson = TestJson Json
19-
20-
instance arbitraryJson :: Arbitrary TestJson where
21-
arbitrary = TestJson <$> (resize 5 genJson)
22-
23-
prop_encode_then_decode :: TestJson -> Boolean
24-
prop_encode_then_decode (TestJson json) =
25-
Right json == (decodeJson $ encodeJson $ json)
26-
27-
prop_decode_then_encode :: TestJson -> Boolean
28-
prop_decode_then_encode (TestJson json) =
29-
let decoded = (decodeJson json) :: Either String Json in
30-
Right json == (decoded >>= (encodeJson >>> pure))
31-
32-
prop_toPrims_fromPrims :: TestJson -> Result
33-
prop_toPrims_fromPrims (TestJson j) =
34-
Just j == fromPrims (toPrims j) <?> "fromPrims.toPrims: " <> show (toPrims j) <> "\n\n" <> show (fromPrims (toPrims j))
35-
36-
newtype TestJCursor = TestJCursor JCursor
37-
38-
runTestJCursor :: TestJCursor -> JCursor
39-
runTestJCursor (TestJCursor j) = j
40-
41-
instance arbJCursor :: Arbitrary TestJCursor where
42-
arbitrary = do
11+
import Data.String.Gen (genUnicodeString)
12+
import Effect (Effect)
13+
import Effect.Console (log)
14+
import Test.QuickCheck (Result, quickCheck, (<?>))
15+
import Test.QuickCheck.Gen (Gen, chooseInt, resize)
16+
17+
genTestJson :: Gen Json
18+
genTestJson = resize 5 genJson
19+
20+
prop_toPrims_fromPrims :: Gen Result
21+
prop_toPrims_fromPrims = do
22+
j <- genTestJson
23+
pure $ Just j == fromPrims (toPrims j) <?> "fromPrims.toPrims: " <> show (toPrims j) <> "\n\n" <> foldMap stringify (fromPrims (toPrims j))
24+
25+
genTestJCursor :: Gen JCursor
26+
genTestJCursor = do
4327
i <- chooseInt 0 2
4428
r <- if i == 0 then pure JCursorTop
45-
else if i == 1 then JField <$> arbitrary <*> (runTestJCursor <$> arbitrary)
46-
else JIndex <$> arbitrary <*> (runTestJCursor <$> arbitrary)
47-
pure $ TestJCursor r
29+
else if i == 1 then JField <$> genUnicodeString <*> genTestJCursor
30+
else JIndex <$> chooseInt bottom top <*> genTestJCursor
31+
pure r
4832

49-
prop_jcursor_serialization :: TestJCursor -> Result
50-
prop_jcursor_serialization (TestJCursor c) =
51-
(decodeJson (encodeJson c) == Right c) <?> "JCursor: " <> show c
33+
prop_jcursor_serialization :: Gen Result
34+
prop_jcursor_serialization = do
35+
c <- genTestJCursor
36+
pure $ (decodeJson (encodeJson c) == Right c) <?> "JCursor: " <> show c
5237

53-
main :: SC () Unit
38+
main :: Effect Unit
5439
main = do
55-
log "Testing that any JSON can be encoded and then decoded"
56-
quickCheck' 20 prop_encode_then_decode
57-
58-
log "Testing that any JSON can be decoded and then encoded"
59-
quickCheck' 20 prop_decode_then_encode
60-
6140
log "Testing that toPrims / fromPrims inverses"
62-
quickCheck' 20 prop_toPrims_fromPrims
41+
quickCheck prop_toPrims_fromPrims
6342

6443
log "Testing that JCursor can be encoded / decoded from JSON"
65-
quickCheck' 20 prop_jcursor_serialization
66-
67-
log "Testing .? combinator"
68-
assert $ let bar = fromString "bar"
69-
in (M.singleton "foo" bar) .? "foo" == Right bar
44+
quickCheck prop_jcursor_serialization

0 commit comments

Comments
 (0)