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"); }
public void StarPatternTest(string spec, string dataKey, string expected1, string expected2) { IStarPathElement star = new StarRegexPathElement(spec); MatchedElement lpe = star.Match(dataKey, null); lpe.GetSubKeyCount().Should().Be(3); lpe.GetSubKeyRef(0).Should().Be(dataKey); lpe.GetSubKeyRef(1).Should().Be(expected1); lpe.GetSubKeyRef(2).Should().Be(expected2); }
public void TestStarsInMiddleNonGreedy() { IStarPathElement star = new StarDoublePathElement("a*b*c"); MatchedElement lpe = star.Match("abbccbccc", null); // a -> a // * -> b index 1 // b -> b // * -> ccbcc index 2 // c -> c lpe.GetSubKeyRef(0).Should().Be("abbccbccc"); lpe.GetSubKeyRef(1).Should().Be("b"); lpe.GetSubKeyRef(2).Should().Be("ccbcc"); lpe.GetSubKeyCount().Should().Be(3); }
public void TestStarInFirstAndMiddle() { IStarPathElement star = new StarDoublePathElement("*a*"); star.StringMatch("bbbaaccccc").Should().BeTrue(); star.StringMatch("abbbbbbbbcc").Should().BeFalse(); star.StringMatch("bbba").Should().BeFalse(); MatchedElement lpe = star.Match("bbbaccc", null); // * -> bbb // a -> a // * -> ccc lpe.GetSubKeyRef(0).Should().Be("bbbaccc"); lpe.GetSubKeyRef(1).Should().Be("bbb"); lpe.GetSubKeyRef(2).Should().Be("ccc"); lpe.GetSubKeyCount().Should().Be(3); }
public void TestStarInMiddle() { IStarPathElement star = new StarSinglePathElement("tuna-*-marlin"); star.StringMatch("tuna-tuna-marlin").Should().BeTrue(); star.StringMatch("tuna-bob-marlin").Should().BeTrue(); star.StringMatch("tuna--marlin").Should().BeFalse(); star.StringMatch("tunamarlin").Should().BeFalse(); star.StringMatch("marlin-bob-tuna").Should().BeFalse(); MatchedElement lpe = star.Match("tuna-bob-marlin", null); lpe.GetSubKeyRef(0).Should().Be("tuna-bob-marlin"); lpe.GetSubKeyRef(1).Should().Be("bob"); lpe.GetSubKeyCount().Should().Be(2); star.Match("bob", null).Should().BeNull(); }
public void TestStarAtFront() { IStarPathElement star = new StarSinglePathElement("*-tuna"); star.StringMatch("tuna-tuna").Should().BeTrue(); star.StringMatch("bob-tuna").Should().BeTrue(); star.StringMatch("-tuna").Should().BeFalse(); // * has to catch something star.StringMatch("tuna").Should().BeFalse(); star.StringMatch("tuna-bob").Should().BeFalse(); MatchedElement lpe = star.Match("bob-tuna", null); lpe.GetSubKeyRef(0).Should().Be("bob-tuna"); lpe.GetSubKeyRef(1).Should().Be("bob"); lpe.GetSubKeyCount().Should().Be(2); star.Match("-tuna", null).Should().BeNull(); }
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"); } }
public void TestStarsInMiddle() { IStarPathElement star = new StarDoublePathElement("a*b*c"); star.StringMatch("a123b456c").Should().BeTrue(); star.StringMatch("abccbcc").Should().BeTrue(); MatchedElement lpe = star.Match("abccbcc", null); // a -> a // * -> bcc index 1 // b -> b // * -> c index 2 // c -> c lpe.GetSubKeyRef(0).Should().Be("abccbcc"); lpe.GetSubKeyRef(1).Should().Be("bcc"); lpe.GetSubKeyRef(2).Should().Be("c"); lpe.GetSubKeyCount().Should().Be(3); }
public void TestStarAtFrontAndEnd() { IStarPathElement star = new StarDoublePathElement("*a*c"); star.StringMatch("bbbbadddc").Should().BeTrue(); star.StringMatch("bacc").Should().BeTrue(); star.StringMatch("bac").Should().BeFalse(); star.StringMatch("baa").Should().BeFalse(); MatchedElement lpe = star.Match("abcadefc", null); // * -> abc // a -> a index 4 // * -> def // c -> c lpe.GetSubKeyRef(0).Should().Be("abcadefc"); lpe.GetSubKeyRef(1).Should().Be("abc"); lpe.GetSubKeyRef(2).Should().Be("def"); lpe.GetSubKeyCount().Should().Be(3); }
public void TestStarAtMiddleAndEnd() { IStarPathElement star = new StarDoublePathElement("a*b*"); star.StringMatch("adbc").Should().BeTrue(); star.StringMatch("abbc").Should().BeTrue(); star.StringMatch("adddddd").Should().BeFalse(); star.StringMatch("addb").Should().BeFalse(); star.StringMatch("abc").Should().BeFalse(); MatchedElement lpe = star.Match("abcbbac", null); // a -> a // * -> bc index 1 // b -> b index 3 // * -> bac index 4 // c -> c lpe.GetSubKeyRef(0).Should().Be("abcbbac"); lpe.GetSubKeyRef(1).Should().Be("bc"); lpe.GetSubKeyRef(2).Should().Be("bac"); lpe.GetSubKeyCount().Should().Be(3); }
public DocumentRange CalculateRange() => MatchedElement.GetHighlightingRange();
public virtual string Evaluate(WalkedPath walkedPath) { MatchedElement pe = walkedPath.ElementFromEnd(_dRef.GetPathIndex()).MatchedElement; return(pe.GetSubKeyRef(_dRef.GetKeyGroup())); }