Skip to content

Commit

Permalink
Merge pull request #36 from purescript-contrib/updates
Browse files Browse the repository at this point in the history
Updates for PureScript 0.11
  • Loading branch information
garyb authored Apr 8, 2017
2 parents 87af84f + 0049933 commit 101b895
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
install:
- npm install -g bower
- npm install
Expand Down
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
},
"license": "MIT",
"dependencies": {
"purescript-argonaut-codecs": "^2.0.0",
"purescript-argonaut-core": "^2.0.0",
"purescript-argonaut-traversals": "^2.0.0"
"purescript-argonaut-codecs": "^3.0.0",
"purescript-argonaut-core": "^3.1.0",
"purescript-argonaut-traversals": "^3.0.0"
},
"devDependencies": {
"purescript-console": "^2.0.0",
"purescript-strongcheck": "^2.0.0"
"purescript-console": "^3.0.0",
"purescript-strongcheck": "^3.1.0"
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"test": "pulp build --include examples --censor-lib --strict && pulp test"
},
"devDependencies": {
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"purescript": "^0.10.1",
"rimraf": "^2.5.4"
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.6.1"
}
}
10 changes: 4 additions & 6 deletions src/Data/Argonaut.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ module Data.Argonaut
, module Data.Argonaut.Encode
, module Data.Argonaut.JCursor
, module Data.Argonaut.Parser
, module Data.Argonaut.Printer
, module Data.Argonaut.Prisms
, module Data.Argonaut.Traversals
) where

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, jsonEmptyArray, jsonEmptyObject, jsonFalse, jsonNull, jsonSingletonArray, jsonSingletonObject, jsonTrue, jsonZero, toArray, toBoolean, toNull, toNumber, toObject, toString)
import Data.Argonaut.Decode (class DecodeJson, decodeJson, gDecodeJson, gDecodeJson', getField, (.?))
import Data.Argonaut.Encode (class EncodeJson, assoc, encodeJson, extend, gEncodeJson, gEncodeJson', (:=), (~>))
import Data.Argonaut.JCursor (JCursor(..), JsonPrim(..), cursorGet, cursorSet, downField, downIndex, exactNull, fail, fromPrims, inferEmpty, insideOut, primBool, primNull, primNum, primStr, primToJson, runJsonPrim, toPrims)
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, jsonFalse, jsonNull, jsonSingletonArray, jsonSingletonObject, jsonTrue, jsonZero, toArray, toBoolean, toNull, toNumber, toObject, toString)
import Data.Argonaut.Decode (class DecodeJson, decodeJson, getField, (.?))
import Data.Argonaut.Encode (class EncodeJson, assoc, encodeJson, extend, (:=), (~>))
import Data.Argonaut.JCursor (JCursor(..), JsonPrim(..), cursorGet, cursorSet, downField, downIndex, fail, fromPrims, inferEmpty, insideOut, primBool, primNull, primNum, primStr, primToJson, runJsonPrim, toPrims)
import Data.Argonaut.Parser (jsonParser)
import Data.Argonaut.Printer (class Printer, printJson)
import Data.Argonaut.Prisms (_Array, _Boolean, _Null, _Number, _Object, _String)
import Data.Argonaut.Traversals (_JsonArray, _JsonBoolean, _JsonNull, _JsonNumber, _JsonObject, _JsonString)
48 changes: 4 additions & 44 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,21 @@ import Prelude

import Control.Monad.Eff.Console (log)

import Data.Argonaut (Json, fromString, encodeJson, decodeJson, fromObject, fromArray, fromNumber, fromBoolean, jsonNull, (.?))
import Data.Argonaut (Json, decodeJson, encodeJson, fromString, (.?))
import Data.Argonaut.JCursor (JCursor(..), toPrims, fromPrims)
import Data.Array (zipWith, nubBy, length)
import Data.Argonaut.Gen (genJson)
import Data.Either (Either(..))
import Data.List (fromFoldable)
import Data.Maybe (Maybe(..))
import Data.StrMap as M
import Data.Tuple (Tuple(..), fst)

import Test.StrongCheck (SC, Result, assert, quickCheck', (<?>))
import Test.StrongCheck.Arbitrary (class Arbitrary, arbitrary)
import Test.StrongCheck.Data.AlphaNumString (AlphaNumString(..))
import Test.StrongCheck.Gen (Gen, Size, showSample, chooseInt, sized, frequency, oneOf, vectorOf)
import Test.StrongCheck.Gen (chooseInt, resize)

newtype TestJson = TestJson Json

genJNull :: Gen Json
genJNull = pure jsonNull

genJBool :: Gen Json
genJBool = fromBoolean <$> arbitrary

genJNumber :: Gen Json
genJNumber = fromNumber <$> arbitrary

genJString :: Gen Json
genJString = fromString <$> arbitrary

genJArray :: Size -> Gen Json
genJArray sz = fromArray <$> vectorOf sz (genJson $ sz - 1)

genJObject :: Size -> Gen Json
genJObject sz = do
v <- vectorOf sz (genJson $ sz - 1)
k <- vectorOf (length v) (arbitrary :: Gen AlphaNumString)
let
f (AlphaNumString s) = s <> "x"
k' = f <$> k
pure $ fromObject <<< M.fromFoldable <<< nubBy (\a b -> (fst a) == (fst b)) $ zipWith Tuple k' v

genJson :: Size -> Gen Json
genJson 0 = oneOf genJNull [genJBool, genJNumber, genJString]
genJson n = frequency (Tuple 1.0 genJNull) rest where
rest = fromFoldable [Tuple 2.0 genJBool,
Tuple 2.0 genJNumber,
Tuple 3.0 genJString,
Tuple 1.0 (genJArray n),
Tuple 1.0 (genJObject n)]


instance arbitraryJson :: Arbitrary TestJson where
arbitrary = TestJson <$> sized genJson
arbitrary = TestJson <$> (resize 5 genJson)

prop_encode_then_decode :: TestJson -> Boolean
prop_encode_then_decode (TestJson json) =
Expand Down Expand Up @@ -89,9 +52,6 @@ prop_jcursor_serialization (TestJCursor c) =

main :: SC () Unit
main = do
log "Showing small sample of JSON"
showSample (genJson 10)

log "Testing that any JSON can be encoded and then decoded"
quickCheck' 20 prop_encode_then_decode

Expand Down

0 comments on commit 101b895

Please sign in to comment.