Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
a7dab291
Commit
a7dab291
authored
Jun 16, 2020
by
Justin Woo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle sum type nullary constructors in generic JSON
parent
15953f46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
Argonaut.purs
src/Gargantext/Utils/Argonaut.purs
+9
-0
Spec.purs
test/Gargantext/Utils/Spec.purs
+7
-0
No files found.
src/Gargantext/Utils/Argonaut.purs
View file @
a7dab291
...
@@ -56,6 +56,11 @@ instance genericSumDecodeJsonRepConstructor ::
...
@@ -56,6 +56,11 @@ instance genericSumDecodeJsonRepConstructor ::
argument <- genericSumDecodeJsonRep inner
argument <- genericSumDecodeJsonRep inner
pure $ GR.Constructor argument
pure $ GR.Constructor argument
instance genericSumDecodeJsonRepNoArguments ::
GenericSumDecodeJsonRep (GR.NoArguments) where
genericSumDecodeJsonRep _ = do
pure GR.NoArguments
instance genericSumDecodeJsonRepArgument ::
instance genericSumDecodeJsonRepArgument ::
( Argonaut.DecodeJson a
( Argonaut.DecodeJson a
) => GenericSumDecodeJsonRep (GR.Argument a) where
) => GenericSumDecodeJsonRep (GR.Argument a) where
...
@@ -79,6 +84,10 @@ instance genericSumEncodeJsonRepConstructor ::
...
@@ -79,6 +84,10 @@ instance genericSumEncodeJsonRepConstructor ::
let argument = genericSumEncodeJsonRep inner
let argument = genericSumEncodeJsonRep inner
Argonaut.jsonSingletonObject name argument
Argonaut.jsonSingletonObject name argument
instance genericSumEncodeJsonRepNoArguments ::
GenericSumEncodeJsonRep GR.NoArguments where
genericSumEncodeJsonRep GR.NoArguments = Argonaut.jsonNull
instance genericSumEncodeJsonRepArgument ::
instance genericSumEncodeJsonRepArgument ::
( Argonaut.EncodeJson a
( Argonaut.EncodeJson a
) => GenericSumEncodeJsonRep (GR.Argument a) where
) => GenericSumEncodeJsonRep (GR.Argument a) where
...
...
test/Gargantext/Utils/Spec.purs
View file @
a7dab291
...
@@ -17,6 +17,7 @@ data Fruit
...
@@ -17,6 +17,7 @@ data Fruit
= Boat { hi :: Int }
= Boat { hi :: Int }
| Gravy String
| Gravy String
| Pork Int
| Pork Int
| Chicken
derive instance eqFruit :: Eq Fruit
derive instance eqFruit :: Eq Fruit
derive instance genericFruit :: Generic Fruit _
derive instance genericFruit :: Generic Fruit _
...
@@ -76,3 +77,9 @@ spec =
...
@@ -76,3 +77,9 @@ spec =
let result2' = Argonaut.decodeJson result2
let result2' = Argonaut.decodeJson result2
Argonaut.stringify result2 `shouldEqual` """{"Gravy":"hi"}"""
Argonaut.stringify result2 `shouldEqual` """{"Gravy":"hi"}"""
result2' `shouldEqual` Right input2
result2' `shouldEqual` Right input2
let input3 = Chicken
let result3 = Argonaut.encodeJson input3
let result3' = Argonaut.decodeJson result3
Argonaut.stringify result3 `shouldEqual` """{"Chicken":null}"""
result3' `shouldEqual` Right input3
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment