public void Random_access_of_indents_works() { var writer = new IndentedTextWriter(new StringWriter(), " "); foreach (var i in new[] { 4, 2, 5, -7, 0, 5, -1, 9, 0, 0 }) { writer.Indent = i; var j = i < 0 ? 0 : i; Assert.Equal(j * 3, writer.CurrentIndentation().Length); Assert.Equal(j * 3, writer.CurrentIndentation().Length); } }
[Fact] // CodePlex 1603 public void Extreme_indentation_does_not_overflow_buffer_size() { var output = new StringWriter(); var writer = new IndentedTextWriter(output, " "); var totalLength = 0; // Run once, filling the cache for (var i = 0; i < 500; i++) { writer.Indent = i; Assert.Equal(i * 3, writer.CurrentIndentation().Length); writer.WriteLine("OhNo!"); totalLength += i * 3 + 7; Assert.Equal(totalLength, output.ToString().Length); } // Run again, this time using the cache for (var i = 0; i < 500; i++) { writer.Indent = i; Assert.Equal(i * 3, writer.CurrentIndentation().Length); } }
private void Generate(ProcedureOperation procedureOperation, string methodName, IndentedTextWriter writer) { DebugCheck.NotNull(procedureOperation); DebugCheck.NotEmpty(methodName); DebugCheck.NotNull(writer); writer.Write(methodName); writer.WriteLine("("); writer.Indent++; writer.Write(Quote(procedureOperation.Name)); writer.WriteLine(","); if (procedureOperation.Parameters.Any()) { writer.WriteLine("Function(p) New With"); writer.Indent++; writer.WriteLine("{"); writer.Indent++; procedureOperation.Parameters.Each( (p, i) => { var scrubbedName = ScrubName(p.Name); writer.Write("."); writer.Write(scrubbedName); writer.Write(" ="); Generate(p, writer, !string.Equals(p.Name, scrubbedName, StringComparison.Ordinal)); if (i < procedureOperation.Parameters.Count - 1) { writer.Write(","); } writer.WriteLine(); }); writer.Indent--; writer.WriteLine("},"); writer.Indent--; } writer.Write("body :="); if (!string.IsNullOrWhiteSpace(procedureOperation.BodySql)) { writer.WriteLine(); writer.Indent++; var indentString = "\" & vbCrLf & _" + writer.NewLine + writer.CurrentIndentation() + "\""; writer.WriteLine( Generate( procedureOperation .BodySql .Replace(Environment.NewLine, indentString))); writer.Indent--; } else { writer.WriteLine(" \"\""); } writer.Indent--; writer.WriteLine(")"); writer.WriteLine(); }