예제 #1
0
        public void Numbers()
        {
            // Arrange
            var data = Json.Null;
            var op   = new FunctionCall(Minus.Builtin_2, new Literal(2), new Literal(1));

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual(Utils.JsonNumberArray(1)).Should().BeTrue();
        }
예제 #2
0
        public void ToJsonTest()
        {
            // Arrange
            var data = "[1, 2, 3, {}]".AsJson();
            var op   = new FunctionCall(ToJson.Builtin);

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[\"[1, 2, 3, {}]\"]".AsJson()).Should().BeTrue();
        }
예제 #3
0
        public void FirstTest()
        {
            // Arrange
            var data = Json.ArrayParams(Json.Number(0), Json.Number(1));
            var op   = new FunctionCall(First.Builtin, new Enumerate());

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[0]".AsJson()).Should().BeTrue();
        }
예제 #4
0
        public void ImplodeTest()
        {
            // Arrange
            var data = "[97, 98, 99, 100]".AsJson();
            var op   = new FunctionCall(Implode.Builtin);

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[\"abcd\"]".AsJson()).Should().BeTrue();
        }
예제 #5
0
        public void TestEmpty()
        {
            // Arrange
            var data = MakeNestedArray();
            var op   = new FunctionCall(Empty.Builtin);

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            result.Count().Should().Be(0);
        }
예제 #6
0
        public void ContainsStringsTest()
        {
            // Arrange
            var data = Json.String("abacabacab");
            var op   = new FunctionCall(
                Contains.Builtin, new Literal("acab"));

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[true]".AsJson()).Should().BeTrue();
        }
예제 #7
0
        public void Strings()
        {
            // Arrange
            var data = Json.String("a");
            var op   = new FunctionCall(Plus.Builtin, new Identity(), new Identity());

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result)
            .DeepEqual(Json.ArrayParams(Json.String("aa")))
            .Should().BeTrue();
        }
예제 #8
0
        public void Arrays()
        {
            // Arrange
            var data = Json.ArrayParams(Json.Number(1));
            var op   = new FunctionCall(Plus.Builtin, new Identity(), new Identity());

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result)
            .DeepEqual(Json.ArrayParams(Utils.JsonNumberArray(1, 1)))
            .Should().BeTrue();
        }
예제 #9
0
        public void InnerIterateNumbers()
        {
            // Arrange
            var data = Utils.JsonNumberArray(1, 2, 3);
            var op   = new FunctionCall(Plus.Builtin, new Enumerate(), new Enumerate());

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result)
            .DeepEqual(Utils.JsonNumberArray(2, 3, 4, 3, 4, 5, 4, 5, 6))
            .Should().BeTrue();
        }
예제 #10
0
        public void NumbersAndStrings()
        {
            // Arrange
            var data = Json.Null;
            var op   = new FunctionCall(Times.Builtin, new Literal(3), new Literal("ba"));

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result)
            .DeepEqual(Json.ArrayParams(Json.String("bababa")))
            .Should().BeTrue();
        }
예제 #11
0
        public void ContainsDictionaryTest()
        {
            // Arrange
            var data = "{\"a\":1,\"b\":2,\"c\":3}".AsJson();
            var op   = new FunctionCall(
                Contains.Builtin, new Literal {
                Value = "{\"a\":1,\"c\":3}".AsJson()
            });

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[true]".AsJson()).Should().BeTrue();
        }
예제 #12
0
        public void MaxByTestEmpty()
        {
            // Arrange
            var data = Json.ArrayParams();
            var op   = new FunctionCall(
                MaxBy.Builtin, new Literal {
                Value = "[]".AsJson()
            });

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[null]".AsJson()).Should().BeTrue();
        }
예제 #13
0
        public void MaxByTest()
        {
            // Arrange
            var data = Json.ArrayParams(Json.Number(0), Json.Number(1), Json.Number(0), Json.Number(2));
            var op   = new FunctionCall(
                MaxBy.Builtin, new Literal {
                Value = "[[0], [1], [0], [2]]".AsJson()
            });

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[2]".AsJson()).Should().BeTrue();
        }
예제 #14
0
        public void Singleline()
        {
            // Arrange
            var data = Json.String("th\nis");
            var op   = new FunctionCall(
                RegexMatch.Builtin,
                new Literal("th$"),
                new Literal("s"),
                new Literal {
                Value = Json.False
            });

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            Json.Array(result).DeepEqual("[]".AsJson()).Should().BeTrue();
        }
예제 #15
0
        public void NowTest()
        {
            // Arrange
            var data = Json.Null;
            var op   = new FunctionCall(DateFunctions.Now);

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            result.Count().Should().Be(1);
            result.First().Type.Should().Be(JsonValueType.Number);
            var epoch     = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var utcNow    = DateTime.UtcNow;
            var assertion = Math.Abs(result.First().GetNumber() - (utcNow - epoch).TotalSeconds) < 1;

            assertion.Should().BeTrue();
        }
예제 #16
0
        public void ObjectsWithLiteral()
        {
            // Arrange
            var data = Json.ObjectParams(new JsonProperty("a", Json.Number(1)));
            var op   = new FunctionCall(
                Plus.Builtin,
                new Identity(),
                new Literal {
                Value = Json.ObjectParams(new JsonProperty("b", Json.Number(2)))
            });

            // Act
            var result = op.RunAsSequence(data);

            // Assert
            var expectedValue = Json.ArrayParams(Json.ObjectParams(
                                                     new JsonProperty("a", Json.Number(1)),
                                                     new JsonProperty("b", Json.Number(2))));

            Json.Array(result).DeepEqual(expectedValue).Should().BeTrue();
        }