Skip to content

Commit 893dee4

Browse files
committed
test: prolog goal setting
1 parent b4c39d6 commit 893dee4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/scala/io/github/kelvindev15/prolog/dsl/DeclarativeDSL.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ trait DeclarativeDSL:
4040
def directive(using theory: MutableTheoryWrapper)(directive: Directive): Unit = theory add directive
4141
def clause(using theory: MutableTheoryWrapper)(c: Clause): Unit = theory add c
4242

43-
def solve(using program: PrologProgram)(goal: () => Term): Unit =
44-
prologProgram = prologProgram withGoal goal()
43+
def solve(using program: PrologProgram)(goal: Term): Unit =
44+
prologProgram = prologProgram withGoal goal
4545

4646
object DeclarativeDSL:
4747
trait MutableTheoryWrapper:

src/test/scala/io/github/kelvindev15/dsl/TestDeclarativeDSL.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package io.github.kelvindev15.dsl
22

33
import io.github.kelvindev15.prolog.PrologProgram
44
import io.github.kelvindev15.prolog.core.Constant.Atom
5-
import io.github.kelvindev15.prolog.core.{Constant, Struct, Variable}
5+
import io.github.kelvindev15.prolog.core.Goals.Conjunction
6+
import io.github.kelvindev15.prolog.core.PrologList.Cons
67
import io.github.kelvindev15.prolog.core.Struct.{Directive, Fact, Rule}
8+
import io.github.kelvindev15.prolog.core.{Constant, PrologList, Struct, Variable}
79
import io.github.kelvindev15.prolog.dsl.{DeclarativeDSL, PrologDSL}
810
import org.scalatest.funsuite.AnyFunSuite
911
import org.scalatest.matchers.should.Matchers
@@ -61,3 +63,13 @@ class TestDeclarativeDSL extends AnyFunSuite with Matchers with PrologDSL with D
6163
Struct(Atom("is"),
6264
Constant.Numeric(2.5), Struct(Atom("+"), Variable("X"), Variable("Y")))))),
6365
)
66+
67+
test("Setting the goal of a prolog program"):
68+
prolog {
69+
solve {
70+
&&(2 is X + Y, (head(H) | T) `=` S)
71+
}
72+
}.goal shouldBe Some(Conjunction(
73+
Struct(Atom("is"), Constant.Numeric(2), Struct(Atom("+"), Variable("X"), Variable("Y"))),
74+
Struct(Atom("="), Cons(Variable("H"), Variable("T")), Variable("S"))
75+
))

0 commit comments

Comments
 (0)