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 MatchedElement Match(string dataKey, WalkedPath walkedPath) { if (RawKey == dataKey) { return(new MatchedElement(RawKey)); } return(null); }
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 MatchedElement Match(string dataKey, WalkedPath walkedPath) { return(walkedPath.LastElement().MatchedElement); // copy what our parent was so that write keys of &0 and &1 both work. }
public string Evaluate(WalkedPath walkedPath) => RawKey;
public virtual MatchedElement Match(string dataKey, WalkedPath walkedPath) { string evaled = Evaluate(walkedPath); return(new MatchedElement(evaled)); }
public virtual string Evaluate(WalkedPath walkedPath) { MatchedElement pe = walkedPath.ElementFromEnd(_dRef.GetPathIndex()).MatchedElement; return(pe.GetSubKeyRef(_dRef.GetKeyGroup())); }