Esempio n. 1
0
        public void TestBug325187()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.ElseNewLinePlacement = NewLinePlacement.NewLine;

            TestStatementFormatting(policy,
                                    @"foreach (int i in myints)
if (i == 6)
Console.WriteLine (""Yeah"");
else
Console.WriteLine (""Bad indent"");",
                                    @"foreach (int i in myints)
	if (i == 6)
		Console.WriteLine (""Yeah"");
	else
		Console.WriteLine (""Bad indent"");"        );
        }
        public void TestIndentPreprocessorStatementsAdd()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.IndentPreprocessorDirectives = true;

            Test(policy,
                 @"class Test
{
#region DEBUG
#endregion
}", @"class Test
{
	#region DEBUG

	#endregion
}");
        }
Esempio n. 3
0
        public void TestBrackets_StackedIfElse_AlignElseToCorrectIf()
        {
            CSharpFormattingOptions fmt = FormattingOptionsFactory.CreateMono();

            fmt.AlignEmbeddedStatements = false;
            fmt.AlignElseInIfStatements = false;
            var indent = Helper.CreateEngine(@"
class Foo {
	void Test ()
	{ 
		if (true)
			if (true)
			{ }
			else $ "            , fmt);

            Assert.AreEqual("\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t\t", indent.NextLineIndent);
        }
Esempio n. 4
0
        public void TestBrackets_AnonymousMethodAsFirstParameterWithoutAlignment()
        {
            var policy = FormattingOptionsFactory.CreateMono();

            policy.AlignToFirstMethodCallArgument = policy.AlignToFirstIndexerArgument = false;

            var indent = Helper.CreateEngine(@"
class Foo 
{
	void Test ()
	{ 
		Foo (delegate {
			$
", policy);

            Assert.AreEqual("\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t", indent.NextLineIndent);
        }
        public void TestYieldReturnIndentation()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.ClassBraceStyle = BraceStyle.EndOfLine;
            Test(policy, @"class Test {
	Test TestMethod ()
	{
yield return null;
	}
}",
                 @"class Test {
	Test TestMethod ()
	{
		yield return null;
	}
}");
        }
Esempio n. 6
0
        public void TestBug16231()
        {
            var policy = FormattingOptionsFactory.CreateMono();

            var indent = Helper.CreateEngine(@"
class Foo 
{
	void Test ()
	{ 
		switch (foo) {
		}
		if (true) {
			$
", policy);

            Assert.AreEqual("\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t", indent.NextLineIndent);
        }
 public void TestContinueSemicolon()
 {
     CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
     Test(policy, @"class Test
     {
     Test TestMethod ()
     {
     continue ;
     }
     }",
          @"class Test
     {
     Test TestMethod ()
     {
     continue;
     }
     }");
 }
Esempio n. 8
0
        public void DeepMethodContinuationStatement()
        {
            var fmt = FormattingOptionsFactory.CreateMono();
            // fmt.AlignToFirstMethodCallArgument = false;
            var indent = Helper.CreateEngine(@"
class Foo
{
	void Test ()
	{
		if (true)
			Call(A)
				.Foo ()
				.Foo ()
				.Foo (); $"                , fmt);

            Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t", indent.NextLineIndent);
        }
 public void TestThrowSemicolon()
 {
     CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
     Test(policy, @"class Test
     {
     Test TestMethod ()
     {
     throw new NotSupportedException () 	 ;
     }
     }",
          @"class Test
     {
     Test TestMethod ()
     {
     throw new NotSupportedException ();
     }
     }");
 }
Esempio n. 10
0
        public void TestConstantVariableDeclarationIndentation()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();
            policy.ClassBraceStyle = BraceStyle.EndOfLine;

            Test(policy, @"class Test {
            Test TestMethod ()
            {
            const int a = 5;
            }
            }",
                 @"class Test {
            Test TestMethod ()
            {
            const int a = 5;
            }
            }");
        }
Esempio n. 11
0
        public void DeepMethodContinuationStatement_AlignToMemberReferenceDot()
        {
            CSharpFormattingOptions fmt = FormattingOptionsFactory.CreateMono();

            fmt.AlignToMemberReferenceDot = true;
            var indent = Helper.CreateEngine(@"
class Foo
{
	void Test ()
	{
		if (true)
			Call(A).Foo ()
			       .Foo ()
			       .Foo (); $"            , fmt);

            Assert.AreEqual("\t\t\t       ", indent.ThisLineIndent);
            Assert.AreEqual("\t\t", indent.NextLineIndent);
        }
Esempio n. 12
0
        public void BinaryExpressionAlignment()
        {
            CSharpFormattingOptions fmt = FormattingOptionsFactory.CreateMono();

            fmt.AlignToFirstIndexerArgument = false;
            var indent = Helper.CreateEngine(@"
class Foo
{
	void Test ()
	{
		public static bool IsComplexExpression(AstNode expr)
		{
			return expr.StartLocation.Line != expr.EndLocation.Line ||
				expr is ConditionalExpression ||$"                , fmt);

            Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t\t", indent.NextLineIndent);
        }
        public void PasteVerbatimString()
        {
            var indent = CreateEngine(@"
class Foo
{
void Bar ()
{
	
}
}");
            ITextPasteHandler handler = new TextPasteIndentEngine(indent, new TextEditorOptions {
                EolMarker = "\n"
            }, FormattingOptionsFactory.CreateMono());
            var str  = "string str = @\"\n1\n\t2 \n\t\t3\n\";";
            var text = handler.FormatPlainText(indent.Offset, str, null);

            Assert.AreEqual(str, text);
        }
Esempio n. 14
0
        public void TestBug670213()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.MethodBraceStyle = BraceStyle.EndOfLine;

            Test(policy, @"class Test
{
	Test MyMethod() // Comment
	{
	}
}",
                 @"class Test
{
	Test MyMethod () { // Comment
	}
}");
        }
Esempio n. 15
0
        public void TestBrackets_AnonymousMethodAsParameterCase2()
        {
            var opt = FormattingOptionsFactory.CreateMono();
            //opt.AlignToFirstMethodCallArgument = false;
            var indent = Helper.CreateEngine(@"
class Foo {
	void Test ()
	{ 
		Foo (a,
			b,
			delegate {
				evlel();
				$
", opt);

            Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t\t", indent.NextLineIndent);
        }
Esempio n. 16
0
        public void TestIndentPropertyOneLineCase2()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.SimplePropertyFormatting = PropertyFormatting.AllowOneLine;
            policy.SimpleGetBlockFormatting = PropertyFormatting.AllowOneLine;
            policy.SimpleSetBlockFormatting = PropertyFormatting.AllowOneLine;

            Test(policy,
                 @"class Test
{
	Test TestMe {      get { ; }set{;}                  }
}",
                 @"class Test
{
	Test TestMe { get { ; } set { ; } }
}");
        }
Esempio n. 17
0
        public void TestBrackets_StackedIfElseIf_IfInNewLine()
        {
            var fmt = FormattingOptionsFactory.CreateMono();
            // fmt.AlignEmbeddedStatements = false;
            var indent = Helper.CreateEngine(@"
class Foo {
	void Test ()
	{ 
		if (true)
			FooBar ();
		else
			if (true) {
				$
", fmt);

            Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t\t", indent.NextLineIndent);
        }
        public void TestEmptyStatementIndentation()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.ClassBraceStyle = BraceStyle.EndOfLine;

            Test(policy, @"class Test {
	Test TestMethod ()
	{
;
	}
}", @"class Test {
	Test TestMethod ()
	{
		;
	}
}");
        }
Esempio n. 19
0
        public void TestBrackets_RemoveStatementContinuationWhenNoSemicolon()
        {
            var fmt = FormattingOptionsFactory.CreateMono();
            // fmt.AlignEmbeddedStatements = false;
            var indent = Helper.CreateEngine(@"
class Foo {
	void Test ()
	{ 
		if (true)
			using (this)
				if (true)
				{
					// ...
				} $ "                , fmt);

            Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t", indent.NextLineIndent);
        }
        public void TestYieldBreakSemicolon()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.ClassBraceStyle = BraceStyle.EndOfLine;
            Test(policy, @"class Test {
	Test TestMethod ()
	{
		yield break      ;
	}
}",
                 @"class Test {
	Test TestMethod ()
	{
		yield break;
	}
}");
        }
Esempio n. 21
0
        public void TestBug677261()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.ConstructorBraceStyle = BraceStyle.EndOfLine;

            Test(policy, @"class Test
{
	Test ()
	   {
	}
}",
                 @"class Test
{
	Test () {
	}
}");
        }
Esempio n. 22
0
        public void TestNextLineShifted_IfStatement()
        {
            var policy = FormattingOptionsFactory.CreateMono();

            policy.StatementBraceStyle = BraceStyle.NextLineShifted;
            var indent = Helper.CreateEngine(@"
class Foo 
{
	public static void Main (string[] args)
	{
		if (true)
		{$
	}
", policy);

            Assert.AreEqual("\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t", indent.NextLineIndent);
        }
Esempio n. 23
0
        public void TestBug12270()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            Test(policy,
                 @"class C
{
	public void Test<T> () where T : new  ()
	{
	}
}",
                 @"class C
{
	public void Test<T> () where T : new()
	{
	}
}");
        }
Esempio n. 24
0
        public void TestBrackets_CustomIndent6()
        {
            CSharpFormattingOptions fmt = FormattingOptionsFactory.CreateMono();

            fmt.AlignEmbeddedStatements = false;
            var indent = Helper.CreateEngine(@"
class Foo {
	void Test ()
	{
		using (this)
			if (true)
	{
				$	
	}"    , fmt);

            Assert.AreEqual("\t\t\t\t", indent.ThisLineIndent);
            Assert.AreEqual("\t\t\t\t", indent.NextLineIndent);
        }
Esempio n. 25
0
        public void TestClassIndentationWithDocComment()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.ClassBraceStyle = BraceStyle.DoNotChange;

            Test(policy,
                 @"/// <summary>
		/// olwcowcolwc
		/// </summary>
			class Test {
}",
                 @"/// <summary>
/// olwcowcolwc
/// </summary>
class Test {
}");
        }
Esempio n. 26
0
        public void TestPropertyForceOneLine()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.SimplePropertyFormatting = PropertyFormatting.ForceOneLine;

            Test(policy, @"class Test
{
	Test A {
		get { return null; }
		set { ; }
	}
}",
                 @"class Test
{
	Test A { get { return null; } set { ; } }
}");
        }
Esempio n. 27
0
        public void TestIndentPropertyBodyIndexerCase()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.IndentPropertyBody = true;

            var adapter = Test(policy,
                               @"class Test
{
	Test this[int a] {
			get {
	return null;
}
set {
	;
}
	}
}",
                               @"class Test
{
	Test this [int a] {
		get {
			return null;
		}
		set {
			;
		}
	}
}");

            policy.IndentPropertyBody = false;
            Continue(policy, adapter,
                     @"class Test
{
	Test this [int a] {
	get {
		return null;
	}
	set {
		;
	}
	}
}");
        }
Esempio n. 28
0
        public void TestIndentEventBody()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.IndentEventBody = true;

            var adapter = Test(policy,
                               @"class Test
{
	public event EventHandler TestMe {
								add {
							;
						}
remove {
	;
}
	}
}",
                               @"class Test
{
	public event EventHandler TestMe {
		add {
			;
		}
		remove {
			;
		}
	}
}");

            policy.IndentEventBody = false;
            Continue(policy, adapter,
                     @"class Test
{
	public event EventHandler TestMe {
	add {
		;
	}
	remove {
		;
	}
	}
}");
        }
Esempio n. 29
0
        public static CSharpFormattingOptions LoadFormattingProfile(System.IO.Stream input)
        {
            CSharpFormattingOptions result = FormattingOptionsFactory.CreateMono();

            result.Name = "noname";
            using (XmlTextReader reader = new XmlTextReader(input)) {
                reader.ReadToFollowing("Options");
                reader.ReadToDescendant("FormattingProfile");
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.LocalName == "Property")
                        {
                            var    info      = typeof(CSharpFormattingOptions).GetProperty(reader.GetAttribute("name"));
                            string valString = reader.GetAttribute("value");
                            object value;
                            if (info.PropertyType == typeof(bool))
                            {
                                value = Boolean.Parse(valString);
                            }
                            else if (info.PropertyType == typeof(int))
                            {
                                value = Int32.Parse(valString);
                            }
                            else
                            {
                                value = Enum.Parse(info.PropertyType, valString);
                            }
                            info.SetValue(result, value, null);
                        }
                        else if (reader.LocalName == "FormattingProfile")
                        {
                            result.Name = reader.GetAttribute("name");
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "FormattingProfile")
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
Esempio n. 30
0
        public void TestBug415469()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            TestStatementFormatting(policy,
                                    @"switch (condition) {
case CONDITION1:
return foo != null ? foo.Bar : null;
case CONDITION2:
string goo = foo != null ? foo.Bar : null;
return ""Should be indented like this"";
}", @"switch (condition) {
case CONDITION1:
	return foo != null ? foo.Bar : null;
case CONDITION2:
	string goo = foo != null ? foo.Bar : null;
	return ""Should be indented like this"";
}");
        }