Skip to content

Commit

Permalink
Fix yaml-to-dhall support for empty objects (#1186)
Browse files Browse the repository at this point in the history
* Fix `yaml-to-dhall` support for empty objects

`yaml-to-dhall` was decoding an empty object into:

```dhall
[] : { mapKey : Text, mapValue : Text }
```

... instead of:

```dhall
[] : List { mapKey : Text, mapValue : Text }
```

... which this change fixes

* Add missing test files

* Hopefully fix test failure on Windows

I suspect that the test failure is due to the locale for the test suite
not being set to UTF8
  • Loading branch information
Gabriella439 authored and mergify[bot] committed Aug 9, 2019
1 parent ce17b86 commit 268c796
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
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

0 comments on commit 268c796

Please sign in to comment.