This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/tests/TestUtils.cpp

33 lines
1.2 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include <plasp/utils/Parsing.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-05-24 02:23:56 +02:00
TEST(UtilsTests, ParseSimple)
{
std::stringstream stream("identifier 5 \n-51\t expected unexpected 100 -100");
ASSERT_EQ(plasp::utils::parse<std::string>(stream), "identifier");
ASSERT_EQ(plasp::utils::parse<size_t>(stream), 5);
ASSERT_EQ(plasp::utils::parse<int>(stream), -51);
ASSERT_NO_THROW(plasp::utils::parseExpected<std::string>(stream, "expected"));
ASSERT_THROW(plasp::utils::parseExpected<std::string>(stream, "expected"), plasp::utils::ParserException);
ASSERT_NO_THROW(plasp::utils::parseExpected<size_t>(stream, 100));
ASSERT_THROW(plasp::utils::parseExpected<size_t>(stream, 100), plasp::utils::ParserException);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST(UtilsTests, EscapeASP)
{
const std::string predicate = "action(stack_on(block-1, block-2, value@3, value@4))";
const auto escaped = plasp::utils::escapeASP(predicate);
const auto unescaped = plasp::utils::unescapeASP(escaped);
ASSERT_EQ(escaped.find("-"), std::string::npos);
ASSERT_EQ(escaped.find("@"), std::string::npos);
ASSERT_EQ(predicate, unescaped);
}