Skip to content

Commit de51daf

Browse files
sjakobimergify[bot]
authored andcommitted
dhall-json: Add a defaultConversion for converting maps (#1579)
1 parent 338d640 commit de51daf

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

dhall-json/src/Dhall/JSON.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ module Dhall.JSON (
201201
, omitEmpty
202202
, parsePreservationAndOmission
203203
, Conversion(..)
204+
, defaultConversion
204205
, convertToHomogeneousMaps
205206
, parseConversion
206207
, SpecialDoubleMode(..)
@@ -646,6 +647,12 @@ data Conversion
646647
= NoConversion
647648
| Conversion { mapKey :: Text, mapValue :: Text }
648649

650+
defaultConversion :: Conversion
651+
defaultConversion = Conversion
652+
{ mapKey = "mapKey"
653+
, mapValue = "mapValue"
654+
}
655+
649656
{-| Convert association lists to homogeneous maps
650657
651658
This converts an association list of the form:

dhall-json/src/Dhall/JSON/Yaml.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ module Dhall.JSON.Yaml
1919
import Data.ByteString (ByteString)
2020
import Data.Monoid ((<>))
2121
import Data.Text (Text)
22-
import Dhall.JSON (Conversion(..), SpecialDoubleMode(..), codeToValue)
22+
import Dhall.JSON (Conversion(..), SpecialDoubleMode(..))
2323
import Options.Applicative (Parser)
2424

2525
import qualified Data.Aeson
2626
import qualified Data.Aeson.Yaml
2727
import qualified Data.ByteString.Lazy
2828
import qualified Data.Vector
2929
import qualified Dhall
30+
import qualified Dhall.JSON
3031
import qualified Options.Applicative
3132

3233
data Options = Options
@@ -45,7 +46,7 @@ defaultOptions =
4546
, omission = id
4647
, documents = False
4748
, quoted = False
48-
, conversion = NoConversion
49+
, conversion = Dhall.JSON.defaultConversion
4950
, file = Nothing
5051
, output = Nothing
5152
}
@@ -76,7 +77,7 @@ dhallToYaml Options{..} mFilePath code = do
7677

7778
let explaining = if explain then Dhall.detailed else id
7879

79-
json <- omission <$> explaining (codeToValue conversion UseYAMLEncoding mFilePath code)
80+
json <- omission <$> explaining (Dhall.JSON.codeToValue conversion UseYAMLEncoding mFilePath code)
8081

8182
return $ jsonToYaml json documents quoted
8283

dhall-json/tasty/Main.hs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
module Main where
66

77
import Data.Monoid ((<>))
8-
import Dhall.JSON (Conversion(..))
98
import Test.Tasty (TestTree)
109

1110
import qualified Data.Aeson as Aeson
@@ -67,12 +66,8 @@ testDhallToJSON prefix = Test.Tasty.HUnit.testCase prefix $ do
6766

6867
_ <- Core.throws (Dhall.TypeCheck.typeOf resolvedExpression)
6968

70-
let mapKey = "mapKey"
71-
let mapValue = "mapValue"
72-
let conversion = Conversion {..}
73-
7469
let convertedExpression =
75-
Dhall.JSON.convertToHomogeneousMaps conversion resolvedExpression
70+
Dhall.JSON.convertToHomogeneousMaps Dhall.JSON.defaultConversion resolvedExpression
7671

7772
actualValue <- do
7873
Core.throws (Dhall.JSON.dhallToJSON convertedExpression)

dhall-yaml/tasty/Main.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Test.Tasty (TestTree)
1010

1111
import qualified Data.ByteString
1212
import qualified Data.Text.IO
13-
import qualified Dhall.JSON
1413
import qualified Dhall.JSON.Yaml
1514
import qualified Dhall.Yaml
1615
import qualified GHC.IO.Encoding
@@ -38,7 +37,6 @@ testTree =
3837
"./tasty/data/emptyList"
3938
, testDhallToYaml
4039
Dhall.JSON.Yaml.defaultOptions
41-
{ conversion = Dhall.JSON.Conversion "mapKey" "mapValue" }
4240
"./tasty/data/emptyMap"
4341
, Test.Tasty.ExpectedFailure.ignoreTestBecause "#1516" $
4442
testDhallToYaml

0 commit comments

Comments
 (0)