public void TestMatcherNestedAnyInAnyInEqualsNoMatch()
        {
            const string expressionJson  = @"
[""anyin"",
    1,
    [""field"", ""nestedArray""],
    [""anyin"",
        2,
        [""field"", 1],
        [""equals"",
            [""field"", 2],
            [""value"", ""z""]
        ]
    ]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new string[] { };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void TestMatcherAnyEveryInEquals()
        {
            const string expressionJson  = @"
[""anyeveryin"",
    1,
    [""field"", ""testArray""],
    [""equals"",
        [""field"", 1],
        [""value"", ""jewels""]
    ]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new[]
            {
                "5b47eb0936ff92a567a0307e"
            };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void TestMatcherSometimesMissingBoolEquals()
        {
            const string expressionJson  = @"
[""equals"",
    [""field"", ""sometimesValue""],
    [""value"", false]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new[]
            {
                "5b47eb0936ff92a567a0307e",
                "5b47eb096b1d911c0b9492fb"
            };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void TestMatcherTrueEquals()
        {
            const string expressionJson  = @"
[""equals"",
    [""field"",""isActive""],
    [""value"",true]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new[]
            {
                "5b47eb0936ff92a567a0307e",
                "5b47eb0950e9076fc0aecd52",
                "5b47eb095c3ad73b9925f7f8",
                "5b47eb0962222a37d066e231",
                "5b47eb09996a4154c35b2f98",
                "5b47eb098eee4b4c4330ec64"
            };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void TestMatcherNotTrueEquals()
        {
            const string expressionJson =
                @"
[""not"",
    [""equals"",
        [""field"", ""isActive""],
        [""value"", true]
    ]
]";
            var expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new[]
            {
                "5b47eb096b1d911c0b9492fb",
                "5b47eb093771f06ced629663",
                "5b47eb09ffac5a6ce37042e7",
                "5b47eb091f57571d3c3b1aa1"
            };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void Simple_False_Expression()
        {
            var expression = new FalseExpression();
            var bytes      = Encoding.UTF8.GetBytes(EmptyJson);
            var matcher    = new SlowMatcher(new[] { expression });

            Assert.False(matcher.Match(bytes));
        }
        public void LessThan(int value, bool expected)
        {
            var expression = new LessThanExpression(
                new FieldExpression(0, "age"),
                new ValueExpression(10)
                );

            var json  = $"{{ \"age\": {value} }}";
            var bytes = Encoding.UTF8.GetBytes(json);

            var matcher = new SlowMatcher(new[] { expression });

            Assert.Equal(expected, matcher.Match(bytes));
        }
        public void Not_GreaterEqual(int value, bool expected)
        {
            // not >= 0
            var expression = new NotExpression(
                new GreaterEqualExpression(
                    new FieldExpression(0, "age"),
                    new ValueExpression(10)
                    )
                );

            var json  = $"{{ \"age\": {value} }}";
            var bytes = Encoding.UTF8.GetBytes(json);

            var matcher = new SlowMatcher(new[] { expression });

            Assert.Equal(expected, matcher.Match(bytes));
        }
        public void Equals_(dynamic value)
        {
            var expression = new EqualsExpression(
                new FieldExpression(0, "value"),
                new ValueExpression(value)
                );

            if (value is string)
            {
                value = $"\"{value}\"";
            }

            var json  = $"{{ \"value\": {value.ToString().ToLower()} }}";
            var bytes = Encoding.UTF8.GetBytes(json);

            var matcher = new SlowMatcher(new[] { expression });

            Assert.True(matcher.Match(bytes));
        }
        public void Or()
        {
            var expression = new OrExpression(
                new EqualsExpression(
                    new FieldExpression(0, "name"),
                    new ValueExpression("jeff")
                    ),
                new GreaterEqualExpression(
                    new FieldExpression(0, "age"),
                    new ValueExpression(10) // should fail
                    )
                );

            const string json  = "{ \"name\": \"mike\", \"age\": 50 }";
            var          bytes = Encoding.UTF8.GetBytes(json);

            var matcher = new SlowMatcher(new[] { expression });

            Assert.True(matcher.Match(bytes));
        }
        public void TestMatcherMissingStringEquals()
        {
            const string expressionJson  = @"
[""equals"",
    [""field"", ""someValueWhichNeverExists""],
    [""value"", ""hello""]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new string[] { };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void TestMatcherFloatEquals()
        {
            const string expressionJson  = @"
[""equals"",
    [""field"",""latitude""],
    [""value"",-40.262556]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new[] { "5b47eb096b1d911c0b9492fb" };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }
        public void TestMatcherNumericEquals()
        {
            const string expressionJson  = @"
[""equals"",
    [""field"",""age""],
    [""value"",25]
]";
            var          expressionBytes = Encoding.UTF8.GetBytes(expressionJson);

            var parser     = new SimpleParser();
            var expression = parser.ParseJsonExpression(expressionBytes);

            var matcher = new SlowMatcher(new[] { expression });

            var ids = new[] { "5b47eb091f57571d3c3b1aa1" };

            foreach (var entry in _peopleData.Where(x => ids.Contains(x.Key)))
            {
                var data = Encoding.UTF8.GetBytes(entry.Value);
                Assert.True(matcher.Match(data));
            }
        }