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:
parent
ce17b86bc5
commit
268c79631d
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
17
dhall-json/tasty/data/emptyObject.dhall
Normal file
17
dhall-json/tasty/data/emptyObject.dhall
Normal 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 })
|
1
dhall-json/tasty/data/emptyObject.json
Normal file
1
dhall-json/tasty/data/emptyObject.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
17
dhall-json/tasty/data/emptyObjectSchema.dhall
Normal file
17
dhall-json/tasty/data/emptyObjectSchema.dhall
Normal 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
|
Loading…
Reference in New Issue
Block a user