add basic test harness for grammer validation
This commit is contained in:
parent
7829d21bd4
commit
f46e92468c
|
@ -1,7 +0,0 @@
|
|||
#include "parser.hpp"
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
realm::parser::parse(argv[1]);
|
||||
}
|
||||
|
|
@ -137,7 +137,6 @@ struct ParserState
|
|||
template< typename Rule >
|
||||
struct action : nothing< Rule > {};
|
||||
|
||||
#define REALM_PARSER_PRINT_TOKENS
|
||||
#ifdef REALM_PARSER_PRINT_TOKENS
|
||||
#define DEBUG_PRINT_TOKEN(string) std::cout << string << std::endl
|
||||
#else
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
#include "parser.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
static std::vector<std::string> valid_queries = {
|
||||
"truepredicate",
|
||||
"falsepredicate",
|
||||
"TRUEPREDICATE",
|
||||
"FALSEPREDICATE",
|
||||
"truepredicate && truepredicate"
|
||||
};
|
||||
|
||||
static std::vector<std::string> invalid_queries = {
|
||||
"predicate",
|
||||
"truepredicate &&",
|
||||
"truepredicate & truepredicate",
|
||||
};
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
for (auto &query : valid_queries) {
|
||||
std::cout << "valid query: " << query << std::endl;
|
||||
try {
|
||||
realm::parser::parse(query);
|
||||
} catch (std::exception &ex) {
|
||||
std::cout << "FAILURE - " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &query : invalid_queries) {
|
||||
std::cout << "invalid query: " << query << std::endl;
|
||||
try {
|
||||
realm::parser::parse(query);
|
||||
} catch (std::exception &ex) {
|
||||
// std::cout << "message: " << ex.what() << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cout << "FAILURE - query should throw an exception" << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# /bin/sh
|
||||
llvm-g++ -std=c++11 -I ../../../vendor/PEGTL/ -o test test.cpp parser.cpp
|
||||
./test
|
Loading…
Reference in New Issue