Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yaml-to-dhall support for empty objects #1186

Merged
merged 4 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dhall-json/src/Dhall/JSONToDhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ dhallFromJSON (Conversion {..}) expressionType =

elementType
| null elements =
Just (D.Record [ ("mapKey", D.Text), ("mapValue", "JSON") ])
Just (D.App D.List (D.Record [ ("mapKey", D.Text), ("mapValue", "JSON") ]))
| otherwise =
Nothing

Expand Down
7 changes: 6 additions & 1 deletion dhall-json/tasty/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import qualified Dhall.JSONToDhall as JSONToDhall
import qualified Dhall.Parser
import qualified Dhall.TypeCheck
import qualified Dhall.Yaml
import qualified GHC.IO.Encoding
import qualified Test.Tasty
import qualified Test.Tasty.HUnit

main :: IO ()
main = Test.Tasty.defaultMain testTree
main = do
GHC.IO.Encoding.setLocaleEncoding GHC.IO.Encoding.utf8

Test.Tasty.defaultMain testTree

testTree :: TestTree
testTree =
Expand All @@ -36,6 +40,7 @@ testTree =
(Dhall.Yaml.defaultOptions { Dhall.Yaml.quoted = True })
"./tasty/data/quoted"
, testJSONToDhall "./tasty/data/emptyAlternative"
, testJSONToDhall "./tasty/data/emptyObject"
, Test.Tasty.testGroup "Nesting"
[ testDhallToJSON "./tasty/data/nesting0"
, testDhallToJSON "./tasty/data/nesting1"
Expand Down
17 changes: 17 additions & 0 deletions dhall-json/tasty/data/emptyObject.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
λ(JSON : Type)
→ λ ( json
: { array :
List JSON → JSON
, bool :
Bool → JSON
, null :
JSON
, number :
Double → JSON
, object :
List { mapKey : Text, mapValue : JSON } → JSON
, string :
Text → JSON
}
)
→ json.object ([] : List { mapKey : Text, mapValue : JSON })
1 change: 1 addition & 0 deletions dhall-json/tasty/data/emptyObject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
17 changes: 17 additions & 0 deletions dhall-json/tasty/data/emptyObjectSchema.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
∀(JSON : Type)
→ ∀ ( json
: { array :
List JSON → JSON
, bool :
Bool → JSON
, null :
JSON
, number :
Double → JSON
, object :
List { mapKey : Text, mapValue : JSON } → JSON
, string :
Text → JSON
}
)
→ JSON