Skip to content

Commit b4a4c24

Browse files
committed
fixed presenting keyword values in JSON style
1 parent a9922cb commit b4a4c24

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

test/tpresenter.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,11 @@ suite "Presenter":
169169
startMapEvent(), scalarEvent("foo"), scalarEvent("bar"), scalarEvent("baz"),
170170
startSeqEvent(), endSeqEvent(), endMapEvent())
171171
assertOutput(input, "{\n \"foo\": \"bar\",\n \"baz\": []\n}\n", jsonOptions)
172+
173+
test "JSON output with keyword values":
174+
var input = inputSingle(scalarEvent("true"))
175+
assertOutput(input, "true\n", jsonOptions)
176+
input = inputSingle(scalarEvent("false", yTagBoolean))
177+
assertOutput(input, "false\n", jsonOptions)
178+
input = inputSingle(scalarEvent("~", yTagNull))
179+
assertOutput(input, "null\n", jsonOptions)

yaml/presenter.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ proc doPresent(
718718
ctx.safeWrite("...")
719719
ctx.safeNewline()
720720
ctx.wroteDirectivesEnd =
721-
item.explicitDirectivesEnd or ctx.options.directivesEnd == deAlways or not s.peek().emptyProperties()
721+
item.explicitDirectivesEnd or ctx.options.directivesEnd == deAlways or (
722+
ctx.options.directivesEnd != deNever and not s.peek().emptyProperties())
722723

723724
if ctx.options.directivesEnd != deNever:
724725
resetHandles(ctx.handles)
@@ -804,7 +805,7 @@ proc doPresent(
804805
case ctx.options.quoting
805806
of sqJson:
806807
var hint = yTypeUnknown
807-
if ctx.levels.len > 0 and ctx.state == dFlowMapValue: hint = guessType(item.scalarContent)
808+
if ctx.levels.len == 0 or ctx.state == dFlowMapValue: hint = guessType(item.scalarContent)
808809
let tag = item.scalarProperties.tag
809810
if tag in [yTagQuestionMark, yTagBoolean] and
810811
hint in {yTypeBoolTrue, yTypeBoolFalse}:

0 commit comments

Comments
 (0)