private static string BuildText( CodeWriterHelperHierarchy hierarchy ) { var list = new List<CodeWriterHelper>(); AppendHierarchy( 0, list, hierarchy ); return BuildText( list ); }
public void InnerAppendCodeWriterTest() { var linesStart = new[] { new CodeWriterHelper( 0, "namespace Test" ), new CodeWriterHelper( 0, "{" ), new CodeWriterHelper( 1, "public class Main" ), new CodeWriterHelper( 1, "{" ), }; var linesEnd = new[] { new CodeWriterHelper( 1, "}" ), new CodeWriterHelper( 0, "}" ), }; var lines1 = new[] { new CodeWriterHelper( 1, "public void Method1()" ), new CodeWriterHelper( 1, "{" ), new CodeWriterHelper( 1, "}" ), }; var lines2 = new[] { new CodeWriterHelper( 1, "public void Method2( int value )" ), new CodeWriterHelper( 1, "{" ), new CodeWriterHelper( 1, "}" ), }; var mainCodeWriter = GetCodeWriter( linesStart ); mainCodeWriter.Append( GetCodeWriter( lines1 ) ); mainCodeWriter.AppendLine(); mainCodeWriter.Append( GetCodeWriter( lines2 ) ); mainCodeWriter.AppendLine(); AppendCodeWriter( mainCodeWriter, linesEnd ); var hierarchy = new CodeWriterHelperHierarchy( linesStart, linesEnd, new CodeWriterHelperHierarchy( lines1, lines2 ) ); var expectedText = BuildText( hierarchy ); var actualText = mainCodeWriter.ToString(); Assert.That( actualText, Is.EqualTo( expectedText ) ); }
private static void AppendHierarchy( int startIndent, ICollection<CodeWriterHelper> list, CodeWriterHelperHierarchy hierarchy ) { var lastIndent = 0; foreach (var helper in hierarchy.startHelpers) { list.Add( new CodeWriterHelper( startIndent + helper.indent, helper.texts ) ); lastIndent = helper.indent; } foreach (var item in hierarchy.innerItems) AppendHierarchy( lastIndent, list, item ); foreach (var helper in hierarchy.endHelpers) list.Add( new CodeWriterHelper( startIndent + helper.indent, helper.texts ) ); }