first string tests and custom error messages
This commit is contained in:
parent
a64fab83ad
commit
be93d3dd58
|
@ -288,17 +288,34 @@ template<> struct action< not_pre >
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template< typename Rule >
|
||||||
|
struct error_message_control : pegtl::normal< Rule >
|
||||||
|
{
|
||||||
|
static const std::string error_message;
|
||||||
|
|
||||||
|
template< typename Input, typename ... States >
|
||||||
|
static void raise( const Input & in, States && ... )
|
||||||
|
{
|
||||||
|
throw pegtl::parse_error( error_message, in );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
const std::string error_message_control< chars >::error_message = "Invalid characters in string constant.";
|
||||||
|
|
||||||
|
template< typename Rule>
|
||||||
|
const std::string error_message_control< Rule >::error_message = "Invalid predicate.";
|
||||||
|
|
||||||
Predicate parse(const std::string &query)
|
Predicate parse(const std::string &query)
|
||||||
{
|
{
|
||||||
analyze< pred >();
|
analyze< pred >();
|
||||||
const std::string source = "user query";
|
|
||||||
|
|
||||||
Predicate out_predicate(Predicate::Type::And);
|
Predicate out_predicate(Predicate::Type::And);
|
||||||
|
|
||||||
ParserState state;
|
ParserState state;
|
||||||
state.predicate_stack.push_back(&out_predicate);
|
state.predicate_stack.push_back(&out_predicate);
|
||||||
|
|
||||||
pegtl::parse< must< pred, eof >, action >(query, source, state);
|
pegtl::parse< must< pred, eof >, action, error_message_control >(query, query, state);
|
||||||
if (out_predicate.type == Predicate::Type::And && out_predicate.cpnd.sub_predicates.size() == 1) {
|
if (out_predicate.type == Predicate::Type::And && out_predicate.cpnd.sub_predicates.size() == 1) {
|
||||||
return std::move(out_predicate.cpnd.sub_predicates.back());
|
return std::move(out_predicate.cpnd.sub_predicates.back());
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ var testCases = {
|
||||||
"floatTests" : {
|
"floatTests" : {
|
||||||
"schema" : [{
|
"schema" : [{
|
||||||
"name": "FloatObject",
|
"name": "FloatObject",
|
||||||
"properties": [{ "name": "floatCol", "type": Realm.Types.Float }],
|
"properties": [{ "name": "floatCol", "type": Realm.Types.FLOAT }],
|
||||||
}],
|
}],
|
||||||
"objects": [
|
"objects": [
|
||||||
{ "type": "FloatObject", "value": [-1.001] },
|
{ "type": "FloatObject", "value": [-1.001] },
|
||||||
|
@ -191,7 +191,7 @@ var testCases = {
|
||||||
"doubleTests" : {
|
"doubleTests" : {
|
||||||
"schema" : [{
|
"schema" : [{
|
||||||
"name": "DoubleObject",
|
"name": "DoubleObject",
|
||||||
"properties": [{ "name": "doubleCol", "type": Realm.Types.Double }],
|
"properties": [{ "name": "doubleCol", "type": Realm.Types.DOUBLE }],
|
||||||
}],
|
}],
|
||||||
"objects": [
|
"objects": [
|
||||||
{ "type": "DoubleObject", "value": [-1.001] },
|
{ "type": "DoubleObject", "value": [-1.001] },
|
||||||
|
@ -221,16 +221,23 @@ var testCases = {
|
||||||
|
|
||||||
"stringTests" : {
|
"stringTests" : {
|
||||||
"schema" : [{
|
"schema" : [{
|
||||||
"name": "DoubleObject",
|
"name": "StringObject",
|
||||||
"properties": [{ "name": "doubleCol", "type": Realm.Types.Double }],
|
"properties": [{ "name": "stringCol", "type": Realm.Types.STRING }],
|
||||||
}],
|
}],
|
||||||
"objects": [
|
"objects": [
|
||||||
{ "type": "DoubleObject", "value": [-1.001] },
|
{ "type": "StringObject", "value": ["A"] },
|
||||||
{ "type": "DoubleObject", "value": [0.0] },
|
{ "type": "StringObject", "value": ["a"] },
|
||||||
{ "type": "DoubleObject", "value": [100.2] },
|
{ "type": "StringObject", "value": ["a"] },
|
||||||
|
{ "type": "StringObject", "value": ["abc"] },
|
||||||
|
{ "type": "StringObject", "value": [""] },
|
||||||
|
{ "type": "StringObject", "value": ["\\\"\\n\\0\\r\\\\'"] },
|
||||||
],
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
["QueryCount", 1, "DoubleObject", "doubleCol == -1.001"],
|
["QueryCount", 2, "StringObject", "stringCol == 'a'"],
|
||||||
|
["QueryCount", 2, "StringObject", "stringCol == \"a\""],
|
||||||
|
["QueryCount", 1, "StringObject", "stringCol == 'abc'"],
|
||||||
|
["QueryCount", 1, "StringObject", "stringCol == ''"],
|
||||||
|
["QueryCount", 1, "StringObject", "stringCol == \"\\\"\\n\\0\\r\\\\'\""],
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -374,10 +381,13 @@ module.exports = BaseTest.extend({
|
||||||
runQuerySuite(testCases.intTests);
|
runQuerySuite(testCases.intTests);
|
||||||
},
|
},
|
||||||
testFloatQueries: function() {
|
testFloatQueries: function() {
|
||||||
runQuerySuite(testCases.intTests);
|
runQuerySuite(testCases.floatTests);
|
||||||
},
|
},
|
||||||
testDoubleQueries: function() {
|
testDoubleQueries: function() {
|
||||||
runQuerySuite(testCases.intTests);
|
runQuerySuite(testCases.doubleTests);
|
||||||
|
},
|
||||||
|
testStringQueries: function() {
|
||||||
|
runQuerySuite(testCases.stringTests);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue