public IJsonMasherOperator RecordPosition(IJsonMasherOperator ast, int startPosition) { SourceInformation.SetProgramPosition( ast, new ProgramPosition(startPosition, _tokens[_index - 1].EndPos)); return(ast); }
public static (IEnumerable <Json> json, IMashContext context) RunAsSequenceWithContext( this IJsonMasherOperator op, Json data) { var masher = new Mashers.JsonMasher(); var result = masher.Mash(data.AsEnumerable(), op, DefaultMashStack.Instance); return(json : result.sequence, context : result.context); }
public void BooleanTestsTheory(IJsonMasherOperator op, string input, string output) { // Arrange // Act var result = op.RunAsSequence(input.AsJson()); // Assert Json.Array(result) .DeepEqual(output.AsJson()) .Should().BeTrue(); }
public (IEnumerable <Json> sequence, IMashContext context) Mash( IEnumerable <Json> seq, IJsonMasherOperator op, IMashStack stack, SourceInformation sourceInformation = null, int tickLimit = 0) { MashContext _context = MashContext.CreateContext(tickLimit, sourceInformation, stack); return( sequence : seq.SelectMany(json => op.Mash(json, _context)), context : _context); }
public IJsonMasherOperator RecordPosition( IJsonMasherOperator ast, IJsonMasherOperator first, IJsonMasherOperator last) { var posFirst = SourceInformation.GetProgramPosition(first); var posLast = SourceInformation.GetProgramPosition(last); SourceInformation.SetProgramPosition( ast, new ProgramPosition( posFirst?.StartPosition ?? 0, posLast?.EndPosition ?? 0)); return(ast); }
public static IEnumerable <PathAndValue> GeneratePaths( IJsonMasherOperator masher, Json json, IMashContext context) { if (masher is IPathGenerator generator) { foreach (var pathAndValue in generator.GeneratePaths(JsonPath.Empty, json, context)) { yield return(pathAndValue); } } else { throw context.PushStack(masher).Error("Not a path expression."); } }
public void MiscellaneousTestsTheory( IJsonMasherOperator op, string input, string output, string stdErr) { // Arrange // Act var(result, context) = op.RunAsSequenceWithContext(input.AsJson()); // Assert Json.Array(result) .DeepEqual(output.AsJson()) .Should().BeTrue(); if (stdErr != null) { Json.Array(context.Log) .DeepEqual(stdErr.AsJson()) .Should().BeTrue(); } }
public void ParseTest(string program, IJsonMasherOperator expectation) { // Arrange var parser = new Parser(); // Act var(result, _) = parser.Parse(program); // Assert result.Should().BeEquivalentTo( expectation, options => options .RespectingRuntimeTypes() .WithStrictOrdering() .ComparingByValue <Builtin>() .ComparingByMembers <PropertyDescriptor>() .ComparingByMembers <FunctionName>() .ComparingByMembers <ObjectMatcherProperty>() .ComparingByMembers <ObjectMatcher>() .ComparingByValue <Enumerate>() .ComparingByValue <Identity>()); }
private record TestItem(IJsonMasherOperator Op, string Input, string Output, string StdErr = null);
public static (Json json, IMashContext context) RunAsScalarWithContext( this IJsonMasherOperator op, Json data) { var(json, context) = op.RunAsSequenceWithContext(data); return(json.First(), context); }
public static Json RunAsScalar(this IJsonMasherOperator op, Json data) => op.RunAsSequence(data).First();
public static IEnumerable <Json> RunAsSequence(this IJsonMasherOperator op, Json data) => op.RunAsSequenceWithContext(data).json;
private record TestItem(IJsonMasherOperator Op, string Input, string Output);
public IMashStack Push(IJsonMasherOperator op) => this;
private record TestItem(string program, IJsonMasherOperator expectation);
private static IEnumerable <FunctionDefinition> ExtractFunctionDefinitions(IJsonMasherOperator ast) => ast switch {