mirror of https://github.com/status-im/NimYAML.git
Added `+DOC ---` event output. Fixed parserTests
This commit is contained in:
parent
9eee22bbc5
commit
2bb32139c4
|
@ -21,10 +21,10 @@ proc ensureTestSuiteCloneCorrect(pwd: string) {.compileTime.} =
|
|||
var isCorrectClone = true
|
||||
if dirExists(absolutePath / ".git"):
|
||||
let remoteUrl =
|
||||
staticExec("cd \"" & absolutePath & "\" && git remote get-url origin")
|
||||
staticExec("cd \"" & absolutePath & "\" && git remote get-url origin").strip
|
||||
if remoteUrl != testSuiteUrl:
|
||||
isCorrectClone = false
|
||||
let branches = staticExec("cd \"" & absolutePath & "\" && git branch")
|
||||
let branches = staticExec("cd \"" & absolutePath & "\" && git branch").strip
|
||||
if "* data" notin branches.splitLines():
|
||||
isCorrectClone = false
|
||||
if isCorrectClone:
|
||||
|
@ -96,7 +96,7 @@ proc parserTest(path: string): bool =
|
|||
|
||||
macro genTests(): untyped =
|
||||
let
|
||||
pwd = staticExec("pwd")
|
||||
pwd = staticExec("pwd").strip
|
||||
absolutePath = '"' & (pwd / testSuiteFolder) & '"'
|
||||
echo "[tparser] Generating tests from " & absolutePath
|
||||
ensureTestSuiteCloneCorrect(pwd)
|
||||
|
@ -104,6 +104,7 @@ macro genTests(): untyped =
|
|||
# walkDir for some crude reason does not work with travis build
|
||||
let dirItems = staticExec("ls -1d " & absolutePath / "*")
|
||||
for dirPath in dirItems.splitLines():
|
||||
if dirPath.strip.len == 0: continue
|
||||
if dirPath[^4..^1] in [".git", "name", "tags", "meta"]: continue
|
||||
let title = slurp(dirPath / "===")
|
||||
result.add(newCall("test",
|
||||
|
|
|
@ -547,7 +547,8 @@ parserState initial:
|
|||
state = blockObjectStart
|
||||
of ltStreamEnd: c.isFinished = true
|
||||
of ltDirectivesEnd:
|
||||
e = startDocEvent()
|
||||
when defined(yamlScalarRepInd): e = startDocEvent(true)
|
||||
else: e = startDocEvent()
|
||||
result = true
|
||||
c.advance()
|
||||
state = blockObjectStart
|
||||
|
@ -738,7 +739,9 @@ parserState expectDocEnd:
|
|||
|
||||
parserState startDoc:
|
||||
c.initDocValues()
|
||||
e = startDocEvent()
|
||||
when defined(yamlScalarRepInd):
|
||||
e = startDocEvent(c.lex.cur == ltDirectivesEnd)
|
||||
else: e = startDocEvent()
|
||||
result = true
|
||||
c.advance()
|
||||
state = blockObjectStart
|
||||
|
@ -1110,7 +1113,10 @@ proc display*(p: YamlParser, event: YamlStreamEvent): string
|
|||
case event.kind
|
||||
of yamlEndMap: result = "-MAP"
|
||||
of yamlEndSeq: result = "-SEQ"
|
||||
of yamlStartDoc: result = "+DOC"
|
||||
of yamlStartDoc:
|
||||
result = "+DOC"
|
||||
when defined(yamlScalarRepInd):
|
||||
if event.explicitDirectivesEnd: result &= " ---"
|
||||
of yamlEndDoc: result = "-DOC"
|
||||
of yamlStartMap:
|
||||
result = "+MAP" & p.renderAttrs(event.mapTag, event.mapAnchor, true)
|
||||
|
|
|
@ -58,7 +58,11 @@ type
|
|||
scalarContent*: string # may not be nil (but empty)
|
||||
when defined(yamlScalarRepInd):
|
||||
scalarRep* : ScalarRepresentationIndicator
|
||||
of yamlEndMap, yamlEndSeq, yamlStartDoc, yamlEndDoc: discard
|
||||
of yamlStartDoc:
|
||||
when defined(yamlScalarRepInd):
|
||||
explicitDirectivesEnd*: bool
|
||||
else: discard
|
||||
of yamlEndMap, yamlEndSeq, yamlEndDoc: discard
|
||||
of yamlAlias:
|
||||
aliasTarget* : AnchorId
|
||||
|
||||
|
@ -259,7 +263,10 @@ proc `$`*(event: YamlStreamEvent): string {.raises: [].} =
|
|||
case event.kind
|
||||
of yamlEndMap: result = "-MAP"
|
||||
of yamlEndSeq: result = "-SEQ"
|
||||
of yamlStartDoc: result = "+DOC"
|
||||
of yamlStartDoc:
|
||||
result = "+DOC"
|
||||
when defined(yamlScalarRepInd):
|
||||
if event.explicitDirectivesEnd: result &= " ---"
|
||||
of yamlEndDoc: result = "-DOC"
|
||||
of yamlStartMap: result = "+MAP" & renderAttrs(event.mapTag, event.mapAnchor)
|
||||
of yamlStartSeq: result = "+SEQ" & renderAttrs(event.seqTag, event.seqAnchor)
|
||||
|
@ -284,7 +291,14 @@ proc tag*(event: YamlStreamEvent): TagId {.raises: [FieldError].} =
|
|||
of yamlScalar: result = event.scalarTag
|
||||
else: raise newException(FieldError, "Event " & $event.kind & " has no tag")
|
||||
|
||||
proc startDocEvent*(): YamlStreamEvent {.inline, raises: [].} =
|
||||
when defined(yamlScalarRepInd):
|
||||
proc startDocEvent*(explicit: bool = false): YamlStreamEvent
|
||||
{.inline, raises: [].} =
|
||||
## creates a new event that marks the start of a YAML document
|
||||
result = YamlStreamEvent(kind: yamlStartDoc,
|
||||
explicitDirectivesEnd: explicit)
|
||||
else:
|
||||
proc startDocEvent*(): YamlStreamEvent {.inline, raises: [].} =
|
||||
## creates a new event that marks the start of a YAML document
|
||||
result = YamlStreamEvent(kind: yamlStartDoc)
|
||||
|
||||
|
|
Loading…
Reference in New Issue