Пример #1
0
        /// <summary>
        /// Dump the node recursively to a json format for diffing.
        /// </summary>
        /// <param name="node">The <see cref="SyntaxNode"/>.</param>
        /// <param name="settings">The <see cref="AstWriterSettings"/>.</param>
        /// <returns>The node serialized into a string format.</returns>
        public static string Serialize(SyntaxNode node, AstWriterSettings settings = null)
        {
            var writer = new AstWriter(settings ?? AstWriterSettings.Default).Write(node);

            return(writer.ToString());
        }
Пример #2
0
 /// <summary>
 /// Serializes the syntax tree and compares the strings.
 /// This can be useful when having trouble getting whitespace right.
 /// </summary>
 /// <typeparam name="T">The node type.</typeparam>
 /// <param name="expected">The expected shape of the AST.</param>
 /// <param name="actual">The actual node.</param>
 /// <param name="settings"><see cref="AstWriterSettings"/>.</param>
 public static void Ast <T>(T expected, T actual, AstWriterSettings settings = null)
     where T : SyntaxNode
 {
     CodeAssert.AreEqual(AstWriter.Serialize(expected, settings), AstWriter.Serialize(actual, settings));
 }