Skip to content

Commit

Permalink
Also check negative cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Oct 3, 2023
1 parent b35bbf7 commit 1b205d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ trait ParserSuite extends SimpleIOSuite {
}
}

validTokensTest(testCase, trimWhitespace)
}

private def validTokensTest(
testCase: TestCase,
trimWhitespace: Boolean,
) =
test(testCase.name + " (v2 scanner)") {
testCase.readInput(trimWhitespace).map { input =>
val scanned = Scanner.scan(input)
Expand All @@ -65,11 +72,12 @@ trait ParserSuite extends SimpleIOSuite {
assert(errors.isEmpty)
}
}
}

// invalidTokens: a flag that tells the suite whether the file should contain invalid tokens.
def loadNegativeParserTests[Alg[_[_]]: SourceParser](
prefix: String,
trimWhitespace: Boolean = false,
invalidTokens: Boolean,
): Unit = loadTestCases("", List("negative", prefix)).foreach { testCase =>
test(testCase.name) {
testCase.readInput(trimWhitespace).map { input =>
Expand All @@ -79,6 +87,10 @@ trait ParserSuite extends SimpleIOSuite {
}
}
}

if (!invalidTokens)
validTokensTest(testCase, trimWhitespace)

}

private def readText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import playground.smithyql.Prelude
import playground.smithyql.parser.ParserSuite

object PreludeParserNegativeTests extends ParserSuite {
loadNegativeParserTests[Prelude]("prelude", trimWhitespace = true)
loadNegativeParserTests[Prelude]("prelude", trimWhitespace = true, invalidTokens = false)
}

0 comments on commit 1b205d3

Please sign in to comment.