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

* 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
This commit is contained in:
Gabriel Gonzalez 2019-08-09 11:21:40 -07:00 committed by mergify[bot]
parent ce17b86bc5
commit 268c79631d
5 changed files with 42 additions and 2 deletions

View File

@ -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

View File

@ -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 =
@ -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"

View File

@ -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 })

View File

@ -0,0 +1 @@
{}

View File

@ -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