void TestProgram(string program, PrettyPrintOptions options)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(program));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
			outputVisitor.Options = options;
			outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
		}
		void TestStatement(string statement, PrettyPrintOptions options)
		{
			StringBuilder b = new StringBuilder();
			b.AppendLine("void Method()");
			b.AppendLine("{");
			using (StringReader r = new StringReader(statement)) {
				string line;
				while ((line = r.ReadLine()) != null) {
					b.Append("  ");
					b.AppendLine(line);
				}
			}
			b.AppendLine("}");
			TestTypeMember(b.ToString(), options);
		}
		void TestTypeMember(string program, PrettyPrintOptions options)
		{
			StringBuilder b = new StringBuilder();
			b.AppendLine("class A");
			b.AppendLine("{");
			using (StringReader r = new StringReader(program)) {
				string line;
				while ((line = r.ReadLine()) != null) {
					b.Append("  ");
					b.AppendLine(line);
				}
			}
			b.AppendLine("}");
			TestProgram(b.ToString(), options);
		}
		public void IfStatementSeparateLines()
		{
			PrettyPrintOptions options = new PrettyPrintOptions();
			options.PlaceElseOnNewLine = true;
			options.StatementBraceStyle = BraceStyle.NextLine;
			
			TestStatement("if (a)\n" +
			              "{\n" +
			              "  m1();\n" +
			              "}\n" +
			              "else\n" +
			              "{\n" +
			              "  m2();\n" +
			              "}", options);
			
			TestStatement("if (a)\n" +
			              "{\n" +
			              "  m1();\n" +
			              "}\n" +
			              "else if (b)\n" +
			              "{\n" +
			              "  m2();\n" +
			              "}\n" +
			              "else\n" +
			              "{\n" +
			              "  m3();\n" +
			              "}", options);
		}
 public CSharpOutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
 {
     this.prettyPrintOptions = prettyPrintOptions;
 }
Example #6
0
		static PrettyPrintOptions CreatePrettyPrintOptions()
		{
			PrettyPrintOptions options = new PrettyPrintOptions();
			options.PropertyBraceStyle = BraceStyle.NextLine;
			options.PropertyGetBraceStyle = BraceStyle.NextLine;
			options.PropertySetBraceStyle = BraceStyle.NextLine;
			options.ClassBraceStyle = BraceStyle.NextLine;
			options.IndentationChar = ' ';
			options.IndentSize = 4;
			options.TabSize = 4;			
			return options;
		}
		public CSharpOutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
		{
			this.prettyPrintOptions = prettyPrintOptions;
		}