| 38 | ASSERT_EQ(node.GetValue()->Dump(), val); |
| 39 | |
| 40 | TEST(RedisQueryParserTest, Simple) { |
| 41 | AssertSyntaxError(Parse("")); |
| 42 | AssertSyntaxError(Parse("a")); |
| 43 | AssertSyntaxError(Parse("@a")); |
| 44 | AssertSyntaxError(Parse("a:")); |
| 45 | AssertSyntaxError(Parse("@a:")); |
| 46 | AssertSyntaxError(Parse("@a:[]")); |
| 47 | AssertSyntaxError(Parse("@a:[1 2")); |
| 48 | AssertSyntaxError(Parse("@a:[(inf 1]")); |
| 49 | AssertSyntaxError(Parse("@a:[((1 2]")); |
| 50 | AssertSyntaxError(Parse("@a:[1]")); |
| 51 | AssertSyntaxError(Parse("@a:[1 2 3]")); |
| 52 | AssertSyntaxError(Parse("@a:{}")); |
| 53 | AssertSyntaxError(Parse("@a:{x")); |
| 54 | AssertSyntaxError(Parse("@a:{|}")); |
| 55 | AssertSyntaxError(Parse("@a:{x|}")); |
| 56 | AssertSyntaxError(Parse("@a:{|y}")); |
| 57 | AssertSyntaxError(Parse("@a:{x|y|}")); |
| 58 | AssertSyntaxError(Parse("@a:{x}|")); |
| 59 | AssertSyntaxError(Parse("@a:{x} -")); |
| 60 | AssertSyntaxError(Parse("@a:{x}|@a:{x}|")); |
| 61 | |
| 62 | AssertIR(Parse("@a:[1 2]"), "(and a >= 1, a <= 2)"); |
| 63 | AssertIR(Parse("@a : [1 2]"), "(and a >= 1, a <= 2)"); |
| 64 | AssertIR(Parse("@a:[(1 2]"), "(and a > 1, a <= 2)"); |
| 65 | AssertIR(Parse("@a:[1 (2]"), "(and a >= 1, a < 2)"); |
| 66 | AssertIR(Parse("@a:[(1 (2]"), "(and a > 1, a < 2)"); |
| 67 | AssertIR(Parse("@a:[inf 2]"), "a <= 2"); |
| 68 | AssertIR(Parse("@a:[-inf 2]"), "a <= 2"); |
| 69 | AssertIR(Parse("@a:[1 inf]"), "a >= 1"); |
| 70 | AssertIR(Parse("@a:[1 +inf]"), "a >= 1"); |
| 71 | AssertIR(Parse("@a:[(1 +inf]"), "a > 1"); |
| 72 | AssertIR(Parse("@a:[-inf +inf]"), "true"); |
| 73 | AssertIR(Parse("@a:{x}"), "a hastag \"x\""); |
| 74 | AssertIR(Parse("@a:{x|y}"), R"((or a hastag "x", a hastag "y"))"); |
| 75 | AssertIR(Parse("@a:{x|y|z}"), R"((or a hastag "x", a hastag "y", a hastag "z"))"); |
| 76 | AssertIR(Parse(R"(@a:{"x"|y})"), R"((or a hastag "x", a hastag "y"))"); |
| 77 | AssertIR(Parse(R"(@a:{"x" | "y"})"), R"((or a hastag "x", a hastag "y"))"); |
| 78 | AssertIR(Parse("@a:{x} @b:[1 inf]"), "(and a hastag \"x\", b >= 1)"); |
| 79 | AssertIR(Parse("@a:{x} | @b:[1 inf]"), "(or a hastag \"x\", b >= 1)"); |
| 80 | AssertIR(Parse("@a:{x} @b:[1 inf] @c:{y}"), "(and a hastag \"x\", b >= 1, c hastag \"y\")"); |
| 81 | AssertIR(Parse("@a:{x}|@b:[1 inf] | @c:{y}"), "(or a hastag \"x\", b >= 1, c hastag \"y\")"); |
| 82 | AssertIR(Parse("@a:[1 inf] @b:[inf 2]| @c:[(3 inf]"), "(or (and a >= 1, b <= 2), c > 3)"); |
| 83 | AssertIR(Parse("@a:[1 inf] | @b:[inf 2] @c:[(3 inf]"), "(or a >= 1, (and b <= 2, c > 3))"); |
| 84 | AssertIR(Parse("(@a:[1 inf] @b:[inf 2])| @c:[(3 inf]"), "(or (and a >= 1, b <= 2), c > 3)"); |
| 85 | AssertIR(Parse("@a:[1 inf] | (@b:[inf 2] @c:[(3 inf])"), "(or a >= 1, (and b <= 2, c > 3))"); |
| 86 | AssertIR(Parse("@a:[1 inf] (@b:[inf 2]| @c:[(3 inf])"), "(and a >= 1, (or b <= 2, c > 3))"); |
| 87 | AssertIR(Parse("(@a:[1 inf] | @b:[inf 2]) @c:[(3 inf]"), "(and (or a >= 1, b <= 2), c > 3)"); |
| 88 | AssertIR(Parse("-@a:{x}"), "not a hastag \"x\""); |
| 89 | AssertIR(Parse("-@a:[(1 +inf]"), "not a > 1"); |
| 90 | AssertIR(Parse("-@a:[1 inf] @b:[inf 2]| -@c:[(3 inf]"), "(or (and not a >= 1, b <= 2), not c > 3)"); |
| 91 | AssertIR(Parse("@a:[1 inf] -(@b:[inf 2]| @c:[(3 inf])"), "(and a >= 1, not (or b <= 2, c > 3))"); |
| 92 | AssertIR(Parse("*"), "true"); |
| 93 | AssertIR(Parse("* *"), "(and true, true)"); |
| 94 | AssertIR(Parse("*|*"), "(or true, true)"); |
| 95 | } |
| 96 | |
| 97 | TEST(RedisQueryParserTest, Params) { |