Ejemplo n.º 1
0
        public void ValidRHSTests(string dotNotation, string expected)
        {
            var    paths = PathElementBuilder.ParseDotNotationRHS(dotNotation);
            string actualCanonicalForm = BuildCanonicalString(paths);

            actualCanonicalForm.Should().Be(expected);
        }
Ejemplo n.º 2
0
        public void calculateOutputTest_arrayIndexes()
        {
            // simulate Shiftr LHS specs
            var pe1 = (IMatchablePathElement)PathElementBuilder.ParseSingleKeyLHS("tuna-*-marlin-*");
            var pe2 = (IMatchablePathElement)PathElementBuilder.ParseSingleKeyLHS("rating-*");

            // match them against some data to get LiteralPathElements with captured values
            MatchedElement lpe = pe1.Match("tuna-2-marlin-3", new WalkedPath());

            lpe.GetSubKeyRef(1).Should().Be("2");
            lpe.GetSubKeyRef(2).Should().Be("3");

            MatchedElement lpe2 = pe2.Match("rating-BBB", new WalkedPath(null, lpe));

            lpe2.GetSubKeyCount().Should().Be(2);
            lpe2.GetSubKeyRef(1).Should().Be("BBB");

            // Build an write path path
            ShiftrWriter shiftrWriter = new ShiftrWriter("tuna[&(1,1)].marlin[&(1,2)].&(0,1)");

            shiftrWriter.Size().Should().Be(5);
            shiftrWriter.GetCanonicalForm().Should().Be("tuna.[&(1,1)].marlin.[&(1,2)].&(0,1)");

            // Evaluate the write path against the LiteralPath elements we build above ( like Shiftr does )
            WalkedPath twoSteps = new WalkedPath(null, lpe);

            twoSteps.Add(null, lpe2);
            var stringPath = shiftrWriter.Evaluate(twoSteps);

            stringPath[0].Should().Be("tuna");
            stringPath[1].Should().Be("2");
            stringPath[2].Should().Be("marlin");
            stringPath[3].Should().Be("3");
            stringPath[4].Should().Be("BBB");
        }
Ejemplo n.º 3
0
        public void TestTransposePathParsing()
        {
            var paths = PathElementBuilder.ParseDotNotationRHS("test.@(2,foo\\.bar)");

            paths.Count.Should().Be(2);
            var actualApe = (TransposePathElement)paths[1];

            actualApe.GetCanonicalForm().Should().Be("@(2,foo\\.bar)");
        }
Ejemplo n.º 4
0
        public void calculateOutputTest_refsOnly()
        {
            var pe1 = (IMatchablePathElement)PathElementBuilder.ParseSingleKeyLHS("tuna-*-marlin-*");
            var pe2 = (IMatchablePathElement)PathElementBuilder.ParseSingleKeyLHS("rating-*");

            MatchedElement lpe = pe1.Match("tuna-marlin", new WalkedPath());

            lpe.Should().BeNull();

            lpe = pe1.Match("tuna-A-marlin-AAA", new WalkedPath());
            lpe.RawKey.Should().Be("tuna-A-marlin-AAA");
            lpe.GetSubKeyRef(0).Should().Be("tuna-A-marlin-AAA");
            lpe.GetSubKeyCount().Should().Be(3);
            lpe.GetSubKeyRef(1).Should().Be("A");
            lpe.GetSubKeyRef(2).Should().Be("AAA");

            MatchedElement lpe2 = pe2.Match("rating-BBB", new WalkedPath(null, lpe));

            lpe2.RawKey.Should().Be("rating-BBB");
            lpe2.GetSubKeyRef(0).Should().Be("rating-BBB");
            lpe2.GetSubKeyCount().Should().Be(2);
            lpe2.GetSubKeyRef(1).Should().Be("BBB");

            ShiftrWriter outputPath = new ShiftrWriter("&(1,2).&.value");
            WalkedPath   twoSteps   = new WalkedPath(null, lpe);

            twoSteps.Add(null, lpe2);
            {
                var outputElement    = (IEvaluatablePathElement)outputPath.Get(0);
                var evaledLeafOutput = outputElement.Evaluate(twoSteps);
                evaledLeafOutput.Should().Be("AAA");
            }
            {
                var outputElement    = (IEvaluatablePathElement)outputPath.Get(1);
                var evaledLeafOutput = outputElement.Evaluate(twoSteps);
                evaledLeafOutput.Should().Be("rating-BBB");
            }
            {
                var outputElement    = (IEvaluatablePathElement)outputPath.Get(2);
                var evaledLeafOutput = outputElement.Evaluate(twoSteps);
                evaledLeafOutput.Should().Be("value");
            }
        }
Ejemplo n.º 5
0
 public void FailureRHSTests(string dotNotation)
 {
     FluentActions
     .Invoking(() => PathElementBuilder.ParseDotNotationRHS(dotNotation))
     .Should().Throw <SpecException>();
 }