From c681498701a4947ce46da6b69742fa1bfda1a27b Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Fri, 22 Oct 2021 17:42:48 +0200 Subject: [PATCH] updated tests, fixed problems --- test/testEventParser.nim | 19 +++++++++++++++++++ test/tparser.nim | 2 +- test/yaml-test-suite | 2 +- yaml/parser.nim | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/testEventParser.nim b/test/testEventParser.nim index 8577905..1700b46 100644 --- a/test/testEventParser.nim +++ b/test/testEventParser.nim @@ -10,6 +10,7 @@ import lexbase, streams, tables, strutils type LexerToken = enum plusStr, minusStr, plusDoc, minusDoc, plusMap, minusMap, plusSeq, minusSeq, + mapBraces, seqBrackets, eqVal, eqAli, chevTag, andAnchor, starAnchor, colonContent, sqContent, dqContent, litContent, foContent, explDirEnd, explDocEnd, noToken @@ -89,6 +90,18 @@ proc nextToken(lex: var EventLexer): LexerToken = lex.content.add(lex.buf[lex.bufpos]) lex.bufpos.inc() result = starAnchor + of '{': + lex.bufpos.inc() + if lex.buf[lex.bufpos] == '}': + result = mapBraces + else: raise newException(EventStreamError, "Invalid token: {" & lex.buf[lex.bufpos]) + lex.bufpos.inc() + of '[': + lex.bufpos.inc() + if lex.buf[lex.bufpos] == ']': + result = seqBrackets + else: raise newException(EventStreamError, "Invalid token: [" & lex.buf[lex.bufpos]) + lex.bufpos.inc() else: lex.content = "" while lex.buf[lex.bufpos] notin {' ', '\t', '\r', '\l', EndOfFile}: @@ -210,6 +223,12 @@ proc parseEventStream*(input: Stream): YamlStream = of minusSeq: eventStart(yamlEndSeq) of eqVal: eventStart(yamlScalar) of eqAli: eventStart(yamlAlias) + of mapBraces: + assertInEvent("braces") + curEvent.mapStyle = csFlow + of seqBrackets: + assertInEvent("brackets") + curEvent.seqStyle = csFlow of chevTag: assertInEvent("tag") if curTag() != yTagQuestionMark: diff --git a/test/tparser.nim b/test/tparser.nim index f471035..fcd152f 100644 --- a/test/tparser.nim +++ b/test/tparser.nim @@ -73,7 +73,7 @@ macro genTests(): untyped = let errorTests = toHashSet(staticExec("cd " & (absolutePath / "tags" / "error") & " && ls -1d *").splitLines()) - var ignored = toHashSet([".git", "name", "tags", "meta", "G5U8"]) # G5U8 seems wrong + var ignored = toHashSet([".git", "name", "tags", "meta"]) result = newStmtList() # walkDir for some crude reason does not work with travis build diff --git a/test/yaml-test-suite b/test/yaml-test-suite index de56edb..80f2894 160000 --- a/test/yaml-test-suite +++ b/test/yaml-test-suite @@ -1 +1 @@ -Subproject commit de56edb2d317fdf47ab4bca8a0ae42c06b4afa66 +Subproject commit 80f289435a56189bbc5ca2f318574e48dbeef8aa diff --git a/yaml/parser.nim b/yaml/parser.nim index a7ae9be..20309b6 100644 --- a/yaml/parser.nim +++ b/yaml/parser.nim @@ -267,6 +267,8 @@ proc beforeDoc(c: Context, e: var Event): bool = c.pushLevel(afterDirectivesEnd, -1) return true of StreamEnd: + if seenDirectives: + raise c.generateError("Missing `---` after directives") c.popLevel() return false of Indentation: