public void GetNormalized_MultipleIndexes_ReturnsSelf()
        {
            var element = new JsonPathArrayIndexListElement(new[] { 7, 42 });

            var actual = element.GetNormalized();

            actual.Should().Be(element);
        }
        public void Matches_UnknownArrayIndexList_ReturnsFalse()
        {
            var element = new JsonPathArrayIndexElement(7);
            var other   = new JsonPathArrayIndexListElement(new[] { 0, 7 });

            bool?actual = element.Matches(other);

            actual.Should().BeFalse();
        }
        public void Matches_ArrayIndexList(int?start, int?end, int step, int index, bool?expected)
        {
            var element = new JsonPathArraySliceElement(start, end, step);
            var other   = new JsonPathArrayIndexListElement(new [] { index });

            bool?actual = element.Matches(other);

            actual.Should().Be(expected);
        }
        public void Matches_ArrayIndexList(string expression, int indexCount, bool?expected)
        {
            var element = new JsonPathExpressionElement(expression);
            var other   = new JsonPathArrayIndexListElement(Enumerable.Range(0, indexCount).ToList());

            bool?actual = element.Matches(other);

            actual.Should().Be(expected);
        }
        public void GetNormalized_PeriodicIndexesStartingFromZero_ReturnsArraySliceElementWithNullStart()
        {
            var element  = new JsonPathArrayIndexListElement(new[] { 0, 1, 2, 3 });
            var expected = new JsonPathArraySliceElement(null, 4, 1);

            var actual = element.GetNormalized();

            actual.Should().BeEquivalentTo(expected);
        }
        public void GetNormalized_PeriodicIndexesWithNegativeStep_ReturnsArraySliceElement()
        {
            var element  = new JsonPathArrayIndexListElement(new[] { 3, 2, 1 });
            var expected = new JsonPathArraySliceElement(3, 0, -1);

            var actual = element.GetNormalized();

            actual.Should().BeEquivalentTo(expected);
        }
        public void GetNormalized_PeriodicIndexes_ReturnsArraySliceElement()
        {
            var element  = new JsonPathArrayIndexListElement(new[] { 1, 2, 3 });
            var expected = new JsonPathArraySliceElement(1, 4, 1);

            var actual = element.GetNormalized();

            actual.Should().BeEquivalentTo(expected);
        }
        public void GetNormalized_SingleIndex_ReturnsArrayIndexElement()
        {
            var element  = new JsonPathArrayIndexListElement(new [] { 42 });
            var expected = new JsonPathArrayIndexElement(42);

            var actual = element.GetNormalized();

            actual.Should().BeEquivalentTo(expected);
        }
        public void Matches_Any_ReturnsFalse(JsonPathElementType type)
        {
            var element = new JsonPathArrayIndexListElement(new [] { 0, 1 });
            var other   = ElementCreator.CreateAny(type);

            bool?actual = element.Matches(other);

            actual.Should().BeFalse();
        }
        public void Matches_KnownArrayIndexesList_ReturnsTrue()
        {
            var element = new JsonPathArrayIndexListElement(new [] { 0, 1, 2, 3 });
            var other   = new JsonPathArrayIndexListElement(new [] { 1, 2 });

            bool?actual = element.Matches(other);

            actual.Should().BeTrue();
        }
        public void GetNormalized_PeriodicIndexesEndingWithMaxValue_ReturnsArraySliceElementWithNullEnd()
        {
            var element  = new JsonPathArrayIndexListElement(new[] { int.MaxValue - 6, int.MaxValue - 4, int.MaxValue - 2, int.MaxValue });
            var expected = new JsonPathArraySliceElement(int.MaxValue - 6, null, 2);

            var actual = element.GetNormalized();

            actual.Should().BeEquivalentTo(expected);
        }
Exemple #12
0
        private static void AppendArrayIndexList(this StringBuilder builder, JsonPathArrayIndexListElement element)
        {
            builder.Append('[');

            bool isFirst = true;

            foreach (int index in element.Indexes)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    builder.Append(',');
                }

                builder.Append(index);
            }

            builder.Append(']');
        }
        public void IsNormalized(bool expected, params int[] indexes)
        {
            var element = new JsonPathArrayIndexListElement(indexes);

            element.IsNormalized.Should().Be(expected);
        }