Add implementation test

This commit is contained in:
Florian Schroedl
2022-08-26 18:45:49 +02:00
parent b70c2f3519
commit 0a3812c83d

View File

@@ -324,7 +324,7 @@ when isMainModule:
# parse
assert testAbc1Parser.flatMap(following(@[ch('a'), str("bc"), digit])).tokensToString() == "abc1"
block parsingHelpers:
block testParsingHelpers:
let testParenParser = initParserResult("(123)")
let testQuoteParser = initParserResult("\"123\"")
@@ -338,8 +338,18 @@ when isMainModule:
assert testParenParser.flatMap(anyBetween(ch('('), ch(')'))).tokensToString() == "123"
assert testQuoteParser.flatMap(anyBetweenPair(testQuote)).tokensToString() == "123"
block parsingAliases:
block testParsingAliases:
assert initParserResult("").flatMap(newlineOrEol).isOk() == true
assert initParserResult("abc ").flatMap(str("abc") + newlineOrEol).error().expected == newlineEolExpectedErr
assert initParserResult("").flatMap(whitespaceOrEol).isOk() == true
assert initParserResult("abc ").flatMap(str("abc") + whitespaceOrEol + whitespaceOrEol).tokensToString() == "abc "
block testImplementations:
let testSentenceStr = "This is a sentence\n\nFollowing another sentence."
let testSentenceParser = initParserResult(testSentenceStr)
let testSentence1 = anyUntil(newline) + newline + newlineOrEol +
manyUntil(choice(@[letter, whitespace]), ch('.')) + ch('.') +
newlineOrEol
assert testSentenceParser.flatMap(testSentence1).tokensToString() == testSentenceStr