Пример #1
0
 public IJsonMasherOperator RecordPosition(IJsonMasherOperator ast, int startPosition)
 {
     SourceInformation.SetProgramPosition(
         ast,
         new ProgramPosition(startPosition, _tokens[_index - 1].EndPos));
     return(ast);
 }
Пример #2
0
        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);
        }
Пример #3
0
        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();
        }
Пример #4
0
        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);
        }
Пример #5
0
            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);
            }
Пример #6
0
 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.");
     }
 }
Пример #7
0
        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();
            }
        }
Пример #8
0
        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>());
        }
Пример #9
0
 private record TestItem(IJsonMasherOperator Op, string Input, string Output, string StdErr = null);
Пример #10
0
 public static (Json json, IMashContext context) RunAsScalarWithContext(
     this IJsonMasherOperator op, Json data)
 {
     var(json, context) = op.RunAsSequenceWithContext(data);
     return(json.First(), context);
 }
Пример #11
0
 public static Json RunAsScalar(this IJsonMasherOperator op, Json data)
 => op.RunAsSequence(data).First();
Пример #12
0
 public static IEnumerable <Json> RunAsSequence(this IJsonMasherOperator op, Json data)
 => op.RunAsSequenceWithContext(data).json;
Пример #13
0
 private record TestItem(IJsonMasherOperator Op, string Input, string Output);
Пример #14
0
 public IMashStack Push(IJsonMasherOperator op) => this;
Пример #15
0
 private record TestItem(string program, IJsonMasherOperator expectation);
Пример #16
0
 private static IEnumerable <FunctionDefinition> ExtractFunctionDefinitions(IJsonMasherOperator ast)
 => ast switch
 {