Rework parsing structure
This commit is contained in:
parent
a4ec29f084
commit
b9f419a59d
17 changed files with 246 additions and 278 deletions
36
tests/parser/ScriptParserTests.kt
Normal file
36
tests/parser/ScriptParserTests.kt
Normal file
|
@ -0,0 +1,36 @@
|
|||
package parser
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertInstanceOf
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.ast.logic.Fact
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.logic.equivalent
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ScriptParserTests {
|
||||
private lateinit var parser: ScriptParser
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
parser = ScriptParser()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parse single atom`() {
|
||||
val input = """
|
||||
a.
|
||||
""".trimIndent()
|
||||
|
||||
val result = parser.parse(input)
|
||||
val expected = Fact(Atom("a"))
|
||||
|
||||
assertEquals(1, result.size, "Should return one result")
|
||||
assertInstanceOf(Fact::class.java, result[0], "Result should be a fact")
|
||||
assertTrue(
|
||||
equivalent(expected.head, result[0].head, emptyMap()),
|
||||
"Expected fact 'a'"
|
||||
)
|
||||
}
|
||||
}
|
Reference in a new issue