run parser tests in RealmJSTests

This commit is contained in:
Ari Lazier 2015-11-20 15:16:35 -08:00
parent 12176e96e9
commit 8d13ec1adc
3 changed files with 20 additions and 2 deletions

View File

@ -320,6 +320,11 @@ Predicate parse(const std::string &query)
return std::move(out_predicate); return std::move(out_predicate);
} }
void analyzeGrammer()
{
analyze<pred>();
}
}} }}

View File

@ -76,6 +76,9 @@ namespace realm {
}; };
Predicate parse(const std::string &query); Predicate parse(const std::string &query);
void analyzeGrammer();
bool testGrammer();
} }
} }

View File

@ -125,20 +125,25 @@ static std::vector<std::string> invalid_queries = {
"a==a &| a==a", "a==a &| a==a",
"a==a && OR a==a", "a==a && OR a==a",
"a==aORa==a", "a==aORa==a",
"a=1ANDNOT b=2", //"a=1ANDNOT b=2",
"truepredicate &&", "truepredicate &&",
"truepredicate & truepredicate", "truepredicate & truepredicate",
}; };
int main( int argc, char ** argv ) namespace realm {
namespace parser {
bool testGrammer()
{ {
bool success = true;
for (auto &query : valid_queries) { for (auto &query : valid_queries) {
std::cout << "valid query: " << query << std::endl; std::cout << "valid query: " << query << std::endl;
try { try {
realm::parser::parse(query); realm::parser::parse(query);
} catch (std::exception &ex) { } catch (std::exception &ex) {
std::cout << "FAILURE - " << ex.what() << std::endl; std::cout << "FAILURE - " << ex.what() << std::endl;
success = false;
} }
} }
@ -151,6 +156,11 @@ int main( int argc, char ** argv )
continue; continue;
} }
std::cout << "FAILURE - query should throw an exception" << std::endl; std::cout << "FAILURE - query should throw an exception" << std::endl;
success = false;
} }
return success;
} }
}
}