From aa3bad1a69a3f32f00908dcc3b29701b02256792 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 18 Nov 2015 12:40:25 -0800 Subject: [PATCH] more string tests and bugfix --- src/object-store/parser/query_builder.cpp | 3 +++ tests/QueryTests.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/object-store/parser/query_builder.cpp b/src/object-store/parser/query_builder.cpp index a836f777..9039ef6b 100644 --- a/src/object-store/parser/query_builder.cpp +++ b/src/object-store/parser/query_builder.cpp @@ -267,6 +267,9 @@ struct ValueGetter { if (value.type == parser::Expression::Type::Argument) { return args.string_for_argument(std::stoi(value.s)); } + if (value.type != parser::Expression::Type::String) { + throw std::runtime_error("Attempting to compare String property to a non-String value"); + } return value.s; } }; diff --git a/tests/QueryTests.js b/tests/QueryTests.js index 8970ea1f..3edf4773 100644 --- a/tests/QueryTests.js +++ b/tests/QueryTests.js @@ -52,9 +52,10 @@ function runQuerySuite(suite) { TestCase.assertEqual(test[1], results.length, "Query '" + args[1] + "' on type '" + args[0] + "' expected " + test[1] + " results, got " + results.length); } else if (test[0] == "QueryThrows") { + var args = test.slice(1); TestCase.assertThrows(function() { - realm.objects.apply(realm, test.slice(1)); - }); + realm.objects.apply(realm, args); + }, "Expected exception not thrown for query: " + JSON.stringify(args)); } else { throw "Invalid query test '" + test[0] + "'"; @@ -253,6 +254,12 @@ var testCases = { ["QueryCount", 1, "StringObject", "stringCol CONTAINS 'b'"], ["QueryCount", 2, "StringObject", "stringCol contains 'c'"], ["QueryCount", 9, "StringObject", "stringCol CONTAINS ''"], + ["QueryCount", 2, "StringObject", "stringCol == $0", "a"], + ["QueryCount", 2, "StringObject", "stringCol ENDSWITH $0", "c"], + + ["QueryThrows", "StringObject", "stringCol == true"], + ["QueryThrows", "StringObject", "stringCol == 123"], + ["QueryThrows", "StringObject", "stringCol CONTAINS $0", 1], // ["QueryCount", 3, "StringObject", "stringCol ==[c] 'a'"], // ["QueryCount", 5, "StringObject", "stringCol BEGINSWITH[c] 'A'"],