dhall-to-{json,yaml,yaml-ng}: Handle empty maps correctly (#1561)

Fixes #1559.

This requires aeson-yaml >= 1.0.5.0 since older versions
incorrectly encode empty objects.

The raised bound also fixes #1560. A regression test is included.
This commit is contained in:
Simon Jakobi 2019-12-01 19:41:46 +01:00 committed by mergify[bot]
parent 8eb78704d5
commit 85645a2470
10 changed files with 18 additions and 5 deletions

View File

@ -37,7 +37,7 @@ Library
base >= 4.8.0.0 && < 5 ,
aeson >= 1.0.0.0 && < 1.5 ,
aeson-pretty < 0.9 ,
aeson-yaml >= 1.0.4 && < 1.1 ,
aeson-yaml >= 1.0.5 && < 1.1 ,
bytestring < 0.11,
containers ,
dhall >= 1.27.0 && < 1.28,

View File

@ -858,7 +858,7 @@ convertToHomogeneousMaps (Conversion {..}) e0 = loop (Core.normalize e0)
case elements of
[] ->
case a of
Just (Core.Record m) -> do
Just (Core.App Core.List (Core.Record m)) -> do
guard (Foldable.length m == 2)
guard (Dhall.Map.member mapKey m)
guard (Dhall.Map.member mapValue m)

View File

@ -31,6 +31,7 @@ testTree :: TestTree
testTree =
Test.Tasty.testGroup "dhall-json"
[ testDhallToJSON "./tasty/data/issue48"
, testDhallToJSON "./tasty/data/emptyObjectStrongType"
, testJSONToDhall "./tasty/data/emptyAlternative"
, testJSONToDhall "./tasty/data/emptyObject"
, testJSONToDhall "./tasty/data/emptyList"

View File

@ -10,6 +10,7 @@ import Test.Tasty (TestTree)
import qualified Data.ByteString
import qualified Data.Text.IO
import qualified Dhall.JSON
import qualified Dhall.JSON.Yaml
import qualified Dhall.Yaml
import qualified GHC.IO.Encoding
@ -32,6 +33,13 @@ testTree =
, testDhallToYaml
Dhall.JSON.Yaml.defaultOptions
"./tasty/data/special"
, testDhallToYaml
Dhall.JSON.Yaml.defaultOptions
"./tasty/data/emptyList"
, testDhallToYaml
Dhall.JSON.Yaml.defaultOptions
{ conversion = Dhall.JSON.Conversion "mapKey" "mapValue" }
"./tasty/data/emptyMap"
, Test.Tasty.ExpectedFailure.ignoreTestBecause "#1516" $
testDhallToYaml
(Dhall.JSON.Yaml.defaultOptions { quoted = True })

View File

@ -0,0 +1 @@
[] : List Bool

View File

@ -0,0 +1 @@
[]

View File

@ -0,0 +1 @@
[] : List { mapKey : Text, mapValue : Natural }

View File

@ -0,0 +1 @@
{}

View File

@ -4,8 +4,8 @@
}:
mkDerivation {
pname = "aeson-yaml";
version = "1.0.4.0";
sha256 = "7a6ddaad23f50dc7b419707e49904ad3b5ea9fcd29d2cae0e4adaf300fbb8264";
version = "1.0.5.0";
sha256 = "e3c49b52b7000dcfe0a227af2e3a70aa7fd97f5c577156ad659470b17127a533";
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [

View File

@ -22,7 +22,7 @@ extra-deps:
- HsYAML-aeson-0.2.0.0@sha256:04796abfc01cffded83f37a10e6edba4f0c0a15d45bef44fc5bb4313d9c87757,1791
- ordered-containers-0.2.2@sha256:ebf2be3f592d9cf148ea6b8375f8af97148d44f82d8d04476899285e965afdbf,810
- lsp-test-0.6.1.0@sha256:df0fc403c03b6d036be13de3ff23d9951ae2506080135cd6862eded2c969a6da,3483
- aeson-yaml-1.0.4.0@sha256:72d91a4a2ade87b8a4bdf73937d2c62bd2c60053df1841f8bf1e6204387959b8,1975
- aeson-yaml-1.0.5.0@sha256:5786f021c1e088d6a5aa259120ec5b1f22bb1757f4427c1a87e0513d00f17f31,1975
- prettyprinter-1.5.1@sha256:fca87c3e2611d3499a0341a59857e9b424a23f31646e4737d535a18582284f96,5375
- atomic-write-0.2.0.7@sha256:3b626dfbc288cd070f1ac31b1c15ddd49822a923778ffe21f92b2116ffc72dc3,4584
nix: