Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dhall-json/dhall-json.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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.5 && < 1.1 ,
aeson-yaml >= 1.0.6 && < 1.1 ,
bytestring < 0.11,
containers ,
dhall >= 1.28.0 && < 1.31,
Expand Down
12 changes: 11 additions & 1 deletion dhall-yaml/src/Dhall/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Data.ByteString.Lazy (toStrict)

import qualified Data.Aeson
import qualified Data.ByteString
import qualified Data.Char as Char
import qualified Data.Text as Text
import qualified Data.Vector
import qualified Data.YAML as Y
Expand Down Expand Up @@ -60,8 +61,17 @@ jsonToYaml json documents quoted =
style (Y.SStr s)
| "\n" `Text.isInfixOf` s =
Right (YE.untagged, YE.Literal YE.Clip YE.IndentAuto, s)
| quoted =
| quoted || Text.all isNumberOrDateRelated s || isBoolString =
Right (YE.untagged, YE.SingleQuoted, s)
where
isBoolString
| Text.length s > 5 = False
| otherwise =
case Text.toLower s of
"true" -> True
"false" -> True
_ -> False
isNumberOrDateRelated c = Char.isDigit c || c == '.' || c == 'e' || c == '-'
style s =
YS.schemaEncoderScalar Y.coreSchemaEncoder s

Expand Down
4 changes: 1 addition & 3 deletions dhall-yaml/tasty/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import qualified Dhall.JSON.Yaml
import qualified Dhall.Yaml
import qualified GHC.IO.Encoding
import qualified Test.Tasty
import qualified Test.Tasty.ExpectedFailure
import qualified Test.Tasty.HUnit

main :: IO ()
Expand All @@ -38,8 +37,7 @@ testTree =
, testDhallToYaml
Dhall.JSON.Yaml.defaultOptions
"./tasty/data/emptyMap"
, Test.Tasty.ExpectedFailure.ignoreTestBecause "#1516" $
testDhallToYaml
, testDhallToYaml
(Dhall.JSON.Yaml.defaultOptions { quoted = True })
"./tasty/data/quoted"
]
Expand Down
2 changes: 2 additions & 0 deletions dhall-yaml/tasty/data/normal.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
, text = ./yaml.txt as Text
, int_value = 1
, bool_value = True
, bool_string = "true"
, yes = "y"
, hello_world = "hello world"
}
4 changes: 3 additions & 1 deletion dhall-yaml/tasty/data/normal.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
bool_string: 'true'
bool_value: true
hello_world: hello world
int_value: 1
string_value: "2000-01-01"
string_value: '2000-01-01'
text: |
Plain text
yes: y
2 changes: 2 additions & 0 deletions dhall-yaml/tasty/data/quoted.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
, text = ./yaml.txt as Text
, int_value = 1
, bool_value = True
, bool_string = "true"
, yes = "y"
, hello_world = "hello world"
}
2 changes: 2 additions & 0 deletions dhall-yaml/tasty/data/quoted.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'bool_string': 'true'
'bool_value': true
'hello_world': 'hello world'
'int_value': 1
'string_value': '2000-01-01'
'text': |
Expand Down
4 changes: 2 additions & 2 deletions nix/aeson-yaml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
}:
mkDerivation {
pname = "aeson-yaml";
version = "1.0.5.0";
sha256 = "e3c49b52b7000dcfe0a227af2e3a70aa7fd97f5c577156ad659470b17127a533";
version = "1.0.6.0";
sha256 = "feac4e3706601ec65e4bc8a71c0e95c36383426f7b286b09d3f673429f24359b";
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.10.0.0
- aeson-yaml-1.0.5.0@sha256:5786f021c1e088d6a5aa259120ec5b1f22bb1757f4427c1a87e0513d00f17f31,1975
- aeson-yaml-1.0.6.0@sha256:bdf6d67265d9a3e251122fa53d2f0f19e0b9865d928e5d6efb77d4754ca3f6cb,1975
- prettyprinter-1.6.0
- atomic-write-0.2.0.7@sha256:3b626dfbc288cd070f1ac31b1c15ddd49822a923778ffe21f92b2116ffc72dc3,4584
- megaparsec-8.0.0
Expand Down