44 inline Own<TranslationUnit>
makeATU(std::string program) {
50 inline Own<Clause>
makeClause(std::string name, Own<Argument> headArgument) {
51 auto headAtom = mk<Atom>(name);
52 headAtom->addArgument(std::move(headArgument));
53 auto clause = mk<Clause>();
54 clause->setHead(std::move(headAtom));
65 EXPECT_TRUE(empty->getProgram().getRelations().empty());
71 .decl e ( a : Node , b : Node )
72 .decl r ( from : Node , to : Node )
75 r(X,Z) :- r(X,Y), r(Y,Z).
79 auto& prog = tu->getProgram();
80 std::cout << prog <<
"\n";
90 #define TESTASTCLONEANDEQUAL(SUBTYPE, DL) \
91 TEST(Ast, CloneAndEqual##SUBTYPE) { \
94 Own<TranslationUnit> tu = ParserDriver::parseTranslationUnit(DL, e, d); \
95 Program& program = tu->getProgram(); \
96 EXPECT_EQ(program, program); \
97 Own<Program> clone(program.clone()); \
98 EXPECT_NE(clone.get(), &program); \
99 EXPECT_EQ(*clone, program); \
104 .decl r(a:number,b:number,c:number,d:number)
108 r(X,Y,Z,W) :- a(X), 10 = Y, Y = Z, 8 + W = 12 + 14.
109 r(z + 2, x, y, a) :- s(b), b = to_string(a), z = x, a = y, x = 2, a = 2 + x.
115 .type R = [ a : N, B : N ]
170 R4(x) :- R2(x,x),R1(x,x).
178 r(x) :- r(y), x=cat(cat(x,x),x).
193 d(x,y) :- b(x,y), c(y,x).
199 auto atom = mk<Atom>(
"B");
200 atom->addArgument(mk<Variable>(
"x"));
203 body.push_back(std::move(atom));
204 sum->setBody(std::move(body));
206 auto tu1 =
makeATU(
".decl A,B(x:number) \n A(sum x : B(x)).");
207 auto clause =
makeClause(
"A", std::move(sum));
209 tu1->getProgram().removeClause(clause.get());
210 auto tu2 =
makeATU(
".decl A,B(x:number)");
211 EXPECT_EQ(tu1->getProgram(), tu2->getProgram());
215 auto tu1 =
makeATU(
".decl A,B,C(x:number)");
216 auto& prog1 = tu1->getProgram();
217 auto rel = mk<Relation>();
218 rel->setQualifiedName(
"D");
219 rel->addAttribute(mk<Attribute>(
"x",
"number"));
220 prog1.addRelation(std::move(
rel));
221 auto tu2 =
makeATU(
".decl A,B,C,D(x:number)");
222 EXPECT_EQ(tu1->getProgram(), tu2->getProgram());
225 TEST(Program, RemoveRelation) {
226 auto tu1 =
makeATU(
".decl A,B,C(x:number)");
228 auto tu2 =
makeATU(
".decl A,C(x:number)");
229 EXPECT_EQ(tu1->getProgram(), tu2->getProgram());