Skip to content

Commit 59d8798

Browse files
authored
Merge pull request #30 from purescript-contrib/0.9-updates
Updates for PureScript 0.9.1
2 parents 24db0e5 + 548da98 commit 59d8798

File tree

7 files changed

+103
-101
lines changed

7 files changed

+103
-101
lines changed

.gitignore

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/.*
22
!/.gitignore
3+
!/.jscsrc
4+
!/.jshintrc
35
!/.travis.yml
4-
bower_components/
5-
node_modules/
6-
output/
7-
dist/
8-
tmp/
9-
npm-debug.log
10-
test/test.js
6+
/bower_components/
7+
/node_modules/
8+
/output/

.travis.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
language: node_js
2-
sudo: false
3-
node_js:
4-
- 5
2+
dist: trusty
3+
sudo: required
4+
node_js: 6
55
install:
66
- npm install -g bower
77
- npm install
88
script:
9-
- npm test
9+
- bower install --production
10+
- npm run -s build
11+
- bower install
12+
- npm -s test
1013
after_success:
1114
- >-
1215
test $TRAVIS_TAG &&
13-
node_modules/.bin/psc-publish > .pursuit.json &&
14-
curl -X POST http://pursuit.purescript.org/packages \
15-
-d @.pursuit.json \
16-
-H 'Accept: application/json' \
17-
-H "Authorization: token ${GITHUB_TOKEN}"
16+
echo $GITHUB_TOKEN | pulp login &&
17+
echo y | pulp publish --no-push

bower.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purescript-argonaut",
3-
"description": "PureScript version of Argonaut",
3+
"description": "PureScript's implementation of Argonaut",
44
"authors": [
55
"Hardy Jones <>",
66
"John A. De Goes <john@degoes.net>"
@@ -11,12 +11,12 @@
1111
},
1212
"license": "MIT",
1313
"dependencies": {
14-
"purescript-argonaut-traversals": "^0.7.0",
15-
"purescript-argonaut-core": "^0.2.1",
16-
"purescript-argonaut-codecs": "^0.6.0"
14+
"purescript-argonaut-codecs": "^1.0.0",
15+
"purescript-argonaut-core": "^1.0.0",
16+
"purescript-argonaut-traversals": "^1.0.0"
1717
},
1818
"devDependencies": {
19-
"purescript-console": "^0.1.0",
20-
"purescript-strongcheck": "^0.14.3"
19+
"purescript-console": "^1.0.0",
20+
"purescript-strongcheck": "^1.1.1"
2121
}
2222
}
Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
module Examples.Data.Argonaut.Record where
22

3-
import Data.Argonaut ((~>), (:=), (.?), jsonEmptyObject, printJson)
4-
import Data.Argonaut.Encode (EncodeJson, encodeJson)
5-
import Data.Argonaut.Decode (DecodeJson, decodeJson)
6-
import Data.Maybe (Maybe(..))
7-
8-
import Debug.Trace (print)
9-
10-
newtype Foo = Foo
11-
{ foo :: Maybe Number
12-
, bar :: Maybe String
13-
}
14-
15-
instance decodeJsonFoo :: DecodeJson Foo where
16-
decodeJson json = do
17-
obj <- decodeJson json
18-
foo <- obj .? "foo"
19-
bar <- obj .? "bar"
20-
pure $ Foo {foo: foo, bar: bar}
21-
22-
instance encodeJsonFoo :: EncodeJson Foo where
23-
encodeJson (Foo f)
24-
= "bar" := f.bar
25-
~> "foo" := f.foo
26-
~> jsonEmptyObject
27-
28-
instance showFoo :: Show Foo where
29-
show (Foo f) = "Foo {foo: " ++ show f.foo ++ ", bar:" ++ show f.bar ++ "}"
30-
31-
foo :: Foo
32-
foo = Foo {foo: Just 42, bar: Nothing}
33-
34-
main = do
35-
print $ "raw foo is: " ++ show foo
36-
print $ "encoded foo is: " ++ printJson (encodeJson foo)
3+
import Prelude
4+
5+
import Data.Argonaut (class EncodeJson, class DecodeJson, Json, encodeJson, fromArray, decodeJson, jsonEmptyObject, (~>), (:=), (.?))
6+
import Data.Either (Either)
7+
import Data.Traversable (traverse)
8+
9+
newtype BlogPost = BlogPost
10+
{ id :: Int
11+
, title :: String
12+
, categories :: String
13+
, content :: String
14+
}
15+
16+
instance decodeJsonBlogPost :: DecodeJson BlogPost where
17+
decodeJson json = do
18+
obj <- decodeJson json
19+
id <- obj .? "id"
20+
title <- obj .? "title"
21+
categories <- obj .? "categories"
22+
content <- obj .? "content"
23+
pure $ BlogPost { id, title, categories, content }
24+
25+
instance encodeJson :: EncodeJson BlogPost where
26+
encodeJson (BlogPost post)
27+
= "id" := post.id
28+
~> "title" := post.title
29+
~> "categories" := post.categories
30+
~> "content" := post.content
31+
~> jsonEmptyObject
32+
33+
type BlogPostArray = Array BlogPost
34+
35+
decodeBlogPostArray :: Json -> Either String BlogPostArray
36+
decodeBlogPostArray json = decodeJson json >>= traverse decodeJson
37+
38+
encodeBlogPostArray :: BlogPostArray -> Json
39+
encodeBlogPostArray bpa = fromArray $ encodeJson <$> bpa

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"private": true,
33
"scripts": {
4-
"postinstall": "pulp dep install",
54
"clean": "rimraf output && rimraf .pulp-cache",
6-
"build": "pulp build",
7-
"test": "pulp test"
5+
"build": "pulp build --censor-lib --strict",
6+
"test": "pulp build --include examples --censor-lib --strict && pulp test"
87
},
98
"devDependencies": {
10-
"pulp": "^7.0.0",
11-
"purescript": "^0.7.6",
9+
"pulp": "^9.0.1",
10+
"purescript-psa": "^0.3.9",
11+
"purescript": "^0.9.1",
1212
"rimraf": "^2.4.4"
1313
}
1414
}

src/Data/Argonaut.purs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
module Data.Argonaut (
2-
module Data.Argonaut.Combinators,
3-
module Data.Argonaut.Core,
4-
module Data.Argonaut.Decode,
5-
module Data.Argonaut.Encode,
6-
module Data.Argonaut.Parser,
7-
module Data.Argonaut.Printer,
8-
module Data.Argonaut.JCursor,
9-
module Data.Argonaut.Prisms,
10-
module Data.Argonaut.Traversals
1+
module Data.Argonaut
2+
( module Data.Argonaut.Core
3+
, module Data.Argonaut.Decode
4+
, module Data.Argonaut.Encode
5+
, module Data.Argonaut.JCursor
6+
, module Data.Argonaut.Parser
7+
, module Data.Argonaut.Printer
8+
, module Data.Argonaut.Prisms
9+
, module Data.Argonaut.Traversals
1110
) where
1211

13-
import Data.Argonaut.Combinators
14-
import Data.Argonaut.Core
15-
import Data.Argonaut.Decode
16-
import Data.Argonaut.Encode
17-
import Data.Argonaut.Parser
18-
import Data.Argonaut.Printer
19-
import Data.Argonaut.JCursor
20-
import Data.Argonaut.Prisms
21-
import Data.Argonaut.Traversals
22-
12+
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)
13+
import Data.Argonaut.Decode (class DecodeJson, decodeJson, gDecodeJson, gDecodeJson', getField, (.?))
14+
import Data.Argonaut.Encode (class EncodeJson, assoc, encodeJson, extend, gEncodeJson, gEncodeJson', (:=), (~>))
15+
import Data.Argonaut.JCursor (JCursor(..), JsonPrim(..), cursorGet, cursorSet, downField, downIndex, exactNull, fail, fromPrims, inferEmpty, insideOut, primBool, primNull, primNum, primStr, primToJson, runJsonPrim, toPrims)
16+
import Data.Argonaut.Parser (jsonParser)
17+
import Data.Argonaut.Printer (class Printer, printJson)
18+
import Data.Argonaut.Prisms (_Array, _Boolean, _Null, _Number, _Object, _String)
19+
import Data.Argonaut.Traversals (_JsonArray, _JsonBoolean, _JsonNull, _JsonNumber, _JsonObject, _JsonString)

test/Test/Main.purs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ module Test.Main where
22

33
import Prelude
44

5-
import Data.Argonaut
6-
import Data.Argonaut.JCursor
7-
import Data.Argonaut.Core (Json())
8-
import Data.Either
9-
import Data.Tuple
10-
import Data.Maybe
11-
import Data.Array
12-
import Data.List (toList)
13-
import Control.Monad.Eff.Console
14-
import qualified Data.StrMap as M
15-
16-
import Test.StrongCheck
17-
import Test.StrongCheck.Gen
5+
import Control.Monad.Eff.Console (log)
6+
7+
import Data.Argonaut (Json, fromString, encodeJson, decodeJson, fromObject, fromArray, fromNumber, fromBoolean, jsonNull, (.?))
8+
import Data.Argonaut.JCursor (JCursor(..), toPrims, fromPrims)
9+
import Data.Array (zipWith, nubBy, length)
10+
import Data.Either (Either(..))
11+
import Data.List (fromFoldable)
12+
import Data.Maybe (Maybe(..))
13+
import Data.StrMap as M
14+
import Data.Tuple (Tuple(..), fst)
15+
16+
import Test.StrongCheck (SC, Result, assert, quickCheck', (<?>))
17+
import Test.StrongCheck.Arbitrary (class Arbitrary, arbitrary)
18+
import Test.StrongCheck.Data.AlphaNumString (AlphaNumString(..))
19+
import Test.StrongCheck.Gen (Gen, Size, showSample, chooseInt, sized, frequency, oneOf, vectorOf)
1820

1921
newtype TestJson = TestJson Json
2022

@@ -37,14 +39,15 @@ genJObject :: Size -> Gen Json
3739
genJObject sz = do
3840
v <- vectorOf sz (genJson $ sz - 1)
3941
k <- vectorOf (length v) (arbitrary :: Gen AlphaNumString)
40-
return $ let f (AlphaNumString s) = s ++ "x"
41-
k' = f <$> k
42-
in fromObject <<< M.fromList <<< toList <<< nubBy (\a b -> (fst a) == (fst b)) $ zipWith Tuple k' v
42+
let
43+
f (AlphaNumString s) = s <> "x"
44+
k' = f <$> k
45+
pure $ fromObject <<< M.fromList <<< fromFoldable <<< nubBy (\a b -> (fst a) == (fst b)) $ zipWith Tuple k' v
4346

4447
genJson :: Size -> Gen Json
4548
genJson 0 = oneOf genJNull [genJBool, genJNumber, genJString]
4649
genJson n = frequency (Tuple 1.0 genJNull) rest where
47-
rest = toList [Tuple 2.0 genJBool,
50+
rest = fromFoldable [Tuple 2.0 genJBool,
4851
Tuple 2.0 genJNumber,
4952
Tuple 3.0 genJString,
5053
Tuple 1.0 (genJArray n),
@@ -65,7 +68,7 @@ prop_decode_then_encode (TestJson json) =
6568

6669
prop_toPrims_fromPrims :: TestJson -> Result
6770
prop_toPrims_fromPrims (TestJson j) =
68-
Just j == fromPrims (toPrims j) <?> "fromPrims.toPrims: " ++ show (toPrims j) ++ "\n\n" ++ show (fromPrims (toPrims j))
71+
Just j == fromPrims (toPrims j) <?> "fromPrims.toPrims: " <> show (toPrims j) <> "\n\n" <> show (fromPrims (toPrims j))
6972

7073
newtype TestJCursor = TestJCursor JCursor
7174

@@ -78,12 +81,13 @@ instance arbJCursor :: Arbitrary TestJCursor where
7881
r <- if i == 0 then pure JCursorTop
7982
else if i == 1 then JField <$> arbitrary <*> (runTestJCursor <$> arbitrary)
8083
else JIndex <$> arbitrary <*> (runTestJCursor <$> arbitrary)
81-
return $ TestJCursor r
84+
pure $ TestJCursor r
8285

8386
prop_jcursor_serialization :: TestJCursor -> Result
8487
prop_jcursor_serialization (TestJCursor c) =
85-
(decodeJson (encodeJson c) == Right c) <?> "JCursor: " ++ show c
88+
(decodeJson (encodeJson c) == Right c) <?> "JCursor: " <> show c
8689

90+
main :: SC () Unit
8791
main = do
8892
log "Showing small sample of JSON"
8993
showSample (genJson 10)

0 commit comments

Comments
 (0)