2017-06-18 05:18:52 +02:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
|
|
|
|
#include <pddlparse/AST.h>
|
|
|
|
#include <pddlparse/Parse.h>
|
|
|
|
|
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
|
2017-06-19 00:52:04 +02:00
|
|
|
const pddl::Context::WarningCallback ignoreWarnings = [](const auto &, const auto &){};
|
2017-06-18 05:18:52 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TEST_CASE("[PDDL parser issues] Check past issues", "[PDDL parser issues]")
|
|
|
|
{
|
|
|
|
pddl::Tokenizer tokenizer;
|
|
|
|
pddl::Context context(std::move(tokenizer), ignoreWarnings);
|
|
|
|
|
2017-06-24 20:27:01 +02:00
|
|
|
/*SECTION("white space issues with constants and parsing unsupported sections")
|
2017-06-19 01:15:20 +02:00
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-1.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
CHECK_NOTHROW(pddl::parseDescription(context));
|
2017-06-24 20:27:01 +02:00
|
|
|
}*/
|
2017-06-19 01:15:20 +02:00
|
|
|
|
2017-06-24 20:27:01 +02:00
|
|
|
/*SECTION("white space issues with empty n-ary predicates")
|
2017-06-19 01:15:20 +02:00
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-2.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
CHECK_NOTHROW(pddl::parseDescription(context));
|
2017-06-24 20:27:01 +02:00
|
|
|
}*/
|
2017-06-19 01:15:20 +02:00
|
|
|
|
2017-06-24 20:27:01 +02:00
|
|
|
/*SECTION("comments are correctly ignored")
|
2017-06-19 01:15:20 +02:00
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-3.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
CHECK_NOTHROW(pddl::parseDescription(context));
|
2017-06-24 20:27:01 +02:00
|
|
|
}*/
|
2017-06-19 01:15:20 +02:00
|
|
|
|
2017-06-18 05:18:52 +02:00
|
|
|
// Check that no infinite loop occurs
|
|
|
|
SECTION("“either” in typing section")
|
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-7.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
CHECK_THROWS(pddl::parseDescription(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that whitespace is correctly ignored in type section
|
|
|
|
SECTION("whitespace in typing section")
|
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-8.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
CHECK_NOTHROW(pddl::parseDescription(context));
|
|
|
|
}
|
2017-06-21 16:55:56 +02:00
|
|
|
|
|
|
|
// Check that accidentally unnamed variables lead to an exception and not a segfault
|
|
|
|
SECTION("whitespace in typing section")
|
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-9.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
CHECK_THROWS(pddl::parseDescription(context));
|
|
|
|
}
|
2017-06-21 22:54:07 +02:00
|
|
|
|
|
|
|
// Check that “at” is allowed as a predicate name and not exclusively for “at” expressions
|
|
|
|
SECTION("“at” as predicate name")
|
|
|
|
{
|
|
|
|
const auto domainFile = fs::path("data") / "issues" / "issue-10.pddl";
|
|
|
|
context.tokenizer.read(domainFile);
|
|
|
|
|
|
|
|
const auto description = pddl::parseDescription(context);
|
|
|
|
|
|
|
|
REQUIRE(description.problem);
|
|
|
|
|
|
|
|
const auto &problem = description.problem.value();
|
|
|
|
const auto &facts = problem->initialState.facts;
|
|
|
|
|
|
|
|
const auto invalidFact = std::find_if(facts.cbegin(), facts.cend(),
|
|
|
|
[](const auto &fact)
|
|
|
|
{
|
2017-06-24 20:14:06 +02:00
|
|
|
return fact.template is<pddl::ast::AtPointer<pddl::ast::Literal>>();
|
2017-06-21 22:54:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const auto containsInvalidFact = (invalidFact != facts.cend());
|
|
|
|
|
|
|
|
CHECK(!containsInvalidFact);
|
|
|
|
}
|
2017-06-18 05:18:52 +02:00
|
|
|
}
|