Skip to content

Commit

Permalink
wip(matcher): add new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Hoefer committed Dec 13, 2020
1 parent 4955f16 commit 6c6c845
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ open class GrammarMatcher {

private fun List<String>.prepareScriptString(): MutableList<String> {
return this
.asSequence()
.map { it.replace(" ", "") }
.map { it.replace("\\uFEFF", "") } // remove BOM
.map { it.trim() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ import org.junit.jupiter.api.Test
internal class GrammarMatcherTest {
private val grammarMatcher: GrammarMatcher = GrammarMatcher()

@Test
fun `should return matched grammar for different order position`() {
val grammar = Grammar(
"SUBOBJECT",
listOf(
OBJECT_ID, ASSIGNMENT, BLOCK_START, // object_id = {
ATTRIBUTE_ID, ASSIGNMENT, ATTRIBUTE_VALUE, // attribute_id = attribute_value
OBJECT_ID, ASSIGNMENT, BLOCK_START, // object_id = {
ATTRIBUTE_ID, ASSIGNMENT, ATTRIBUTE_VALUE, // attribute_id = attribute_value
BLOCK_END, // }
ATTRIBUTE_ID, ASSIGNMENT, ATTRIBUTE_VALUE, // attribute_id = attribute_value
BLOCK_END // }
)
)

val actual = grammarMatcher
.rule(grammar, SCRIPT_FULL_EXAMPLE_WITH_SUBOBJECT.split("\n"))
val expected = MatcherResult(SCRIPT_FULL_EXAMPLE_WITH_SUBOBJECT.trimWhiteSpace())

assertThat(actual).isEqualTo(expected)
}

@Test
fun `should return matched grammar for optional definitions exclusive`() {
val grammar = Grammar(
Expand Down

0 comments on commit 6c6c845

Please sign in to comment.