Clause
This commit is contained in:
parent
752c278cb0
commit
8bda3c5af4
15 changed files with 361 additions and 114 deletions
|
@ -2,7 +2,6 @@ package parser.grammars
|
|||
|
||||
import com.github.h0tk3y.betterParse.grammar.Grammar
|
||||
import com.github.h0tk3y.betterParse.grammar.parseToEnd
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -14,8 +13,7 @@ import prolog.ast.logic.Rule
|
|||
import prolog.ast.terms.CompoundTerm
|
||||
import prolog.ast.terms.Structure
|
||||
import prolog.ast.terms.Variable
|
||||
import prolog.builtins.Conjunction
|
||||
import prolog.ast.terms.FunctorInfo
|
||||
import prolog.ast.terms.Functor
|
||||
|
||||
class LogicGrammarTests {
|
||||
private lateinit var parser: Grammar<List<Clause>>
|
||||
|
@ -95,13 +93,13 @@ class LogicGrammarTests {
|
|||
|
||||
assertTrue(rule.head is Structure, "Expected head to be a structure")
|
||||
val head = rule.head as Structure
|
||||
assertEquals(FunctorInfo.of("parent/2"), head.functor, "Expected functor 'parent/2'")
|
||||
assertEquals(Functor.of("parent/2"), head.functor, "Expected functor 'parent/2'")
|
||||
assertEquals(Variable("X"), head.arguments[0], "Expected first argument 'X'")
|
||||
assertEquals(Variable("Y"), head.arguments[1], "Expected second argument 'Y'")
|
||||
|
||||
assertTrue(rule.body is Structure, "Expected body to be a structure")
|
||||
val body = rule.body as Structure
|
||||
assertEquals(FunctorInfo.of("father/2"), body.functor, "Expected functor 'father/2'")
|
||||
assertEquals(Functor.of("father/2"), body.functor, "Expected functor 'father/2'")
|
||||
assertEquals(Variable("X"), body.arguments[0], "Expected first argument 'X'")
|
||||
assertEquals(Variable("Y"), body.arguments[1], "Expected second argument 'Y'")
|
||||
}
|
||||
|
@ -126,12 +124,12 @@ class LogicGrammarTests {
|
|||
|
||||
assertEquals(1, result.size, "Expected 1 rule")
|
||||
val rule = result[0] as Rule
|
||||
assertEquals(FunctorInfo.of("guest/2"), rule.head.functor, "Expected functor 'guest/2'")
|
||||
assertEquals(FunctorInfo.of(",/2"), (rule.body as CompoundTerm).functor, "Expected functor ',/2'")
|
||||
assertEquals(Functor.of("guest/2"), rule.head.functor, "Expected functor 'guest/2'")
|
||||
assertEquals(Functor.of(",/2"), (rule.body as CompoundTerm).functor, "Expected functor ',/2'")
|
||||
val l1 = (rule.body as CompoundTerm).arguments[0] as CompoundTerm
|
||||
assertEquals(FunctorInfo.of(",/2"), l1.functor, "Expected functor ',/2'")
|
||||
assertEquals(Functor.of(",/2"), l1.functor, "Expected functor ',/2'")
|
||||
val l2 = l1.arguments[0] as CompoundTerm
|
||||
assertEquals(FunctorInfo.of("invited/2"), l2.functor, "Expected functor 'invited/2'")
|
||||
assertEquals(Functor.of("invited/2"), l2.functor, "Expected functor 'invited/2'")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -158,6 +156,6 @@ class LogicGrammarTests {
|
|||
assertEquals(1, result.size, "Expected 1 rule")
|
||||
assertTrue(result[0] is Rule, "Expected a rule")
|
||||
val rule = result[0] as Rule
|
||||
assertEquals(FunctorInfo.of("/0"), rule.head.functor, "Expected a constraint")
|
||||
assertEquals(Functor.of("/0"), rule.head.functor, "Expected a constraint")
|
||||
}
|
||||
}
|
Reference in a new issue