diff --git a/parser/main.cpp b/parser/main.cpp deleted file mode 100644 index def876c3..00000000 --- a/parser/main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "parser.hpp" - -int main( int argc, char ** argv ) -{ - realm::parser::parse(argv[1]); -} - diff --git a/parser/parser.cpp b/parser/parser.cpp index c7d18a7f..ef15fd48 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -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 diff --git a/parser/test.cpp b/parser/test.cpp new file mode 100644 index 00000000..23494306 --- /dev/null +++ b/parser/test.cpp @@ -0,0 +1,45 @@ + +#include "parser.hpp" + +#include +#include +#include +#include + +static std::vector valid_queries = { + "truepredicate", + "falsepredicate", + "TRUEPREDICATE", + "FALSEPREDICATE", + "truepredicate && truepredicate" +}; + +static std::vector 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; + } +} + diff --git a/parser/test.sh b/parser/test.sh new file mode 100755 index 00000000..aad1d031 --- /dev/null +++ b/parser/test.sh @@ -0,0 +1,3 @@ +# /bin/sh +llvm-g++ -std=c++11 -I ../../../vendor/PEGTL/ -o test test.cpp parser.cpp +./test