Example #1
0
        public void AllTries_StartWithCompilationUnit(string code)
        {
            var tree = SimpleSyntaxNode.FromSourceCode(code);

            Assert.AreEqual(SyntaxKind.CompilationUnit, tree.Kind);
            Assert.AreEqual(SyntaxNodeType.Node, tree.Type);
        }
        public static string GetJsonTreeFromFile(string path, Encoding encoding = null)
        {
            encoding ??= Encoding.UTF8;
            var code = string.Empty;

            if (File.Exists(path))
            {
                code = File.ReadAllText(path, encoding);
            }

            var tree    = SimpleSyntaxNode.FromSourceCode(code);
            var options = new JsonSerializerOptions {
                MaxDepth = (int)1e4
            };

            return(JsonSerializer.Serialize(tree, typeof(SimpleSyntaxNode), options));
        }
Example #3
0
        public void SimpleTest_When_EmptyCode()
        {
            const string code       = "";
            var          actualTree = SimpleSyntaxNode.FromSourceCode(code);

            var endOfFile = new SimpleSyntaxNode(
                SyntaxNodeType.Token,
                SyntaxKind.EndOfFileToken,
                value: "");

            var expectedTree = new SimpleSyntaxNode(
                SyntaxNodeType.Node,
                SyntaxKind.CompilationUnit,
                new List <SimpleSyntaxNode> {
                endOfFile
            });

            expectedTree.Should().BeEquivalentTo(actualTree);
        }
        public static string GetJsonTreeFromCode(string code)
        {
            var tree = SimpleSyntaxNode.FromSourceCode(code);

            return(JsonSerializer.Serialize(tree));
        }