Ejemplo n.º 1
0
        /// <summary>
        /// <seealso cref="JsonTokenizerTests.TwoSymbolsOfEachType"/>.
        /// </summary>
        public static IEnumerable <object[]> TwoSymbolsWithoutType()
        {
            var symbolTypes = JsonTokenizerTests.JsonTestSymbols();

            // Unterminated strings/comments mess up the tokenization, skip those if they're the first key.
            foreach (var(key1, _) in symbolTypes)
            {
                foreach (var(key2, _) in symbolTypes.Union(JsonTokenizerTests.UnterminatedJsonTestSymbols()))
                {
                    yield return(new object[] { key1, key2 });
                }
            }
        }
Ejemplo n.º 2
0
        public void ParseTreeTokensMatch(string json1, string json2)
        {
            // Sane structure as JsonTokenizerTests.Transition: first check two symbols, then all combinations of three.
            {
                string json           = json1 + json2;
                var    expectedTokens = JsonParser.TokenizeAll(json).Item1;
                Action <IJsonSymbol>[] tokenInspectors = expectedTokens.Select <IGreenJsonSymbol, Action <IJsonSymbol> >((IGreenJsonSymbol expectedGreen) => (IJsonSymbol red) =>
                {
                    IGreenJsonSymbol actualGreen = TerminalSymbolTester.Instance.Visit(red);
                    Assert.IsType(expectedGreen.GetType(), actualGreen);
                    Assert.Equal(expectedGreen.Length, actualGreen.Length);
                    Assert.Equal(expectedGreen.Length, red.Length);
                }).ToArray();

                Assert.Collection(
                    JsonParser.Parse(json).Syntax.TerminalSymbolsInRange(0, json.Length),
                    tokenInspectors);
            }

            // Here Assert.Collection is used so if such a test fails,
            // it gives the index of the third token that was tested.
            Assert.Collection(
                JsonTokenizerTests.JsonTestSymbols(),
                Enumerable.Repeat <Action <(string, Type)> >(x0 =>
            {
                string json        = x0.Item1 + json1 + json2;
                var expectedTokens = JsonParser.TokenizeAll(json).Item1;
                Action <IJsonSymbol>[] tokenInspectors = expectedTokens.Select <IGreenJsonSymbol, Action <IJsonSymbol> >(expectedGreen => symbol =>
                {
                    IGreenJsonSymbol actualGreen = TerminalSymbolTester.Instance.Visit(symbol);
                    Assert.IsType(expectedGreen.GetType(), actualGreen);
                    Assert.Equal(expectedGreen.Length, actualGreen.Length);
                    Assert.Equal(expectedGreen.Length, symbol.Length);
                }).ToArray();

                Assert.Collection(
                    JsonParser.Parse(json).Syntax.TerminalSymbolsInRange(0, json.Length),
                    tokenInspectors);
            }, JsonTokenizerTests.JsonTestSymbols().Count()).ToArray());
        }