Added `+DOC ---` event output. Fixed parserTests

This commit is contained in:
Felix Krause 2017-02-14 22:06:48 +01:00
parent 9eee22bbc5
commit 2bb32139c4
3 changed files with 33 additions and 12 deletions

View File

@ -21,10 +21,10 @@ proc ensureTestSuiteCloneCorrect(pwd: string) {.compileTime.} =
var isCorrectClone = true var isCorrectClone = true
if dirExists(absolutePath / ".git"): if dirExists(absolutePath / ".git"):
let remoteUrl = let remoteUrl =
staticExec("cd \"" & absolutePath & "\" && git remote get-url origin") staticExec("cd \"" & absolutePath & "\" && git remote get-url origin").strip
if remoteUrl != testSuiteUrl: if remoteUrl != testSuiteUrl:
isCorrectClone = false isCorrectClone = false
let branches = staticExec("cd \"" & absolutePath & "\" && git branch") let branches = staticExec("cd \"" & absolutePath & "\" && git branch").strip
if "* data" notin branches.splitLines(): if "* data" notin branches.splitLines():
isCorrectClone = false isCorrectClone = false
if isCorrectClone: if isCorrectClone:
@ -96,7 +96,7 @@ proc parserTest(path: string): bool =
macro genTests(): untyped = macro genTests(): untyped =
let let
pwd = staticExec("pwd") pwd = staticExec("pwd").strip
absolutePath = '"' & (pwd / testSuiteFolder) & '"' absolutePath = '"' & (pwd / testSuiteFolder) & '"'
echo "[tparser] Generating tests from " & absolutePath echo "[tparser] Generating tests from " & absolutePath
ensureTestSuiteCloneCorrect(pwd) ensureTestSuiteCloneCorrect(pwd)
@ -104,6 +104,7 @@ macro genTests(): untyped =
# walkDir for some crude reason does not work with travis build # walkDir for some crude reason does not work with travis build
let dirItems = staticExec("ls -1d " & absolutePath / "*") let dirItems = staticExec("ls -1d " & absolutePath / "*")
for dirPath in dirItems.splitLines(): for dirPath in dirItems.splitLines():
if dirPath.strip.len == 0: continue
if dirPath[^4..^1] in [".git", "name", "tags", "meta"]: continue if dirPath[^4..^1] in [".git", "name", "tags", "meta"]: continue
let title = slurp(dirPath / "===") let title = slurp(dirPath / "===")
result.add(newCall("test", result.add(newCall("test",
@ -112,4 +113,4 @@ macro genTests(): untyped =
newLit(dirPath))))) newLit(dirPath)))))
result = newCall("suite", newLit("Parser Tests (from yaml-test-suite)"), result) result = newCall("suite", newLit("Parser Tests (from yaml-test-suite)"), result)
genTests() genTests()

View File

@ -547,7 +547,8 @@ parserState initial:
state = blockObjectStart state = blockObjectStart
of ltStreamEnd: c.isFinished = true of ltStreamEnd: c.isFinished = true
of ltDirectivesEnd: of ltDirectivesEnd:
e = startDocEvent() when defined(yamlScalarRepInd): e = startDocEvent(true)
else: e = startDocEvent()
result = true result = true
c.advance() c.advance()
state = blockObjectStart state = blockObjectStart
@ -738,7 +739,9 @@ parserState expectDocEnd:
parserState startDoc: parserState startDoc:
c.initDocValues() c.initDocValues()
e = startDocEvent() when defined(yamlScalarRepInd):
e = startDocEvent(c.lex.cur == ltDirectivesEnd)
else: e = startDocEvent()
result = true result = true
c.advance() c.advance()
state = blockObjectStart state = blockObjectStart
@ -1110,7 +1113,10 @@ proc display*(p: YamlParser, event: YamlStreamEvent): string
case event.kind case event.kind
of yamlEndMap: result = "-MAP" of yamlEndMap: result = "-MAP"
of yamlEndSeq: result = "-SEQ" of yamlEndSeq: result = "-SEQ"
of yamlStartDoc: result = "+DOC" of yamlStartDoc:
result = "+DOC"
when defined(yamlScalarRepInd):
if event.explicitDirectivesEnd: result &= " ---"
of yamlEndDoc: result = "-DOC" of yamlEndDoc: result = "-DOC"
of yamlStartMap: of yamlStartMap:
result = "+MAP" & p.renderAttrs(event.mapTag, event.mapAnchor, true) result = "+MAP" & p.renderAttrs(event.mapTag, event.mapAnchor, true)

View File

@ -58,7 +58,11 @@ type
scalarContent*: string # may not be nil (but empty) scalarContent*: string # may not be nil (but empty)
when defined(yamlScalarRepInd): when defined(yamlScalarRepInd):
scalarRep* : ScalarRepresentationIndicator scalarRep* : ScalarRepresentationIndicator
of yamlEndMap, yamlEndSeq, yamlStartDoc, yamlEndDoc: discard of yamlStartDoc:
when defined(yamlScalarRepInd):
explicitDirectivesEnd*: bool
else: discard
of yamlEndMap, yamlEndSeq, yamlEndDoc: discard
of yamlAlias: of yamlAlias:
aliasTarget* : AnchorId aliasTarget* : AnchorId
@ -259,7 +263,10 @@ proc `$`*(event: YamlStreamEvent): string {.raises: [].} =
case event.kind case event.kind
of yamlEndMap: result = "-MAP" of yamlEndMap: result = "-MAP"
of yamlEndSeq: result = "-SEQ" of yamlEndSeq: result = "-SEQ"
of yamlStartDoc: result = "+DOC" of yamlStartDoc:
result = "+DOC"
when defined(yamlScalarRepInd):
if event.explicitDirectivesEnd: result &= " ---"
of yamlEndDoc: result = "-DOC" of yamlEndDoc: result = "-DOC"
of yamlStartMap: result = "+MAP" & renderAttrs(event.mapTag, event.mapAnchor) of yamlStartMap: result = "+MAP" & renderAttrs(event.mapTag, event.mapAnchor)
of yamlStartSeq: result = "+SEQ" & renderAttrs(event.seqTag, event.seqAnchor) of yamlStartSeq: result = "+SEQ" & renderAttrs(event.seqTag, event.seqAnchor)
@ -284,9 +291,16 @@ proc tag*(event: YamlStreamEvent): TagId {.raises: [FieldError].} =
of yamlScalar: result = event.scalarTag of yamlScalar: result = event.scalarTag
else: raise newException(FieldError, "Event " & $event.kind & " has no tag") else: raise newException(FieldError, "Event " & $event.kind & " has no tag")
proc startDocEvent*(): YamlStreamEvent {.inline, raises: [].} = when defined(yamlScalarRepInd):
## creates a new event that marks the start of a YAML document proc startDocEvent*(explicit: bool = false): YamlStreamEvent
result = YamlStreamEvent(kind: yamlStartDoc) {.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)
proc endDocEvent*(): YamlStreamEvent {.inline, raises: [].} = proc endDocEvent*(): YamlStreamEvent {.inline, raises: [].} =
## creates a new event that marks the end of a YAML document ## creates a new event that marks the end of a YAML document