Added unit test to check whether escaped user variable names are correctly escaped.

This commit is contained in:
Patrick Lühne 2016-11-24 15:38:55 +01:00
parent 7702441d24
commit cdfdd8f4ca
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 11 additions and 3 deletions

View File

@ -44,7 +44,7 @@ struct StatementVisitor
const auto &headTerm = **i;
if (i != context.headTerms.cbegin())
outputStream << ", ";
outputStream << " " << Clingo::AST::BinaryOperator::And << " ";
const auto variableName = std::string(AuxiliaryHeadVariablePrefix) + std::to_string(i - context.headTerms.cbegin() + 1);

View File

@ -45,7 +45,7 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
input << "p(N, 1, 2) :- N = 1..5.";
anthem::translate("input", input, context);
REQUIRE(output.str() == "V1 in N, V2 in 1, V3 in 2 and exists X1, X2 (X1 in N and X2 in (1..5) and X1 = X2) -> p(V1, V2, V3)\n");
REQUIRE(output.str() == "V1 in N and V2 in 1 and V3 in 2 and exists X1, X2 (X1 in N and X2 in (1..5) and X1 = X2) -> p(V1, V2, V3)\n");
}
SECTION("disjunctive head")
@ -54,6 +54,14 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
input << "q(3, N); p(N, 1, 2) :- N = 1..5.";
anthem::translate("input", input, context);
REQUIRE(output.str() == "V1 in N, V2 in 1, V3 in 2, V4 in 3, V5 in N and exists X1, X2 (X1 in N and X2 in (1..5) and X1 = X2) -> p(V1, V2, V3) or q(V4, V5)\n");
REQUIRE(output.str() == "V1 in N and V2 in 1 and V3 in 2 and V4 in 3 and V5 in N and exists X1, X2 (X1 in N and X2 in (1..5) and X1 = X2) -> p(V1, V2, V3) or q(V4, V5)\n");
}
SECTION("escaping conflicting variable names")
{
input << "p(X1, V1) :- q(X1), q(V1).";
anthem::translate("input", input, context);
REQUIRE(output.str() == "V1 in _X1 and V2 in _V1 and exists X1 (X1 in _X1 and q(X1)) and exists X2 (X2 in _V1 and q(X2)) -> p(V1, V2)\n");
}
}