dhall-json: Add a defaultConversion for converting maps (#1579)
This commit is contained in:
parent
338d640dcc
commit
de51dafe8e
|
@ -201,6 +201,7 @@ module Dhall.JSON (
|
|||
, omitEmpty
|
||||
, parsePreservationAndOmission
|
||||
, Conversion(..)
|
||||
, defaultConversion
|
||||
, convertToHomogeneousMaps
|
||||
, parseConversion
|
||||
, SpecialDoubleMode(..)
|
||||
|
@ -646,6 +647,12 @@ data Conversion
|
|||
= NoConversion
|
||||
| Conversion { mapKey :: Text, mapValue :: Text }
|
||||
|
||||
defaultConversion :: Conversion
|
||||
defaultConversion = Conversion
|
||||
{ mapKey = "mapKey"
|
||||
, mapValue = "mapValue"
|
||||
}
|
||||
|
||||
{-| Convert association lists to homogeneous maps
|
||||
|
||||
This converts an association list of the form:
|
||||
|
|
|
@ -19,7 +19,7 @@ module Dhall.JSON.Yaml
|
|||
import Data.ByteString (ByteString)
|
||||
import Data.Monoid ((<>))
|
||||
import Data.Text (Text)
|
||||
import Dhall.JSON (Conversion(..), SpecialDoubleMode(..), codeToValue)
|
||||
import Dhall.JSON (Conversion(..), SpecialDoubleMode(..))
|
||||
import Options.Applicative (Parser)
|
||||
|
||||
import qualified Data.Aeson
|
||||
|
@ -27,6 +27,7 @@ import qualified Data.Aeson.Yaml
|
|||
import qualified Data.ByteString.Lazy
|
||||
import qualified Data.Vector
|
||||
import qualified Dhall
|
||||
import qualified Dhall.JSON
|
||||
import qualified Options.Applicative
|
||||
|
||||
data Options = Options
|
||||
|
@ -45,7 +46,7 @@ defaultOptions =
|
|||
, omission = id
|
||||
, documents = False
|
||||
, quoted = False
|
||||
, conversion = NoConversion
|
||||
, conversion = Dhall.JSON.defaultConversion
|
||||
, file = Nothing
|
||||
, output = Nothing
|
||||
}
|
||||
|
@ -76,7 +77,7 @@ dhallToYaml Options{..} mFilePath code = do
|
|||
|
||||
let explaining = if explain then Dhall.detailed else id
|
||||
|
||||
json <- omission <$> explaining (codeToValue conversion UseYAMLEncoding mFilePath code)
|
||||
json <- omission <$> explaining (Dhall.JSON.codeToValue conversion UseYAMLEncoding mFilePath code)
|
||||
|
||||
return $ jsonToYaml json documents quoted
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
module Main where
|
||||
|
||||
import Data.Monoid ((<>))
|
||||
import Dhall.JSON (Conversion(..))
|
||||
import Test.Tasty (TestTree)
|
||||
|
||||
import qualified Data.Aeson as Aeson
|
||||
|
@ -67,12 +66,8 @@ testDhallToJSON prefix = Test.Tasty.HUnit.testCase prefix $ do
|
|||
|
||||
_ <- Core.throws (Dhall.TypeCheck.typeOf resolvedExpression)
|
||||
|
||||
let mapKey = "mapKey"
|
||||
let mapValue = "mapValue"
|
||||
let conversion = Conversion {..}
|
||||
|
||||
let convertedExpression =
|
||||
Dhall.JSON.convertToHomogeneousMaps conversion resolvedExpression
|
||||
Dhall.JSON.convertToHomogeneousMaps Dhall.JSON.defaultConversion resolvedExpression
|
||||
|
||||
actualValue <- do
|
||||
Core.throws (Dhall.JSON.dhallToJSON convertedExpression)
|
||||
|
|
|
@ -10,7 +10,6 @@ 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
|
||||
|
@ -38,7 +37,6 @@ testTree =
|
|||
"./tasty/data/emptyList"
|
||||
, testDhallToYaml
|
||||
Dhall.JSON.Yaml.defaultOptions
|
||||
{ conversion = Dhall.JSON.Conversion "mapKey" "mapValue" }
|
||||
"./tasty/data/emptyMap"
|
||||
, Test.Tasty.ExpectedFailure.ignoreTestBecause "#1516" $
|
||||
testDhallToYaml
|
||||
|
|
Loading…
Reference in New Issue