diff --git a/reactor/Test/test/AssertHelper.kt b/reactor/Test/test/AssertHelper.kt new file mode 100644 index 00000000..c7155a55 --- /dev/null +++ b/reactor/Test/test/AssertHelper.kt @@ -0,0 +1,24 @@ +import org.junit.Assert + +/* + * Copyright 2014-2019 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Fedor Isakov + */ + +infix fun A.shouldBe(that: B) = Assert.assertEquals(that, this) + diff --git a/reactor/Test/test/TestController.kt b/reactor/Test/test/TestController.kt index abe7f651..3aa902a0 100644 --- a/reactor/Test/test/TestController.kt +++ b/reactor/Test/test/TestController.kt @@ -1,11 +1,11 @@ -import jetbrains.mps.logic.reactor.core.Controller -import jetbrains.mps.logic.reactor.core.SessionObjects -import jetbrains.mps.logic.reactor.core.invocation -import jetbrains.mps.logic.reactor.core.occurrence +import jetbrains.mps.logic.reactor.core.* import jetbrains.mps.logic.reactor.evaluation.* import jetbrains.mps.logic.reactor.logical.Logical import jetbrains.mps.logic.reactor.logical.LogicalContext import jetbrains.mps.logic.reactor.program.* +import jetbrains.mps.logic.reactor.util.cons +import jetbrains.mps.unification.Term +import jetbrains.mps.unification.test.MockTerm.* import org.junit.After import org.junit.Assert.* import org.junit.Before @@ -15,6 +15,7 @@ import solver.MockSessionSolver import solver.eq import solver.is_eq + /** * @author Fedor Isakov */ @@ -753,6 +754,58 @@ class TestController { } } + @Test + fun matchHeadWithTerm() { + val (X, Y, Z) = metaLogical("X", "Y", "Z") + val xLogical = X.logical() + val yLogical = Y.logical() + val zLogical = Z.logical() + programWithRules( + rule("main", + headReplaced(constraint("main")), + body( + constraint("foo", term("bar", logicalVar(zLogical))), + constraint("foo", term("bar", logicalVar(xLogical))), + constraint("trigger", xLogical) + ) + ), + rule("rule1", + headReplaced( + constraint("trigger", Y), + constraint("foo", term("bar", metaVar(X))) + ), + guard( + expression ({ x, y -> x.findRoot() == y.findRoot() }, X, Y) + ), + body( + constraint("triggered1", X, Y) + ) + ), + rule("rule2", + headReplaced( + constraint("trigger", Y), + constraint("foo", X) + ), + guard( + expression ({ x, y -> !y.isBound && x.findRoot() == y.findRoot() }, X, Y) + ), + body( + constraint("triggered2", X, Y) + ) + ) + ).controller().run { + evaluate(occurrence("main")) + storeView().run { + val foo = ConstraintSymbol("foo", 1) + val t1 = ConstraintSymbol("triggered1", 2) + constraintSymbols() shouldBe setOf(t1, foo) + occurrences(t1).count() shouldBe 1 + occurrences(t1).first().arguments().first() shouldBe xLogical + occurrences(foo).count() shouldBe 1 + occurrences(foo).first().arguments().first() shouldBe term("bar", logicalVar(zLogical)) + } + } + } } diff --git a/reactor/Test/test/TestRuleMatcher.kt b/reactor/Test/test/TestRuleMatcher.kt index 1797464f..abe84bc9 100644 --- a/reactor/Test/test/TestRuleMatcher.kt +++ b/reactor/Test/test/TestRuleMatcher.kt @@ -32,8 +32,6 @@ import program.MockConstraint class TestRuleMatcher { - infix fun A.shouldBe(that: B) = assertEquals(that, this) - @Test fun testOccurrenceMatchLogical() { val (X, Y) = metaLogical("X", "Y")