Refactoring to use cleaner output implementation.

This commit is contained in:
2016-11-29 06:03:05 +01:00
parent 9b49b8ebe7
commit c4e19dddae
77 changed files with 1661 additions and 1467 deletions

View File

@@ -33,7 +33,7 @@ TEST_CASE("[PDDL normalization] PDDL expressions are correctly reduced", "[PDDL
std::stringstream output;
n1->reduced()->print(output);
REQUIRE(output.str() == "(not (not (and (or (or (not (a)) (b)) (c)) (d))))");
CHECK(output.str() == "(not (not (and (or (or (not (a)) (b)) (c)) (d))))");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -63,7 +63,7 @@ TEST_CASE("[PDDL normalization] PDDL expressions are correctly simplified", "[PD
std::stringstream output;
a1->simplified()->print(output);
REQUIRE(output.str() == "(and (a) (b) (c) (d) (or (e) (f) (g) (h)))");
CHECK(output.str() == "(and (a) (b) (c) (d) (or (e) (f) (g) (h)))");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -78,7 +78,7 @@ TEST_CASE("[PDDL normalization] Implications are correctly replaced", "[PDDL nor
std::stringstream output;
i->normalized()->print(output);
REQUIRE(output.str() == "(or (not (a)) (b))");
CHECK(output.str() == "(or (not (a)) (b))");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,7 +94,7 @@ TEST_CASE("[PDDL normalization] Double negations are correctly replaced", "[PDDL
std::stringstream output;
n1->normalized()->print(output);
REQUIRE(output.str() == "(a)");
CHECK(output.str() == "(a)");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -112,7 +112,7 @@ TEST_CASE("[PDDL normalization] De Morgans rule is correctly applied to negat
std::stringstream output;
n->normalized()->print(output);
REQUIRE(output.str() == "(or (not (a)) (not (b)) (not (c)))");
CHECK(output.str() == "(or (not (a)) (not (b)) (not (c)))");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -130,7 +130,7 @@ TEST_CASE("[PDDL normalization] De Morgans rule is correctly applied to negat
std::stringstream output;
n->normalized()->print(output);
REQUIRE(output.str() == "(and (not (a)) (not (b)) (not (c)))");
CHECK(output.str() == "(and (not (a)) (not (b)) (not (c)))");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -153,5 +153,5 @@ TEST_CASE("[PDDL normalization] Expressions inside double negations are also nor
std::stringstream output;
n1->normalized()->print(output);
REQUIRE(output.str() == "(or (not (a)) (not (b)) (not (c)))");
CHECK(output.str() == "(or (not (a)) (not (b)) (not (c)))");
}

View File

@@ -18,26 +18,29 @@ using namespace plasp::pddl;
TEST_CASE("[PDDL parser] The Blocks World domain is parsed correctly", "[PDDL parser]")
{
const auto description = Description::fromFile("data/blocksworld-domain.pddl");
plasp::output::Logger logger;
Context context(Parser(), logger);
const auto description = Description::fromFile("data/blocksworld-domain.pddl", context);
REQUIRE_NOTHROW(description.domain());
const auto &domain = description.domain();
// Name
REQUIRE(domain.name() == "blocks");
CHECK(domain.name() == "blocks");
// Requirements
REQUIRE(domain.requirements().size() == 2u);
REQUIRE(domain.requirements()[0].type() == Requirement::Type::STRIPS);
REQUIRE(domain.requirements()[1].type() == Requirement::Type::Typing);
CHECK(domain.requirements()[0].type() == Requirement::Type::STRIPS);
CHECK(domain.requirements()[1].type() == Requirement::Type::Typing);
// Types
REQUIRE(domain.types().size() == 1u);
const auto &block = *domain.types()[0];
REQUIRE(block.name() == "block");
CHECK(block.name() == "block");
REQUIRE(block.parentTypes().size() == 0u);
// Predicates
@@ -45,67 +48,70 @@ TEST_CASE("[PDDL parser] The Blocks World domain is parsed correctly", "[PDDL pa
const auto &on = *domain.predicates()[0];
REQUIRE(on.name() == "on");
CHECK(on.name() == "on");
REQUIRE(on.arguments().size() == 2u);
REQUIRE(on.arguments()[0]->name() == "x");
CHECK(on.arguments()[0]->name() == "x");
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
REQUIRE(&onArgument0Type == &block);
REQUIRE(on.arguments()[1]->name() == "y");
CHECK(&onArgument0Type == &block);
CHECK(on.arguments()[1]->name() == "y");
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
REQUIRE(&onArgument1Type == &block);
CHECK(&onArgument1Type == &block);
const auto &handempty = *domain.predicates()[3];
REQUIRE(handempty.name() == "handempty");
REQUIRE(handempty.arguments().empty());
CHECK(handempty.name() == "handempty");
CHECK(handempty.arguments().empty());
// Actions
REQUIRE(domain.actions().size() == 4u);
const auto &pickUp = *domain.actions()[0];
REQUIRE(pickUp.name() == "pick-up");
CHECK(pickUp.name() == "pick-up");
REQUIRE(pickUp.parameters().size() == 1u);
REQUIRE(pickUp.parameters()[0]->name() == "x");
REQUIRE(pickUp.parameters()[0]->type() == &block);
CHECK(pickUp.parameters()[0]->name() == "x");
CHECK(pickUp.parameters()[0]->type() == &block);
const auto &pickUpPre = dynamic_cast<const expressions::And &>(*pickUp.precondition());
REQUIRE(pickUpPre.arguments().size() == 3u);
const auto &pickUpPre0 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[0]);
REQUIRE(pickUpPre0.name() == "clear");
CHECK(pickUpPre0.name() == "clear");
REQUIRE(pickUpPre0.arguments().size() == 1u);
const auto &pickUpPre00 = dynamic_cast<const expressions::Variable &>(*pickUpPre0.arguments()[0]);
REQUIRE(pickUpPre00.name() == "x");
REQUIRE(pickUpPre00.type() == &block);
REQUIRE(&pickUpPre00 == pickUp.parameters()[0].get());
CHECK(pickUpPre00.name() == "x");
CHECK(pickUpPre00.type() == &block);
CHECK(&pickUpPre00 == pickUp.parameters()[0].get());
const auto &pickUpPre2 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[2]);
REQUIRE(pickUpPre2.name() == "handempty");
REQUIRE(pickUpPre2.arguments().size() == 0u);
CHECK(pickUpPre2.name() == "handempty");
CHECK(pickUpPre2.arguments().empty());
const auto &pickUpEff = dynamic_cast<const expressions::And &>(*pickUp.effect());
REQUIRE(pickUpEff.arguments().size() == 4u);
const auto &pickUpEff0 = dynamic_cast<const expressions::Not &>(*pickUpEff.arguments()[0]);
const auto &pickUpEff00 = dynamic_cast<const expressions::Predicate &>(*pickUpEff0.argument());
REQUIRE(pickUpEff00.name() == "ontable");
CHECK(pickUpEff00.name() == "ontable");
REQUIRE(pickUpEff00.arguments().size() == 1u);
const auto &pickUpEff000 = dynamic_cast<const expressions::Variable &>(*pickUpEff00.arguments()[0]);
REQUIRE(pickUpEff000.name() == "x");
REQUIRE(pickUpEff000.type() == &block);
CHECK(pickUpEff000.name() == "x");
CHECK(pickUpEff000.type() == &block);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL parser]")
{
const auto description = Description::fromFiles({"data/blocksworld-domain.pddl", "data/blocksworld-problem.pddl"});
plasp::output::Logger logger;
Context context(Parser(), logger);
const auto description = Description::fromFiles({"data/blocksworld-domain.pddl", "data/blocksworld-problem.pddl"}, context);
REQUIRE_NOTHROW(description.problem());
const auto &problem = description.problem();
// Name
REQUIRE(problem.name() == "blocks-4-0");
REQUIRE(problem.domain().name() == "blocks");
CHECK(problem.name() == "blocks-4-0");
CHECK(problem.domain().name() == "blocks");
// Requirements
// TODO: compute domain vs. problem requirements correctly and check them
@@ -113,26 +119,26 @@ TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL par
// Objects
REQUIRE(problem.objects().size() == 4u);
REQUIRE(problem.objects()[0]->name() == "d");
CHECK(problem.objects()[0]->name() == "d");
REQUIRE(problem.objects()[0]->type() != nullptr);
REQUIRE(problem.objects()[0]->type()->name() == "block");
REQUIRE(problem.objects()[3]->name() == "c");
CHECK(problem.objects()[0]->type()->name() == "block");
CHECK(problem.objects()[3]->name() == "c");
REQUIRE(problem.objects()[3]->type() != nullptr);
REQUIRE(problem.objects()[3]->type()->name() == "block");
CHECK(problem.objects()[3]->type()->name() == "block");
// Initial State
const auto &facts = problem.initialState().facts();
REQUIRE(facts.size() == 9u);
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
REQUIRE(fact0.name() == "clear");
CHECK(fact0.name() == "clear");
REQUIRE(fact0.arguments().size() == 1u);
const auto &fact00 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[0]);
REQUIRE(fact00.name() == "c");
CHECK(fact00.name() == "c");
REQUIRE(fact00.type() != nullptr);
REQUIRE(fact00.type()->name() == "block");
CHECK(fact00.type()->name() == "block");
const auto &fact8 = dynamic_cast<const expressions::Predicate &>(*facts[8].get());
REQUIRE(fact8.name() == "handempty");
CHECK(fact8.name() == "handempty");
REQUIRE(fact8.arguments().size() == 0u);
// Goal
@@ -140,37 +146,40 @@ TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL par
REQUIRE(goal.arguments().size() == 3u);
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
REQUIRE(goal0.name() == "on");
CHECK(goal0.name() == "on");
REQUIRE(goal0.arguments().size() == 2u);
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
REQUIRE(goal00.name() == "d");
CHECK(goal00.name() == "d");
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
REQUIRE(goal01.name() == "c");
CHECK(goal01.name() == "c");
const auto &goal2 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[2]);
REQUIRE(goal2.name() == "on");
CHECK(goal2.name() == "on");
REQUIRE(goal2.arguments().size() == 2u);
const auto &goal20 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[0]);
REQUIRE(goal20.name() == "b");
CHECK(goal20.name() == "b");
const auto &goal21 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[1]);
REQUIRE(goal21.name() == "a");
CHECK(goal21.name() == "a");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] The Storage domain is parsed correctly", "[PDDL parser]")
{
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl");
plasp::output::Logger logger;
Context context(Parser(), logger);
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl", context);
REQUIRE_NOTHROW(description.domain());
const auto &domain = description.domain();
// Name
REQUIRE(domain.name() == "storage-propositional");
CHECK(domain.name() == "storage-propositional");
// Requirements
REQUIRE(domain.requirements().size() == 1u);
REQUIRE(domain.requirements()[0].type() == Requirement::Type::Typing);
CHECK(domain.requirements()[0].type() == Requirement::Type::Typing);
// Types
REQUIRE(domain.types().size() == 10u);
@@ -184,81 +193,84 @@ TEST_CASE("[PDDL parser] The Storage domain is parsed correctly", "[PDDL parser]
const auto &hoistParents = hoist.parentTypes();
REQUIRE(hoistParents.size() == 1u);
REQUIRE(std::find(hoistParents.cbegin(), hoistParents.cend(), &object) != hoistParents.cend());
CHECK(std::find(hoistParents.cbegin(), hoistParents.cend(), &object) != hoistParents.cend());
const auto &areaParents = area.parentTypes();
REQUIRE(areaParents.size() == 2u);
REQUIRE(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
REQUIRE(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
CHECK(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
CHECK(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
// Predicates
REQUIRE(domain.predicates().size() == 8u);
const auto &on = *domain.predicates()[5];
REQUIRE(on.name() == "on");
CHECK(on.name() == "on");
REQUIRE(on.arguments().size() == 2u);
REQUIRE(on.arguments()[0]->name() == "c");
CHECK(on.arguments()[0]->name() == "c");
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
REQUIRE(&onArgument0Type == &crate);
REQUIRE(on.arguments()[1]->name() == "s");
CHECK(&onArgument0Type == &crate);
CHECK(on.arguments()[1]->name() == "s");
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
REQUIRE(&onArgument1Type == &storearea);
CHECK(&onArgument1Type == &storearea);
const auto &in = *domain.predicates()[1];
REQUIRE(in.name() == "in");
CHECK(in.name() == "in");
REQUIRE(in.arguments().size() == 2u);
REQUIRE(in.arguments()[0]->name() == "x");
CHECK(in.arguments()[0]->name() == "x");
const auto &inArgument0Type = dynamic_cast<const expressions::Either &>(*in.arguments()[0]->type());
REQUIRE(inArgument0Type.arguments().size() == 2u);
const auto &inArgument0Type0 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[0]);
REQUIRE(&inArgument0Type0 == &storearea);
CHECK(&inArgument0Type0 == &storearea);
const auto &inArgument0Type1 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[1]);
REQUIRE(&inArgument0Type1 == &crate);
CHECK(&inArgument0Type1 == &crate);
// Actions
REQUIRE(domain.actions().size() == 5u);
const auto &drop = *domain.actions()[1];
REQUIRE(drop.name() == "drop");
CHECK(drop.name() == "drop");
REQUIRE(drop.parameters().size() == 5u);
REQUIRE(drop.parameters()[3]->name() == "a2");
REQUIRE(drop.parameters()[3]->type() == &area);
CHECK(drop.parameters()[3]->name() == "a2");
CHECK(drop.parameters()[3]->type() == &area);
const auto &dropPre = dynamic_cast<const expressions::And &>(*drop.precondition());
REQUIRE(dropPre.arguments().size() == 5u);
const auto &dropPre2 = dynamic_cast<const expressions::Predicate &>(*dropPre.arguments()[2]);
REQUIRE(dropPre2.name() == "lifting");
CHECK(dropPre2.name() == "lifting");
REQUIRE(dropPre2.arguments().size() == 2u);
const auto &dropPre21 = dynamic_cast<const expressions::Variable &>(*dropPre2.arguments()[1]);
REQUIRE(dropPre21.name() == "c");
REQUIRE(dropPre21.type() == &crate);
CHECK(dropPre21.name() == "c");
CHECK(dropPre21.type() == &crate);
const auto &dropEff = dynamic_cast<const expressions::And &>(*drop.effect());
REQUIRE(dropEff.arguments().size() == 5u);
const auto &dropEff2 = dynamic_cast<const expressions::Not &>(*dropEff.arguments()[2]);
const auto &dropEff20 = dynamic_cast<const expressions::Predicate &>(*dropEff2.argument());
REQUIRE(dropEff20.name() == "clear");
CHECK(dropEff20.name() == "clear");
REQUIRE(dropEff20.arguments().size() == 1u);
const auto &dropEff200 = dynamic_cast<const expressions::Variable &>(*dropEff20.arguments()[0]);
REQUIRE(dropEff200.name() == "a1");
REQUIRE(dropEff200.type() == &storearea);
CHECK(dropEff200.name() == "a1");
CHECK(dropEff200.type() == &storearea);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] A Storage problem is parsed correctly", "[PDDL parser]")
{
const auto description = Description::fromFiles({"data/storage-domain.pddl", "data/storage-problem.pddl"});
plasp::output::Logger logger;
Context context(Parser(), logger);
const auto description = Description::fromFiles({"data/storage-domain.pddl", "data/storage-problem.pddl"}, context);
REQUIRE_NOTHROW(description.problem());
const auto &problem = description.problem();
// Name
REQUIRE(problem.name() == "storage-1");
REQUIRE(problem.domain().name() == "storage-propositional");
CHECK(problem.name() == "storage-1");
CHECK(problem.domain().name() == "storage-propositional");
// Requirements
// TODO: compute domain vs. problem requirements correctly and check them
@@ -266,57 +278,60 @@ TEST_CASE("[PDDL parser] A Storage problem is parsed correctly", "[PDDL parser]"
// Objects
REQUIRE(problem.objects().size() == 7u);
REQUIRE(problem.objects()[0]->name() == "depot0-1-1");
CHECK(problem.objects()[0]->name() == "depot0-1-1");
REQUIRE(problem.objects()[0]->type() != nullptr);
REQUIRE(problem.objects()[0]->type()->name() == "storearea");
REQUIRE(problem.objects()[6]->name() == "loadarea");
CHECK(problem.objects()[0]->type()->name() == "storearea");
CHECK(problem.objects()[6]->name() == "loadarea");
REQUIRE(problem.objects()[6]->type() != nullptr);
REQUIRE(problem.objects()[6]->type()->name() == "transitarea");
CHECK(problem.objects()[6]->type()->name() == "transitarea");
// Initial State
const auto &facts = problem.initialState().facts();
REQUIRE(facts.size() == 10u);
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
REQUIRE(fact0.name() == "in");
CHECK(fact0.name() == "in");
REQUIRE(fact0.arguments().size() == 2u);
const auto &fact01 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[1]);
REQUIRE(fact01.name() == "depot0");
CHECK(fact01.name() == "depot0");
REQUIRE(fact01.type() != nullptr);
REQUIRE(fact01.type()->name() == "depot");
CHECK(fact01.type()->name() == "depot");
const auto &fact9 = dynamic_cast<const expressions::Predicate &>(*facts[9].get());
REQUIRE(fact9.name() == "available");
CHECK(fact9.name() == "available");
REQUIRE(fact9.arguments().size() == 1u);
const auto &fact90 = dynamic_cast<const expressions::Constant &>(*fact9.arguments()[0]);
REQUIRE(fact90.name() == "hoist0");
CHECK(fact90.name() == "hoist0");
REQUIRE(fact90.type() != nullptr);
REQUIRE(fact90.type()->name() == "hoist");
CHECK(fact90.type()->name() == "hoist");
// Goal
const auto &goal = dynamic_cast<const expressions::And &>(problem.goal());
REQUIRE(goal.arguments().size() == 1u);
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
REQUIRE(goal0.name() == "in");
CHECK(goal0.name() == "in");
REQUIRE(goal0.arguments().size() == 2u);
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
REQUIRE(goal00.name() == "crate0");
CHECK(goal00.name() == "crate0");
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
REQUIRE(goal01.name() == "depot0");
CHECK(goal01.name() == "depot0");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
{
const auto description = Description::fromFile("data/woodworking-domain.pddl");
plasp::output::Logger logger;
Context context(Parser(), logger);
const auto description = Description::fromFile("data/woodworking-domain.pddl", context);
REQUIRE_NOTHROW(description.domain());
const auto &domain = description.domain();
// Name
REQUIRE(domain.name() == "woodworking");
CHECK(domain.name() == "woodworking");
// Types
const auto &acolour = *domain.types()[0];
@@ -325,11 +340,11 @@ TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
// Constants
REQUIRE(domain.constants().size() == 8u);
REQUIRE(domain.constants()[0]->type() == &surface);
REQUIRE(domain.constants()[2]->type() == &surface);
REQUIRE(domain.constants()[3]->type() == &treatmentstatus);
REQUIRE(domain.constants()[6]->type() == &treatmentstatus);
REQUIRE(domain.constants()[7]->type() == &acolour);
CHECK(domain.constants()[0]->type() == &surface);
CHECK(domain.constants()[2]->type() == &surface);
CHECK(domain.constants()[3]->type() == &treatmentstatus);
CHECK(domain.constants()[6]->type() == &treatmentstatus);
CHECK(domain.constants()[7]->type() == &acolour);
// TODO: add test with constants in predicates
}
@@ -338,68 +353,179 @@ TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
TEST_CASE("[PDDL parser] White spaces are ignored", "[PDDL parser]")
{
REQUIRE_NOTHROW(Description::fromFile("data/white-space-test.pddl"));
plasp::output::Logger logger;
Context context(Parser(), logger);
CHECK_NOTHROW(Description::fromFile("data/white-space-test.pddl", context));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected", "[PDDL parser]")
{
REQUIRE_THROWS_AS(Description::fromFile("data/blocksworld-problem.pddl"), ConsistencyException);
REQUIRE_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}), plasp::utils::ParserException);
plasp::output::Logger logger;
Context context(Parser(), logger);
SECTION("")
{
CHECK_THROWS_AS(Description::fromFile("data/blocksworld-problem.pddl", context), ConsistencyException);
}
SECTION("")
{
CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), plasp::input::ParserException);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] Common PDDL syntax errors are detected", "[PDDL parser]")
{
REQUIRE_NOTHROW(Description::fromFile("data/pddl-syntax/domain-valid.pddl"));
plasp::output::Logger logger;
Context context(Parser(), logger);
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-1.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-2.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-3.pddl"));
SECTION("")
{
CHECK_NOTHROW(Description::fromFile("data/pddl-syntax/domain-valid.pddl", context));
}
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-1.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-2.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-3.pddl"));
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-1.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-2.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-3.pddl", context));
}
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-1.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-2.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-3.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-4.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-5.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-6.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-7.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-8.pddl"));
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-1.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-2.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-3.pddl", context));
}
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-1.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-2.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-3.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-4.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-5.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-6.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-7.pddl"));
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-1.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-2.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-3.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-4.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-5.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-6.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-7.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-8.pddl", context));
}
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-1.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-2.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-3.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-types-4.pddl"));
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-1.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-2.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-3.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-4.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-5.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-6.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-7.pddl", context));
}
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-1.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-2.pddl"));
REQUIRE_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-3.pddl"));
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-1.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-2.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-3.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-4.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-1.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-2.pddl", context));
}
SECTION("")
{
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-3.pddl", context));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[PDDL parser] Former issues are fixed", "[PDDL parser]")
{
// Check white space issues with constants and parsing unsupported sections
REQUIRE_NOTHROW(Description::fromFile("data/issues/issue-1.pddl"));
plasp::output::Logger logger;
Context context(Parser(), logger);
// Check white space issues with empty n-ary predicates
REQUIRE_NOTHROW(Description::fromFile("data/issues/issue-2.pddl"));
SECTION("white space issues with constants and parsing unsupported sections")
{
CHECK_NOTHROW(Description::fromFile("data/issues/issue-1.pddl", context));
}
// Check that comments are correctly ignored
REQUIRE_NOTHROW(Description::fromFile("data/issues/issue-3.pddl"));
SECTION("white space issues with empty n-ary predicates")
{
CHECK_NOTHROW(Description::fromFile("data/issues/issue-2.pddl", context));
}
SECTION("comments are correctly ignored")
{
CHECK_NOTHROW(Description::fromFile("data/issues/issue-3.pddl", context));
}
}

View File

@@ -14,17 +14,20 @@ boost::iostreams::stream<boost::iostreams::null_sink> nullStream((boost::iostrea
TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]")
{
// Check that translating domains without typing information works
plasp::output::Logger logger;
Context context(Parser(), logger);
SECTION("translating domains without typing information works")
{
auto description = Description::fromFile("data/issues/issue-4.pddl");
auto description = Description::fromFile("data/issues/issue-4.pddl", context);
const auto translator = TranslatorASP(description, description.context().logger.outputStream());
REQUIRE_NOTHROW(translator.translate());
CHECK_NOTHROW(translator.translate());
}
// Check that translating the simple blocks world domain works
SECTION("translating the simple blocks world domain works")
{
auto description = Description::fromFile("data/issues/issue-5.pddl");
auto description = Description::fromFile("data/issues/issue-5.pddl", context);
const auto translator = TranslatorASP(description, description.context().logger.outputStream());
REQUIRE_NOTHROW(translator.translate());
CHECK_NOTHROW(translator.translate());
}
}

View File

@@ -48,64 +48,64 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] A valid SAS file is parsed
{
const auto description = plasp::sas::Description::fromStream(m_philosophersTestFile);
REQUIRE_FALSE(description.usesActionCosts());
CHECK_FALSE(description.usesActionCosts());
REQUIRE(description.variables().size() == 37u);
REQUIRE(description.variables()[0].axiomLayer() == -1);
REQUIRE(description.variables()[0].values()[0].sign() == plasp::sas::Value::Sign::Positive);
REQUIRE(description.variables()[0].values()[0].name() == "activate(philosopher-0, forks--pid-rfork)");
REQUIRE(description.variables()[36].axiomLayer() == -1);
REQUIRE(description.variables()[36].values()[1].sign() == plasp::sas::Value::Sign::Negative);
REQUIRE(description.variables()[36].values()[1].name() == "queue-tail-msg(forks-1-, fork)");
CHECK(description.variables()[0].axiomLayer() == -1);
CHECK(description.variables()[0].values()[0].sign() == plasp::sas::Value::Sign::Positive);
CHECK(description.variables()[0].values()[0].name() == "activate(philosopher-0, forks--pid-rfork)");
CHECK(description.variables()[36].axiomLayer() == -1);
CHECK(description.variables()[36].values()[1].sign() == plasp::sas::Value::Sign::Negative);
CHECK(description.variables()[36].values()[1].name() == "queue-tail-msg(forks-1-, fork)");
REQUIRE(description.mutexGroups().size() == 8u);
REQUIRE(description.mutexGroups()[0].facts().size() == 9u);
REQUIRE(&description.mutexGroups()[0].facts()[0].value() == &description.variables()[0].values()[0]);
CHECK(&description.mutexGroups()[0].facts()[0].value() == &description.variables()[0].values()[0]);
REQUIRE(description.mutexGroups()[7].facts().size() == 2u);
REQUIRE(&description.mutexGroups()[7].facts()[1].value() == &description.variables()[34].values()[1]);
CHECK(&description.mutexGroups()[7].facts()[1].value() == &description.variables()[34].values()[1]);
REQUIRE(description.initialState().facts().size() == 37u);
REQUIRE(&description.initialState().facts()[0].value() == &description.variables()[0].values()[8]);
REQUIRE(&description.initialState().facts()[36].value() == &description.variables()[36].values()[1]);
CHECK(&description.initialState().facts()[0].value() == &description.variables()[0].values()[8]);
CHECK(&description.initialState().facts()[36].value() == &description.variables()[36].values()[1]);
REQUIRE(description.goal().facts().size() == 2u);
REQUIRE(&description.goal().facts()[0].value() == &description.variables()[6].values()[0]);
REQUIRE(&description.goal().facts()[1].value() == &description.variables()[7].values()[0]);
CHECK(&description.goal().facts()[0].value() == &description.variables()[6].values()[0]);
CHECK(&description.goal().facts()[1].value() == &description.variables()[7].values()[0]);
REQUIRE(description.operators().size() == 34u);
REQUIRE(description.operators()[0].predicate().name() == "activate-trans");
CHECK(description.operators()[0].predicate().name() == "activate-trans");
REQUIRE(description.operators()[0].predicate().arguments().size() == 5u);
REQUIRE(description.operators()[0].predicate().arguments()[0] == "philosopher-0");
REQUIRE(description.operators()[0].predicate().arguments()[4] == "state-3");
CHECK(description.operators()[0].predicate().arguments()[0] == "philosopher-0");
CHECK(description.operators()[0].predicate().arguments()[4] == "state-3");
REQUIRE(description.operators()[0].preconditions().size() == 3u);
REQUIRE(&description.operators()[0].preconditions()[0].value() == &description.variables()[4].values()[4]);
REQUIRE(&description.operators()[0].preconditions()[1].value() == &description.variables()[16].values()[1]);
REQUIRE(&description.operators()[0].preconditions()[2].value() == &description.variables()[0].values()[8]);
CHECK(&description.operators()[0].preconditions()[0].value() == &description.variables()[4].values()[4]);
CHECK(&description.operators()[0].preconditions()[1].value() == &description.variables()[16].values()[1]);
CHECK(&description.operators()[0].preconditions()[2].value() == &description.variables()[0].values()[8]);
REQUIRE(description.operators()[0].effects().size() == 1u);
REQUIRE(description.operators()[0].effects()[0].conditions().size() == 0u);
REQUIRE(&description.operators()[0].effects()[0].postcondition().value() == &description.variables()[0].values()[0]);
REQUIRE(description.operators()[33].predicate().name() == "queue-write");
CHECK(&description.operators()[0].effects()[0].postcondition().value() == &description.variables()[0].values()[0]);
CHECK(description.operators()[33].predicate().name() == "queue-write");
REQUIRE(description.operators()[33].predicate().arguments().size() == 4u);
REQUIRE(description.operators()[33].predicate().arguments()[0] == "philosopher-1");
REQUIRE(description.operators()[33].predicate().arguments()[3] == "fork");
CHECK(description.operators()[33].predicate().arguments()[0] == "philosopher-1");
CHECK(description.operators()[33].predicate().arguments()[3] == "fork");
REQUIRE(description.operators()[33].preconditions().size() == 2u);
REQUIRE(&description.operators()[33].preconditions()[0].value() == &description.variables()[1].values()[3]);
REQUIRE(&description.operators()[33].preconditions()[1].value() == &description.variables()[2].values()[2]);
CHECK(&description.operators()[33].preconditions()[0].value() == &description.variables()[1].values()[3]);
CHECK(&description.operators()[33].preconditions()[1].value() == &description.variables()[2].values()[2]);
REQUIRE(description.operators()[33].effects().size() == 3u);
REQUIRE(description.operators()[33].effects()[0].conditions().size() == 0u);
REQUIRE(&description.operators()[33].effects()[0].postcondition().value() == &description.variables()[1].values()[7]);
REQUIRE(&description.operators()[33].effects()[2].postcondition().value() == &description.variables()[35].values()[0]);
CHECK(&description.operators()[33].effects()[0].postcondition().value() == &description.variables()[1].values()[7]);
CHECK(&description.operators()[33].effects()[2].postcondition().value() == &description.variables()[35].values()[0]);
REQUIRE(description.axiomRules().size() == 33u);
REQUIRE(description.axiomRules()[0].conditions().size() == 4u);
REQUIRE(&description.axiomRules()[0].conditions()[0].value() == &description.variables()[0].values()[0]);
REQUIRE(&description.axiomRules()[0].conditions()[2].value() == &description.variables()[27].values()[0]);
REQUIRE(&description.axiomRules()[0].conditions()[3].value() == &description.variables()[8].values()[1]);
REQUIRE(&description.axiomRules()[0].postcondition().value() == &description.variables()[8].values()[0]);
CHECK(&description.axiomRules()[0].conditions()[0].value() == &description.variables()[0].values()[0]);
CHECK(&description.axiomRules()[0].conditions()[2].value() == &description.variables()[27].values()[0]);
CHECK(&description.axiomRules()[0].conditions()[3].value() == &description.variables()[8].values()[1]);
CHECK(&description.axiomRules()[0].postcondition().value() == &description.variables()[8].values()[0]);
REQUIRE(description.axiomRules()[32].conditions().size() == 2u);
REQUIRE(&description.axiomRules()[32].conditions()[0].value() == &description.variables()[15].values()[0]);
REQUIRE(&description.axiomRules()[32].conditions()[1].value() == &description.variables()[25].values()[0]);
REQUIRE(&description.axiomRules()[32].postcondition().value() == &description.variables()[25].values()[1]);
CHECK(&description.axiomRules()[32].conditions()[0].value() == &description.variables()[15].values()[0]);
CHECK(&description.axiomRules()[32].conditions()[1].value() == &description.variables()[25].values()[0]);
CHECK(&description.axiomRules()[32].postcondition().value() == &description.variables()[25].values()[1]);
}
catch (const std::exception &e)
{
@@ -123,8 +123,8 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] Trailing empty parentheses
{
const auto description = plasp::sas::Description::fromStream(m_blocksworldTestFile);
REQUIRE(description.variables()[4].values()[0].name() == "handempty");
REQUIRE(description.variables()[5].values()[0].name() == "holding(a)");
CHECK(description.variables()[4].values()[0].name() == "handempty");
CHECK(description.variables()[5].values()[0].name() == "holding(a)");
}
catch (const std::exception &e)
{
@@ -141,8 +141,8 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] “none” values are corr
const auto description = plasp::sas::Description::fromStream(m_freecellTestFile);
// TODO: compare by identity, not value
REQUIRE(description.variables()[0].values()[3] == plasp::sas::Value::None);
REQUIRE(description.variables()[5].values()[6] == plasp::sas::Value::None);
CHECK(description.variables()[0].values()[3] == plasp::sas::Value::None);
CHECK(description.variables()[5].values()[6] == plasp::sas::Value::None);
}
catch (const std::exception &e)
{
@@ -158,19 +158,19 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] SAS requirements are parse
{
const auto description = plasp::sas::Description::fromStream(m_cavedivingTestFile);
REQUIRE(description.usesActionCosts());
REQUIRE(description.usesConditionalEffects());
REQUIRE_FALSE(description.usesAxiomRules());
CHECK(description.usesActionCosts());
CHECK(description.usesConditionalEffects());
CHECK_FALSE(description.usesAxiomRules());
REQUIRE(description.operators().size() == 496u);
REQUIRE(description.operators()[0].costs() == 1u);
REQUIRE(description.operators()[172].costs() == 10u);
REQUIRE(description.operators()[173].costs() == 63u);
CHECK(description.operators()[0].costs() == 1u);
CHECK(description.operators()[172].costs() == 10u);
CHECK(description.operators()[173].costs() == 63u);
REQUIRE(description.operators()[172].effects().size() == 3u);
REQUIRE(description.operators()[172].effects()[1].conditions().size() == 1u);
REQUIRE(&description.operators()[172].effects()[1].conditions()[0].value() == &description.variables()[1].values()[4]);
CHECK(&description.operators()[172].effects()[1].conditions()[0].value() == &description.variables()[1].values()[4]);
}
catch (const std::exception &e)
{
@@ -183,5 +183,5 @@ TEST_CASE_METHOD(SASParserTestsFixture, "[SAS parser] SAS requirements are parse
TEST_CASE("[SAS parser] Former issues are fixed", "[SAS parser]")
{
// Check issue where unexpected whitespaces in SAS files led to a parsing error
REQUIRE_NOTHROW(plasp::sas::Description::fromFile("data/issues/issue-6.sas"));
CHECK_NOTHROW(plasp::sas::Description::fromFile("data/issues/issue-6.sas"));
}

View File

@@ -1,14 +1,14 @@
#include <catch.hpp>
#include <plasp/utils/Parser.h>
#include <plasp/utils/ParserException.h>
#include <plasp/input/Parser.h>
#include <plasp/input/ParserException.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
{
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
plasp::utils::Parser<> p("input", s);
plasp::input::Parser<> p("input", s);
REQUIRE(p.parse<std::string>() == "identifier");
REQUIRE(p.parse<size_t>() == 5u);
@@ -19,7 +19,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
REQUIRE(p.parse<int>() == 100);
REQUIRE(p.parse<size_t>() == 200u);
REQUIRE(p.parse<int>() == -300);
REQUIRE_THROWS_AS(p.parse<size_t>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.parse<size_t>(), plasp::input::ParserException);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -27,7 +27,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
{
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
plasp::utils::Parser<> p("input", s);
plasp::input::Parser<> p("input", s);
REQUIRE_NOTHROW(p.expect<std::string>("identifier"));
REQUIRE_NOTHROW(p.expect<size_t>(5u));
@@ -38,31 +38,31 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
REQUIRE_NOTHROW(p.expect<int>(100));
REQUIRE_NOTHROW(p.expect<size_t>(200u));
REQUIRE_NOTHROW(p.expect<int>(-300));
REQUIRE_THROWS_AS(p.expect<size_t>(-400), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<size_t>(-400), plasp::input::ParserException);
p.seek(0);
REQUIRE_THROWS_AS(p.expect<std::string>("error"), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<std::string>("error"), plasp::input::ParserException);
p.seek(14);
REQUIRE_THROWS_AS(p.expect<size_t>(6u), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<size_t>(6u), plasp::input::ParserException);
p.seek(17);
REQUIRE_THROWS_AS(p.expect<int>(-50), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<int>(-50), plasp::input::ParserException);
p.seek(24);
REQUIRE_THROWS_AS(p.expect<bool>(true), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<bool>(true), plasp::input::ParserException);
p.seek(26);
REQUIRE_THROWS_AS(p.expect<bool>(false), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<bool>(false), plasp::input::ParserException);
p.seek(28);
REQUIRE_THROWS_AS(p.expect<int>(101), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<int>(101), plasp::input::ParserException);
p.seek(31);
REQUIRE_THROWS_AS(p.expect<size_t>(201), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<size_t>(201), plasp::input::ParserException);
p.seek(34);
REQUIRE_THROWS_AS(p.expect<int>(-299), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p.expect<int>(-299), plasp::input::ParserException);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -70,9 +70,9 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser]")
{
std::stringstream s(" identifier 5 \n-51\t 0 1");
plasp::utils::Parser<> p("input", s);
plasp::input::Parser<> p("input", s);
plasp::utils::Parser<>::Position pos;
plasp::input::Parser<>::Position pos;
pos = p.position();
REQUIRE(p.testAndReturn<std::string>("error") == false);
@@ -130,136 +130,136 @@ TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser
TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]")
{
std::stringstream s1("test");
plasp::utils::Parser<> p1("input", s1);
plasp::input::Parser<> p1("input", s1);
REQUIRE_NOTHROW(p1.expect<std::string>("test"));
REQUIRE_THROWS_AS(p1.parse<std::string>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p1.parse<std::string>(), plasp::input::ParserException);
std::stringstream s2("test1 test2 test3");
plasp::utils::Parser<> p2("input", s2);
plasp::input::Parser<> p2("input", s2);
REQUIRE_NOTHROW(p2.expect<std::string>("test1"));
REQUIRE_NOTHROW(p2.expect<std::string>("test2"));
REQUIRE_NOTHROW(p2.expect<std::string>("test3"));
REQUIRE_THROWS_AS(p2.parse<std::string>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p2.parse<std::string>(), plasp::input::ParserException);
std::stringstream s3("-127");
plasp::utils::Parser<> p3("input", s3);
plasp::input::Parser<> p3("input", s3);
p3.expect<int>(-127);
REQUIRE_THROWS_AS(p3.parse<int>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p3.parse<int>(), plasp::input::ParserException);
std::stringstream s4("128 -1023 -4095");
plasp::utils::Parser<> p4("input", s4);
plasp::input::Parser<> p4("input", s4);
REQUIRE_NOTHROW(p4.expect<size_t>(128));
REQUIRE_NOTHROW(p4.expect<int>(-1023));
REQUIRE_NOTHROW(p4.expect<int>(-4095));
REQUIRE_THROWS_AS(p4.parse<int>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p4.parse<int>(), plasp::input::ParserException);
std::stringstream s5("0");
plasp::utils::Parser<> p5("input", s5);
plasp::input::Parser<> p5("input", s5);
p5.expect<bool>(false);
REQUIRE_THROWS_AS(p5.parse<bool>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p5.parse<bool>(), plasp::input::ParserException);
std::stringstream s6("0 1 0");
plasp::utils::Parser<> p6("input", s6);
plasp::input::Parser<> p6("input", s6);
REQUIRE_NOTHROW(p6.expect<bool>(false));
REQUIRE_NOTHROW(p6.expect<bool>(true));
REQUIRE_NOTHROW(p6.expect<bool>(false));
REQUIRE_THROWS_AS(p6.parse<bool>(), plasp::utils::ParserException);
REQUIRE_THROWS_AS(p6.parse<bool>(), plasp::input::ParserException);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[parser] While parsing, the cursor coordinate is as expcected", "[parser]")
TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parser]")
{
std::stringstream s("123 \n4\ntest1\n test2\ntest3 \ntest4\n\n\n\n");
plasp::utils::Parser<> p("input", s);
plasp::input::Parser<> p("input", s);
const auto startPosition = p.position();
plasp::utils::StreamCoordinate c;
plasp::input::Location l;
c = p.coordinate();
REQUIRE(c.row == 1u);
REQUIRE(c.column == 1u);
l = p.location();
REQUIRE(l.rowStart == 1u);
REQUIRE(l.columnStart == 1u);
REQUIRE(p.currentCharacter() == '1');
REQUIRE_NOTHROW(p.advance());
c = p.coordinate();
REQUIRE(c.row == 1u);
REQUIRE(c.column == 2u);
l = p.location();
REQUIRE(l.rowStart == 1u);
REQUIRE(l.columnStart == 2u);
REQUIRE(p.currentCharacter() == '2');
REQUIRE_NOTHROW(p.advance());
c = p.coordinate();
REQUIRE(c.row == 1u);
REQUIRE(c.column == 3u);
l = p.location();
REQUIRE(l.rowStart == 1u);
REQUIRE(l.columnStart == 3u);
REQUIRE(p.currentCharacter() == '3');
REQUIRE_NOTHROW(p.advance());
c = p.coordinate();
REQUIRE(c.row == 1u);
REQUIRE(c.column == 4u);
l = p.location();
REQUIRE(l.rowStart == 1u);
REQUIRE(l.columnStart == 4u);
REQUIRE(p.currentCharacter() == ' ');
REQUIRE_NOTHROW(p.advance());
c = p.coordinate();
REQUIRE(c.row == 1u);
REQUIRE(c.column == 5u);
l = p.location();
REQUIRE(l.rowStart == 1u);
REQUIRE(l.columnStart == 5u);
REQUIRE(p.currentCharacter() == '\n');
REQUIRE_NOTHROW(p.advance());
c = p.coordinate();
REQUIRE(c.row == 2u);
REQUIRE(c.column == 1u);
l = p.location();
REQUIRE(l.rowStart == 2u);
REQUIRE(l.columnStart == 1u);
REQUIRE(p.currentCharacter() == '4');
REQUIRE_NOTHROW(p.advance());
REQUIRE_NOTHROW(p.expect<std::string>("test1"));
c = p.coordinate();
REQUIRE(c.row == 3u);
REQUIRE(c.column == 6u);
l = p.location();
REQUIRE(l.rowStart == 3u);
REQUIRE(l.columnStart == 6u);
REQUIRE_NOTHROW(p.expect<std::string>("test2"));
c = p.coordinate();
REQUIRE(c.row == 4u);
REQUIRE(c.column == 7u);
l = p.location();
REQUIRE(l.rowStart == 4u);
REQUIRE(l.columnStart == 7u);
REQUIRE_NOTHROW(p.expect<std::string>("test3"));
c = p.coordinate();
REQUIRE(c.row == 5u);
REQUIRE(c.column == 6u);
l = p.location();
REQUIRE(l.rowStart == 5u);
REQUIRE(l.columnStart == 6u);
REQUIRE_NOTHROW(p.skipLine());
c = p.coordinate();
REQUIRE(c.row == 6u);
REQUIRE(c.column == 1u);
l = p.location();
REQUIRE(l.rowStart == 6u);
REQUIRE(l.columnStart == 1u);
REQUIRE_NOTHROW(p.skipLine());
c = p.coordinate();
REQUIRE(c.row == 7u);
REQUIRE(c.column == 1u);
l = p.location();
REQUIRE(l.rowStart == 7u);
REQUIRE(l.columnStart == 1u);
REQUIRE_NOTHROW(p.skipWhiteSpace());
c = p.coordinate();
REQUIRE(c.row == 10u);
REQUIRE(c.column == 1u);
l = p.location();
REQUIRE(l.rowStart == 10u);
REQUIRE(l.columnStart == 1u);
REQUIRE(p.atEnd());
p.reset();
@@ -285,30 +285,30 @@ TEST_CASE("[parser] While parsing, the cursor coordinate is as expcected", "[par
TEST_CASE("[parser] Comments are correctly removed", "[parser]")
{
std::stringstream s1("; comment at beginning\ntest1; comment in between\ntest2; comment at end");
plasp::utils::Parser<> p1("input", s1);
plasp::input::Parser<> p1("input", s1);
p1.removeComments(";", "\n", false);
plasp::utils::StreamCoordinate c;
plasp::input::Location l;
REQUIRE_NOTHROW(p1.expect<std::string>("test1"));
c = p1.coordinate();
REQUIRE(c.row == 2u);
REQUIRE(c.column == 6u);
l = p1.location();
REQUIRE(l.rowStart == 2u);
REQUIRE(l.columnStart == 6u);
REQUIRE_NOTHROW(p1.expect<std::string>("test2"));
c = p1.coordinate();
REQUIRE(c.row == 3u);
REQUIRE(c.column == 6u);
l = p1.location();
REQUIRE(l.rowStart == 3u);
REQUIRE(l.columnStart == 6u);
p1.skipWhiteSpace();
REQUIRE(p1.atEnd());
std::stringstream s2("test;");
plasp::utils::Parser<> p2("input", s2);
plasp::input::Parser<> p2("input", s2);
p2.removeComments(";", "\n", false);
@@ -319,7 +319,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]")
REQUIRE(p2.atEnd());
std::stringstream s3("/* comment at start */ test1 /* comment in between */ test2 /*");
plasp::utils::Parser<> p3("input", s3);
plasp::input::Parser<> p3("input", s3);
p3.removeComments("/*", "*/", true);