2012-06-09 23:26:44 +04:00
|
|
|
#include "parsertests.h"
|
|
|
|
#include "handlermacros.h"
|
|
|
|
#include "yaml-cpp/yaml.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Test
|
|
|
|
{
|
|
|
|
namespace Parser {
|
2012-06-09 23:39:00 +04:00
|
|
|
TEST NoEndOfMapFlow()
|
2012-06-09 23:26:44 +04:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
HANDLE("---{header: {id: 1");
|
|
|
|
} catch(const YAML::ParserException& e) {
|
2012-06-09 23:39:00 +04:00
|
|
|
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::END_OF_MAP_FLOW));
|
2012-06-09 23:26:44 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return " no exception caught";
|
|
|
|
}
|
2012-11-09 05:00:46 +04:00
|
|
|
|
|
|
|
TEST PlainScalarStartingWithQuestionMark()
|
|
|
|
{
|
|
|
|
HANDLE("foo: ?bar");
|
|
|
|
EXPECT_DOC_START();
|
|
|
|
EXPECT_MAP_START("?", 0);
|
|
|
|
EXPECT_SCALAR("?", 0, "foo");
|
|
|
|
EXPECT_SCALAR("?", 0, "?bar");
|
|
|
|
EXPECT_MAP_END();
|
|
|
|
EXPECT_DOC_END();
|
|
|
|
DONE();
|
|
|
|
}
|
2012-06-09 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
|
|
|
TEST ret;
|
|
|
|
try {
|
|
|
|
ret = test();
|
|
|
|
} catch(const YAML::Exception& e) {
|
|
|
|
ret.ok = false;
|
|
|
|
ret.error = std::string(" Exception caught: ") + e.what();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ret.ok) {
|
2012-09-16 02:50:44 +04:00
|
|
|
std::cout << "Parser test failed: " << name << "\n";
|
2012-06-09 23:26:44 +04:00
|
|
|
std::cout << ret.error << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret.ok)
|
|
|
|
passed++;
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RunParserTests()
|
|
|
|
{
|
|
|
|
int passed = 0;
|
|
|
|
int total = 0;
|
2012-06-09 23:39:00 +04:00
|
|
|
RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total);
|
2012-11-09 05:00:46 +04:00
|
|
|
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total);
|
2012-06-09 23:26:44 +04:00
|
|
|
|
|
|
|
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
|
|
|
|
return passed == total;
|
|
|
|
}
|
|
|
|
}
|