Преглед изворни кода

* CodeGeneratorFromStatementTest.cs: Added tests for
CodeAssignStatement, CodeAttachEventStatement,
CodeConditionStatement, CodeExpressionStatement,
CodeIterationStatement, CodeLabeledStatement,
CodeMethodReturnStatement, CodeRemoveEventStatement,
CodeSnippetStatement, CodeStatement, CodeVariableDeclarationStatement.
* CodeRemoveEventStatementTest.cs: Added tests for ctors.
* IndentedTextWriterTest.cs: Added tests for Indent property.
* CodeGeneratorFromStatementTest.cs: Added tests for
CodeAssignStatement, CodeAttachEventStatement, CodeConditionStatement,
CodeExpressionStatement, CodeIterationStatement,
CodeLabeledStatement, CodeMethodReturnStatement,
CodeRemoveEventStatement and CodeSnippetStatement.
* CSharpCodeGenerator.cs: No longer output semicolon and newline for
CodeVariableDeclarationStatement in for statement, fixes #75292.
Fixed NRE in GenerateEventReferenceExpression. Cosmetic changes to
code generated for iteration to match MS.NET. Temporary reduce
indentation for label and no longer escape label if its a keyword.
* CodeRemoveEventStatement.cs: Event returns new CodeEventReference
if underlying value is null.
* System_test.dll.sources: Added CodeRemoveEventStatementTest.cs from
System.CodeDom.
* CodeGenerator.cs: Corrected line endings. Set eol-style to native.
* IndentedTextWriter.cs: Indent can no longer become negative.
* VBCodeGenerator.cs: Fixed NRE in GenerateEventReferenceExpression,
and escape event name. Indent statements for iteration. Avoid
ArgumentNullException if expression is not set for CodeReturnStatement.
Temporary reduce indentation for label, and fixed ArgumentNullException
if no statement is set. Cosmetic changes to code generated for
condition to match MS.NET. In OutputTypeNamePair, escape name.

svn path=/trunk/mcs/; revision=53703

Gert Driesen пре 20 година
родитељ
комит
e4e516d410

+ 5 - 0
mcs/class/System/ChangeLog

@@ -1,3 +1,8 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* System_test.dll.sources: Added CodeRemoveEventStatementTest.cs from
+	System.CodeDom.
+
 2005-11-26  Gert Driesen  <[email protected]>
 
 	* System_test.dll.sources: Added CodeGeneratorFromStatementTest.cs

+ 16 - 8
mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs

@@ -261,8 +261,10 @@ namespace Mono.CSharp
 
 		protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression expression)
 		{
-			GenerateExpression (expression.TargetObject);
-			Output.Write ('.');
+			if (expression.TargetObject != null) {
+				GenerateExpression (expression.TargetObject);
+				Output.Write ('.');
+			}
 			Output.Write (GetSafeName (expression.EventName));
 		}
 
@@ -322,7 +324,7 @@ namespace Mono.CSharp
 			GenerateExpression (statement.TestExpression);
 			output.Write ("; ");
 			GenerateStatement (statement.IncrementStatement);
-			output.Write (") ");
+			output.Write (")");
 			dont_write_semicolon = false;
 			OutputStartBrace ();
 			++Indent;
@@ -404,7 +406,7 @@ namespace Mono.CSharp
 					output.Write (' ');
 				else
 					output.WriteLine ();
-				output.WriteLine ("else");
+				output.Write ("else");
 				OutputStartBrace ();
 				++Indent;
 				GenerateStatements (falses);
@@ -481,7 +483,7 @@ namespace Mono.CSharp
 		{
 			TextWriter output = Output;
 			GenerateEventReferenceExpression (statement.Event);
-			Output.Write (" -= ");
+			output.Write (" -= ");
 			GenerateExpression (statement.Listener);
 			output.WriteLine (';');
 		}
@@ -497,10 +499,14 @@ namespace Mono.CSharp
 		
 		protected override void GenerateLabeledStatement (CodeLabeledStatement statement)
 		{
-			Output.Write (String.Concat (GetSafeName (statement.Label), ": "));
+			Indent--;
+			Output.Write (statement.Label);
+			Output.WriteLine (":");
+			Indent++;
 
-			if (statement.Statement != null)
+			if (statement.Statement != null) {
 				GenerateStatement (statement.Statement);
+			}
 		}
 
 		protected override void GenerateVariableDeclarationStatement (CodeVariableDeclarationStatement statement)
@@ -515,7 +521,9 @@ namespace Mono.CSharp
 				GenerateExpression (initExpression);
 			}
 
-			output.WriteLine (';');
+			if (!dont_write_semicolon) {
+				output.WriteLine (';');
+			}
 		}
 
 		protected override void GenerateLinePragmaStart (CodeLinePragma linePragma)

+ 8 - 0
mcs/class/System/Microsoft.CSharp/ChangeLog

@@ -1,3 +1,11 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* CSharpCodeGenerator.cs: No longer output semicolon and newline for
+	CodeVariableDeclarationStatement in for statement, fixes #75292. 
+	Fixed NRE in GenerateEventReferenceExpression. Cosmetic changes to 
+	code generated for iteration to match MS.NET. Temporary reduce 
+	indentation for label and no longer escape label if its a keyword.
+
 2005-11-26  Gert Driesen  <[email protected]>
 
 	* CSharpCodeGenerator.cs: Fixed GenerateComment to also write

+ 9 - 0
mcs/class/System/Microsoft.VisualBasic/ChangeLog

@@ -1,3 +1,12 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* VBCodeGenerator.cs: Fixed NRE in GenerateEventReferenceExpression,
+	and escape event name. Indent statements for iteration. Avoid
+	ArgumentNullException if expression is not set for CodeReturnStatement.
+	Temporary reduce indentation for label, and fixed ArgumentNullException
+	if no statement is set. Cosmetic changes to code generated for 
+	condition to match MS.NET. In OutputTypeNamePair, escape name.
+
 2005-11-26  Gert Driesen  <[email protected]>
 
 	* VBCodeGenerator.cs: Fixed NullReferenceException if no ToThrow

+ 23 - 11
mcs/class/System/Microsoft.VisualBasic/VBCodeGenerator.cs

@@ -288,9 +288,11 @@ namespace Microsoft.VisualBasic
 
 		protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression expression)
 		{
-			GenerateExpression (expression.TargetObject);
-			Output.Write ('.');
-			Output.Write (expression.EventName);
+			if (expression.TargetObject != null) {
+				GenerateExpression (expression.TargetObject);
+				Output.Write ('.');
+			}
+			Output.Write (CreateEscapedIdentifier(expression.EventName));
 		}
 
 		protected override void GenerateDelegateInvokeExpression (CodeDelegateInvokeExpression expression)
@@ -376,8 +378,10 @@ namespace Microsoft.VisualBasic
 			output.Write ("Do While ");
 			GenerateExpression (statement.TestExpression);
 			output.WriteLine ();
+			Indent++;
 			GenerateStatements (statement.Statements);
 			GenerateStatement (statement.IncrementStatement);
+			Indent--;
 			output.WriteLine ("Loop");
 		}
 
@@ -424,19 +428,23 @@ namespace Microsoft.VisualBasic
 		{
 			TextWriter output = Output;
 
-			output.Write ("Return ");
-			GenerateExpression (statement.Expression);
-			output.WriteLine ();
+			if (statement.Expression != null) {
+				output.Write ("Return ");
+				GenerateExpression (statement.Expression);
+				output.WriteLine ();
+			} else {
+				output.WriteLine ("Return");
+			}
 		}
 
 		protected override void GenerateConditionStatement (CodeConditionStatement statement)
 		{
 			TextWriter output = Output;
-			output.Write ("If (");
+			output.Write ("If ");
 
 			GenerateExpression (statement.Condition);
 
-			output.WriteLine (") Then");
+			output.WriteLine (" Then");
 			++Indent;
 			GenerateStatements (statement.TrueStatements);
 			--Indent;
@@ -529,8 +537,12 @@ namespace Microsoft.VisualBasic
 		{
 			TextWriter output = Output;
 
-			output.Write (statement.Label + ":");
-			GenerateStatement (statement.Statement);
+			Indent--;
+			output.WriteLine (statement.Label + ":");
+			Indent++;
+			if (statement.Statement != null) {
+				GenerateStatement (statement.Statement);
+			}
 		}
 
 		protected override void GenerateTypeOfExpression (CodeTypeOfExpression e)
@@ -1322,7 +1334,7 @@ namespace Microsoft.VisualBasic
 				name = "__exception";
 			}
 #endif
-			Output.Write (name + " As " + GetTypeOutput (typeRef));
+			Output.Write (CreateEscapedIdentifier(name) + " As " + GetTypeOutput (typeRef));
 		}
 
 		protected override void OutputType (CodeTypeReference type)

+ 5 - 0
mcs/class/System/System.CodeDom.Compiler/ChangeLog

@@ -1,3 +1,8 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* CodeGenerator.cs: Corrected line endings. Set eol-style to native.
+	* IndentedTextWriter.cs: Indent can no longer become negative.
+
 2005-11-04  Sebastien Pouliot  <[email protected]> 
 
 	* CodeCompiler.cs: Compile now use the Executor class (instead of the

+ 9 - 9
mcs/class/System/System.CodeDom.Compiler/CodeGenerator.cs

@@ -601,16 +601,16 @@ namespace System.CodeDom.Compiler {
 				handled = true;
 			}
 			CodeSnippetStatement snippet = s as CodeSnippetStatement;
-			if (snippet != null) {
-#if NET_2_0
-				int indent = Indent;
-				try {
-					Indent = 0;
-					GenerateSnippetStatement (snippet);
-				} finally {
-					Indent = indent;
+			if (snippet != null) {
+#if NET_2_0
+				int indent = Indent;
+				try {
+					Indent = 0;
+					GenerateSnippetStatement (snippet);
+				} finally {
+					Indent = indent;
 				}
-#else
+#else
 				GenerateSnippetStatement (snippet);
 #endif
 				handled = true;

+ 3 - 0
mcs/class/System/System.CodeDom.Compiler/IndentedTextWriter.cs

@@ -80,6 +80,9 @@ namespace System.CodeDom.Compiler {
 				return indent;
 			}
 			set {
+				if (value < 0) {
+					value = 0;
+				}
 				indent = value;
 			}
 		}

+ 5 - 0
mcs/class/System/System.CodeDom/ChangeLog

@@ -1,3 +1,8 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* CodeRemoveEventStatement.cs: Event returns new CodeEventReference
+	if underlying value is null.
+
 2005-11-20  Gert Driesen  <[email protected]>
 
 	* CodeParameterDeclarationExpressionCollection.cs: Use CollectionBase

+ 3 - 1
mcs/class/System/System.CodeDom/CodeRemoveEventStatement.cs

@@ -45,7 +45,6 @@ namespace System.CodeDom
 		//
 		public CodeRemoveEventStatement ()
 		{
-			eventRef = new CodeEventReferenceExpression (null, String.Empty);
 		}
 
 		public CodeRemoveEventStatement (CodeEventReferenceExpression eventRef,
@@ -69,6 +68,9 @@ namespace System.CodeDom
 		//
 		public CodeEventReferenceExpression Event {
 			get {
+				if (eventRef == null) {
+					eventRef = new CodeEventReferenceExpression ();
+				}
 				return eventRef;
 			}
 			set {

+ 1 - 0
mcs/class/System/System_test.dll.sources

@@ -64,6 +64,7 @@ System.CodeDom/CodeParameterDeclarationExpressionTest.cs
 System.CodeDom/CodeParameterDeclarationExpressionCollectionTest.cs
 System.CodeDom/CodePropertyReferenceExpressionTest.cs
 System.CodeDom/CodeRegionDirectiveTest.cs
+System.CodeDom/CodeRemoveEventStatementTest.cs
 System.CodeDom/CodeSnippetCompileUnitTest.cs
 System.CodeDom/CodeSnippetExpressionTest.cs
 System.CodeDom/CodeSnippetStatementTest.cs

+ 9 - 0
mcs/class/System/Test/Microsoft.CSharp/ChangeLog

@@ -1,3 +1,12 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* CodeGeneratorFromStatementTest.cs: Added tests for 
+	CodeAssignStatement, CodeAttachEventStatement, 
+	CodeConditionStatement, CodeExpressionStatement,
+	CodeIterationStatement, CodeLabeledStatement,
+	CodeMethodReturnStatement, CodeRemoveEventStatement,
+	CodeSnippetStatement, CodeStatement, CodeVariableDeclarationStatement.
+
 2005-11-26  Gert Driesen  <[email protected]>
 
 	* CodeGeneratorFromExpressionTest.cs: Added test for 

+ 447 - 34
mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromStatementTest.cs

@@ -58,6 +58,81 @@ namespace MonoTests.Microsoft.CSharp
 			Generate ();
 		}
 
+		[Test]
+		public void CodeAssignStatementTest ()
+		{
+			CodeSnippetExpression cse1 = new CodeSnippetExpression("A");
+			CodeSnippetExpression cse2 = new CodeSnippetExpression("B");
+
+			CodeAssignStatement assignStatement = new CodeAssignStatement (cse1, cse2);
+			statement = assignStatement;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"A = B;{0}", NewLine), Generate (), "#1");
+
+			assignStatement.Left = null;
+			try {
+				Generate ();
+				Assert.Fail ("#2");
+			} catch (ArgumentNullException) {
+			}
+
+			assignStatement.Left = cse1;
+			Generate ();
+
+			assignStatement.Right = null;
+			try {
+				Generate ();
+				Assert.Fail ("#3");
+			} catch (ArgumentNullException) {
+			}
+
+			assignStatement.Right = cse2;
+			Generate ();
+		}
+
+		[Test]
+		public void CodeAttachEventStatementTest ()
+		{
+			CodeEventReferenceExpression cere = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ("A"), "class");
+			CodeSnippetExpression handler = new CodeSnippetExpression ("EventHandler");
+
+			CodeAttachEventStatement attachEventStatement = new CodeAttachEventStatement ();
+			statement = attachEventStatement;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			attachEventStatement.Event = cere;
+			try {
+				Generate ();
+				Assert.Fail ("#2");
+			} catch (ArgumentNullException) {
+			}
+
+			attachEventStatement.Event = null;
+			attachEventStatement.Listener = handler;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				" += EventHandler;{0}", NewLine), Generate (), "#3");
+
+			attachEventStatement.Event = cere;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"A.@class += EventHandler;{0}", NewLine), Generate (), "#4");
+
+			attachEventStatement.Event = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ((string) null), "");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				". += EventHandler;{0}", NewLine), Generate (), "#5");
+
+			attachEventStatement.Listener = new CodeSnippetExpression ("");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				". += ;{0}", NewLine), Generate (), "#6");
+		}
+
 		[Test]
 		public void CodeCommentStatementTest ()
 		{
@@ -80,25 +155,171 @@ namespace MonoTests.Microsoft.CSharp
 			comment.Text = "a\rb";
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"// a\r//b{0}", NewLine), Generate (), "#4");
-
 		}
 
 		[Test]
-		public void ThrowExceptionStatementTest ()
+		public void CodeConditionStatementTest ()
 		{
-			CodeThrowExceptionStatement ctet = new CodeThrowExceptionStatement ();
-			statement = ctet;
+			CodeStatement[] trueStatements = new CodeStatement[] {
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoA()")),
+				new CodeExpressionStatement (new CodeSnippetExpression (";")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoB()")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("")),
+				new CodeSnippetStatement ("A"),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoC()")) };
+
+			CodeStatement[] falseStatements = new CodeStatement[] {
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoD()")),
+				new CodeSnippetStatement ("B"),
+				new CodeExpressionStatement (new CodeSnippetExpression (";")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoE()")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoF()")) };
+
+			CodeConditionStatement conditionStatement = new CodeConditionStatement ();
+			statement = conditionStatement;
 
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			conditionStatement.Condition = new CodeSnippetExpression ("");
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"throw;{0}", NewLine), Generate (), "#1");
+				"if () {{{0}" +
+				"}}{0}", NewLine), Generate (), "#2");
 
-			ctet.ToThrow = new CodeSnippetExpression ("whatever");
+			conditionStatement.Condition = new CodeSnippetExpression ("true == false");
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"throw whatever;{0}", NewLine), Generate (), "#2");
+				"if (true == false) {{{0}" +
+				"}}{0}", NewLine), Generate (), "#3");
+
+			conditionStatement.TrueStatements.AddRange (trueStatements);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"if (true == false) {{{0}" +
+				"    DoA();{0}" +
+				"    ;;{0}" +
+				"    DoB();{0}" +
+				"    ;{0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC();{0}" +
+				"}}{0}", NewLine), Generate (), "#3");
+
+			conditionStatement.FalseStatements.AddRange (falseStatements);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"if (true == false) {{{0}" +
+				"    DoA();{0}" +
+				"    ;;{0}" +
+				"    DoB();{0}" +
+				"    ;{0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC();{0}" +
+				"}}{0}" +
+				"else {{{0}" +
+				"    DoD();{0}" +
+#if NET_2_0
+				"B{0}" +
+#else
+				"    B{0}" +
+#endif
+				"    ;;{0}" +
+				"    DoE();{0}" +
+				"    ;{0}" +
+				"    DoF();{0}" +
+				"}}{0}", NewLine), Generate (), "#4");
+
+			options.ElseOnClosing = true;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"if (true == false) {{{0}" +
+				"    DoA();{0}" +
+				"    ;;{0}" +
+				"    DoB();{0}" +
+				"    ;{0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC();{0}" +
+				"}} else {{{0}" +
+				"    DoD();{0}" +
+#if NET_2_0
+				"B{0}" +
+#else
+				"    B{0}" +
+#endif
+				"    ;;{0}" +
+				"    DoE();{0}" +
+				"    ;{0}" +
+				"    DoF();{0}" +
+				"}}{0}", NewLine), Generate (), "#5");
+
+			options.ElseOnClosing = false;
+
+			conditionStatement.TrueStatements.Clear ();
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"if (true == false) {{{0}" +
+				"}}{0}" +
+				"else {{{0}" +
+				"    DoD();{0}" +
+#if NET_2_0
+				"B{0}" +
+#else
+				"    B{0}" +
+#endif
+				"    ;;{0}" +
+				"    DoE();{0}" +
+				"    ;{0}" +
+				"    DoF();{0}" +
+				"}}{0}", NewLine), Generate (), "#6");
+
+			conditionStatement.TrueStatements.AddRange (trueStatements);
+			conditionStatement.FalseStatements.Clear ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"if (true == false) {{{0}" +
+				"    DoA();{0}" +
+				"    ;;{0}" +
+				"    DoB();{0}" +
+				"    ;{0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC();{0}" +
+				"}}{0}", NewLine), Generate (), "#7");
+		}
+
+		[Test]
+		public void CodeExpressionStatementTest ()
+		{
+			CodeExpressionStatement ces = new CodeExpressionStatement ();
+			statement = ces;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			ces.Expression = new CodeSnippetExpression ("something");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"something;{0}", NewLine), Generate (), "#2");
 		}
 
 		[Test]
-		public void GotoStatementTest ()
+		public void CodeGotoStatementTest ()
 		{
 			statement = new CodeGotoStatement ("something");
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
@@ -106,7 +327,198 @@ namespace MonoTests.Microsoft.CSharp
 		}
 
 		[Test]
-		public void TryCatchFinallyStatementTest ()
+		public void CodeIterationStatementTest ()
+		{
+			CodeIterationStatement cis = new CodeIterationStatement ();
+			statement = cis;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1: null InitStatement should cause NRE");
+			} catch (NullReferenceException) {
+			}
+
+			cis.InitStatement = new CodeVariableDeclarationStatement (typeof(int),
+				"testInt", new CodePrimitiveExpression(1));
+			try {
+				Generate ();
+				Assert.Fail ("#2: null TestExpression should cause ArgumentNullException");
+			} catch (ArgumentNullException) {
+			}
+
+			cis.TestExpression = new CodeBinaryOperatorExpression (
+				new CodeVariableReferenceExpression ("testInt"),
+				CodeBinaryOperatorType.LessThan, 
+				new CodePrimitiveExpression (10));
+			try {
+				Generate ();
+				Assert.Fail ("#3: null IncrementStatement should cause NRE");
+			} catch (NullReferenceException) {
+			}
+
+			cis.IncrementStatement = new CodeAssignStatement (
+				new CodeVariableReferenceExpression ("testInt"),
+				new CodeBinaryOperatorExpression (
+					new CodeVariableReferenceExpression ("testInt"),
+					CodeBinaryOperatorType.Add,
+					new CodePrimitiveExpression (1)));
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"for (int testInt = 1; (testInt < 10); testInt = (testInt + 1)) {{{0}" +
+				"}}{0}", NewLine), Generate (), "#4");
+
+			cis.Statements.AddRange (new CodeStatement[] {
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoA()")),
+				new CodeExpressionStatement (new CodeSnippetExpression (";")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoB()")),
+				new CodeLabeledStatement ("test", new CodeSnippetStatement ("C")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("")),
+				new CodeSnippetStatement ("A"),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoC()")) });
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"for (int testInt = 1; (testInt < 10); testInt = (testInt + 1)) {{{0}" +
+				"    DoA();{0}" +
+				"    ;;{0}" +
+				"    DoB();{0}" +
+				"test:{0}" +
+#if NET_2_0
+				"C{0}" +
+#else
+				"    C{0}" +
+#endif
+				"    ;{0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC();{0}" +
+				"}}{0}", NewLine), Generate (), "#5");
+		}
+
+		[Test]
+		public void CodeLabeledStatementTest ()
+		{
+			CodeLabeledStatement cls = new CodeLabeledStatement ();
+			statement = cls;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				":{0}", NewLine), Generate (), "#1");
+
+			cls.Label = "class";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"class:{0}", NewLine), Generate (), "#2");
+
+			cls.Statement = new CodeSnippetStatement ("A");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"class:{0}" +
+#if NET_2_0
+				"A{0}",
+#else
+				"    A{0}",
+#endif
+				NewLine), Generate (), "#3");
+		}
+
+		[Test]
+		public void CodeMethodReturnStatementTest ()
+		{
+			CodeMethodReturnStatement cmrs = new CodeMethodReturnStatement ();
+			statement = cmrs;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"return;{0}", NewLine), Generate (), "#1");
+
+			cmrs.Expression = new CodePrimitiveExpression (1);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"return 1;{0}", NewLine), Generate (), "#2");
+		}
+
+		[Test]
+		public void CodeRemoveEventStatementTest ()
+		{
+			CodeEventReferenceExpression cere = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ("A"), "class");
+			CodeSnippetExpression handler = new CodeSnippetExpression ("EventHandler");
+
+			CodeRemoveEventStatement cres = new CodeRemoveEventStatement ();
+			statement = cres;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			cres.Event = cere;
+			try {
+				Generate ();
+				Assert.Fail ("#2");
+			} catch (ArgumentNullException) {
+			}
+
+			cres.Event = null;
+			cres.Listener = handler;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				" -= EventHandler;{0}", NewLine), Generate (), "#3");
+
+			cres.Event = cere;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"A.@class -= EventHandler;{0}", NewLine), Generate (), "#4");
+
+			cres.Event = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ((string) null), "");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				". -= EventHandler;{0}", NewLine), Generate (), "#5");
+
+			cres.Listener = new CodeSnippetExpression ("");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				". -= ;{0}", NewLine), Generate (), "#6");
+		}
+
+		[Test]
+		public void CodeSnippetStatementTest ()
+		{
+			CodeSnippetStatement css = new CodeSnippetStatement ();
+			statement = css;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"{0}", NewLine), Generate (), "#1");
+
+			css.Value = "class";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"class{0}", NewLine), Generate (), "#2");
+
+			css.Value = null;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"{0}", NewLine), Generate (), "#3");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void CodeStatement ()
+		{
+			CodeStatement cs = new CodeStatement ();
+			statement = cs;
+
+			Generate ();
+		}
+
+		[Test]
+		public void CodeThrowExceptionStatementTest ()
+		{
+			CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement ();
+			statement = ctes;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"throw;{0}", NewLine), Generate (), "#1");
+
+			ctes.ToThrow = new CodeSnippetExpression ("whatever");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"throw whatever;{0}", NewLine), Generate (), "#2");
+		}
+
+		[Test]
+		public void CodeTryCatchFinallyStatementTest ()
 		{
 			CodeStatement cs = new CodeGotoStatement ("exit");
 			CodeCatchClause ccc1 = new CodeCatchClause ("ex1", new CodeTypeReference ("System.ArgumentException"));
@@ -163,36 +575,37 @@ namespace MonoTests.Microsoft.CSharp
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"try {{{0}" +
 				"}}{0}", NewLine), Generate (), "#4");
-
 		}
-		
-		/*
-		System.Object
-		   System.CodeDom.CodeObject
-		      System.CodeDom.CodeStatement
-			 System.CodeDom.CodeAssignStatement
-			 System.CodeDom.CodeAttachEventStatement
-			 System.CodeDom.CodeConditionStatement
-			 System.CodeDom.CodeExpressionStatement
-			 System.CodeDom.CodeIterationStatement
-			 System.CodeDom.CodeLabeledStatement
-			 System.CodeDom.CodeMethodReturnStatement
-			 System.CodeDom.CodeRemoveEventStatement
-			 System.CodeDom.CodeSnippetStatement
-			 System.CodeDom.CodeVariableDeclarationStatement
-
-		*/
 
-		
-		/*
 		[Test]
-		public void ReferencedTest ()
+		public void CodeVariableDeclarationStatementTest ()
 		{
-			codeUnit.ReferencedAssemblies.Add ("System.dll");
-			Generate ();
-			Assertion.AssertEquals ("", Code);
+			CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement ();
+			statement = cvds;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"void ;{0}", NewLine), Generate (), "#1");
+
+			cvds.Name = "class";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"void @class;{0}", NewLine), Generate (), "#2");
+
+			cvds.Name = "A";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"void A;{0}", NewLine), Generate (), "#3");
+
+			cvds.Type = new CodeTypeReference (typeof (int));
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"int A;{0}", NewLine), Generate (), "#4");
+
+			cvds.InitExpression = new CodePrimitiveExpression (25);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"int A = 25;{0}", NewLine), Generate (), "#5");
+
+			cvds.Name = null;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"int  = 25;{0}", NewLine), Generate (), "#5");
 		}
-		*/
 	}
 }
 

+ 8 - 0
mcs/class/System/Test/Microsoft.VisualBasic/ChangeLog

@@ -1,3 +1,11 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* CodeGeneratorFromStatementTest.cs: Added tests for
+	CodeAssignStatement, CodeAttachEventStatement, CodeConditionStatement,
+	CodeExpressionStatement, CodeIterationStatement,
+	CodeLabeledStatement, CodeMethodReturnStatement, 
+	CodeRemoveEventStatement and CodeSnippetStatement.
+
 2005-11-26  Gert Driesen  <[email protected]>
 
 	* CodeGeneratorTestBase.cs: Removed Code property, added Generate 

+ 444 - 36
mcs/class/System/Test/Microsoft.VisualBasic/CodeGeneratorFromStatementTest.cs

@@ -58,6 +58,81 @@ namespace MonoTests.Microsoft.VisualBasic
 			Generate ();
 		}
 
+		[Test]
+		public void CodeAssignStatementTest ()
+		{
+			CodeSnippetExpression cse1 = new CodeSnippetExpression ("A");
+			CodeSnippetExpression cse2 = new CodeSnippetExpression ("B");
+
+			CodeAssignStatement assignStatement = new CodeAssignStatement (cse1, cse2);
+			statement = assignStatement;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"A = B{0}", NewLine), Generate (), "#1");
+
+			assignStatement.Left = null;
+			try {
+				Generate ();
+				Assert.Fail ("#2");
+			} catch (ArgumentNullException) {
+			}
+
+			assignStatement.Left = cse1;
+			Generate ();
+
+			assignStatement.Right = null;
+			try {
+				Generate ();
+				Assert.Fail ("#3");
+			} catch (ArgumentNullException) {
+			}
+
+			assignStatement.Right = cse2;
+			Generate ();
+		}
+
+		[Test]
+		public void CodeAttachEventStatementTest ()
+		{
+			CodeEventReferenceExpression cere = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ("A"), "class");
+			CodeSnippetExpression handler = new CodeSnippetExpression ("EventHandler");
+
+			CodeAttachEventStatement attachEventStatement = new CodeAttachEventStatement ();
+			statement = attachEventStatement;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			attachEventStatement.Event = cere;
+			try {
+				Generate ();
+				Assert.Fail ("#2");
+			} catch (ArgumentNullException) {
+			}
+
+			attachEventStatement.Event = null;
+			attachEventStatement.Listener = handler;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"AddHandler , EventHandler{0}", NewLine), Generate (), "#3");
+
+			attachEventStatement.Event = cere;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"AddHandler A.[class], EventHandler{0}", NewLine), Generate (), "#4");
+
+			attachEventStatement.Event = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ((string) null), "");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"AddHandler ., EventHandler{0}", NewLine), Generate (), "#5");
+
+			attachEventStatement.Listener = new CodeSnippetExpression ("");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"AddHandler ., {0}", NewLine), Generate (), "#6");
+		}
+
 		[Test]
 		public void CodeCommentStatementTest ()
 		{
@@ -83,20 +158,166 @@ namespace MonoTests.Microsoft.VisualBasic
 		}
 
 		[Test]
-		public void ThrowExceptionStatementTest ()
+		public void CodeConditionStatementTest ()
 		{
-			CodeThrowExceptionStatement ctet = new CodeThrowExceptionStatement ();
-			statement = ctet;
+			CodeStatement[] trueStatements = new CodeStatement[] {
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoA()")),
+				new CodeExpressionStatement (new CodeSnippetExpression (";")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoB()")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("")),
+				new CodeSnippetStatement ("A"),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoC()")) };
+
+			CodeStatement[] falseStatements = new CodeStatement[] {
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoD()")),
+				new CodeSnippetStatement ("B"),
+				new CodeExpressionStatement (new CodeSnippetExpression (";")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoE()")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoF()")) };
+
+			CodeConditionStatement conditionStatement = new CodeConditionStatement ();
+			statement = conditionStatement;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			conditionStatement.Condition = new CodeSnippetExpression ("");
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"Throw{0}", NewLine), Generate (), "#1");
+				"If  Then{0}" +
+				"End If{0}", NewLine), Generate (), "#2");
 
-			ctet.ToThrow = new CodeSnippetExpression ("whatever");
+			conditionStatement.Condition = new CodeSnippetExpression ("true == false");
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"Throw whatever{0}", NewLine), Generate (), "#2");
+				"If true == false Then{0}" +
+				"End If{0}", NewLine), Generate (), "#3");
+
+			conditionStatement.TrueStatements.AddRange (trueStatements);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"If true == false Then{0}" +
+				"    DoA(){0}" +
+				"    ;{0}" +
+				"    DoB(){0}" +
+				"    {0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC(){0}" +
+				"End If{0}", NewLine), Generate (), "#3");
+
+			conditionStatement.FalseStatements.AddRange (falseStatements);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"If true == false Then{0}" +
+				"    DoA(){0}" +
+				"    ;{0}" +
+				"    DoB(){0}" +
+				"    {0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC(){0}" +
+				"Else{0}" +
+				"    DoD(){0}" +
+#if NET_2_0
+				"B{0}" +
+#else
+				"    B{0}" +
+#endif
+				"    ;{0}" +
+				"    DoE(){0}" +
+				"    {0}" +
+				"    DoF(){0}" +
+				"End If{0}", NewLine), Generate (), "#4");
+
+			options.ElseOnClosing = true;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"If true == false Then{0}" +
+				"    DoA(){0}" +
+				"    ;{0}" +
+				"    DoB(){0}" +
+				"    {0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC(){0}" +
+				"Else{0}" +
+				"    DoD(){0}" +
+#if NET_2_0
+				"B{0}" +
+#else
+				"    B{0}" +
+#endif
+				"    ;{0}" +
+				"    DoE(){0}" +
+				"    {0}" +
+				"    DoF(){0}" +
+				"End If{0}", NewLine), Generate (), "#5");
+
+			options.ElseOnClosing = false;
+
+			conditionStatement.TrueStatements.Clear ();
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"If true == false Then{0}" +
+				"Else{0}" +
+				"    DoD(){0}" +
+#if NET_2_0
+				"B{0}" +
+#else
+				"    B{0}" +
+#endif
+				"    ;{0}" +
+				"    DoE(){0}" +
+				"    {0}" +
+				"    DoF(){0}" +
+				"End If{0}", NewLine), Generate (), "#6");
+
+			conditionStatement.TrueStatements.AddRange (trueStatements);
+			conditionStatement.FalseStatements.Clear ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"If true == false Then{0}" +
+				"    DoA(){0}" +
+				"    ;{0}" +
+				"    DoB(){0}" +
+				"    {0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC(){0}" +
+				"End If{0}", NewLine), Generate (), "#7");
+		}
+
+		[Test]
+		public void CodeExpressionStatementTest ()
+		{
+			CodeExpressionStatement ces = new CodeExpressionStatement ();
+			statement = ces;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			ces.Expression = new CodeSnippetExpression ("something");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"something{0}", NewLine), Generate (), "#2");
 		}
 
 		[Test]
-		public void GotoStatementTest ()
+		public void CodeGotoStatementTest ()
 		{
 			statement = new CodeGotoStatement ("something");
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
@@ -104,7 +325,201 @@ namespace MonoTests.Microsoft.VisualBasic
 		}
 
 		[Test]
-		public void TryCatchFinallyStatementTest ()
+		public void CodeIterationStatementTest ()
+		{
+			CodeIterationStatement cis = new CodeIterationStatement ();
+			statement = cis;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1: null InitStatement should cause NRE");
+			} catch (NullReferenceException) {
+			}
+
+			cis.InitStatement = new CodeVariableDeclarationStatement (typeof (int),
+				"testInt", new CodePrimitiveExpression (1));
+			try {
+				Generate ();
+				Assert.Fail ("#2: null TestExpression should cause ArgumentNullException");
+			} catch (ArgumentNullException) {
+			}
+
+			cis.TestExpression = new CodeBinaryOperatorExpression (
+				new CodeVariableReferenceExpression ("testInt"),
+				CodeBinaryOperatorType.LessThan,
+				new CodePrimitiveExpression (10));
+			try {
+				Generate ();
+				Assert.Fail ("#3: null IncrementStatement should cause NRE");
+			} catch (NullReferenceException) {
+			}
+
+			cis.IncrementStatement = new CodeAssignStatement (
+				new CodeVariableReferenceExpression ("testInt"),
+				new CodeBinaryOperatorExpression (
+					new CodeVariableReferenceExpression ("testInt"),
+					CodeBinaryOperatorType.Add,
+					new CodePrimitiveExpression (1)));
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Dim testInt As Integer = 1{0}" +
+				"Do While (testInt < 10){0}" +
+				"    testInt = (testInt + 1){0}" +
+				"Loop{0}", NewLine), Generate (), "#4");
+
+			cis.Statements.AddRange (new CodeStatement[] {
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoA()")),
+				new CodeExpressionStatement (new CodeSnippetExpression (";")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoB()")),
+				new CodeLabeledStatement ("test", new CodeSnippetStatement ("C")),
+				new CodeExpressionStatement (new CodeSnippetExpression ("")),
+				new CodeSnippetStatement ("A"),
+				new CodeExpressionStatement (new CodeSnippetExpression ("DoC()")) });
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Dim testInt As Integer = 1{0}" +
+				"Do While (testInt < 10){0}" +
+				"    DoA(){0}" +
+				"    ;{0}" +
+				"    DoB(){0}" +
+				"test:{0}" +
+#if NET_2_0
+				"C{0}" +
+#else
+				"    C{0}" +
+#endif
+				"    {0}" +
+#if NET_2_0
+				"A{0}" +
+#else
+				"    A{0}" +
+#endif
+				"    DoC(){0}" +
+				"    testInt = (testInt + 1){0}" +
+				"Loop{0}", NewLine), Generate (), "#5");
+		}
+
+		[Test]
+		public void CodeLabeledStatementTest ()
+		{
+			CodeLabeledStatement cls = new CodeLabeledStatement ();
+			statement = cls;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				":{0}", NewLine), Generate (), "#1");
+
+			cls.Label = "class";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"class:{0}", NewLine), Generate (), "#2");
+
+			cls.Statement = new CodeSnippetStatement ("A");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"class:{0}" +
+#if NET_2_0
+				"A{0}",
+#else
+				"    A{0}",
+#endif
+				NewLine), Generate (), "#3");
+		}
+
+		[Test]
+		public void CodeMethodReturnStatementTest ()
+		{
+			CodeMethodReturnStatement cmrs = new CodeMethodReturnStatement ();
+			statement = cmrs;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Return{0}", NewLine), Generate (), "#1");
+
+			cmrs.Expression = new CodePrimitiveExpression (1);
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Return 1{0}", NewLine), Generate (), "#2");
+		}
+
+		[Test]
+		public void CodeRemoveEventStatementTest ()
+		{
+			CodeEventReferenceExpression cere = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ("A"), "class");
+			CodeSnippetExpression handler = new CodeSnippetExpression ("EventHandler");
+
+			CodeRemoveEventStatement cres = new CodeRemoveEventStatement ();
+			statement = cres;
+
+			try {
+				Generate ();
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException) {
+			}
+
+			cres.Event = cere;
+			try {
+				Generate ();
+				Assert.Fail ("#2");
+			} catch (ArgumentNullException) {
+			}
+
+			cres.Event = null;
+			cres.Listener = handler;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"RemoveHandler , EventHandler{0}", NewLine), Generate (), "#3");
+
+			cres.Event = cere;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"RemoveHandler A.[class], EventHandler{0}", NewLine), Generate (), "#4");
+
+			cres.Event = new CodeEventReferenceExpression (
+				new CodeSnippetExpression ((string) null), "");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"RemoveHandler ., EventHandler{0}", NewLine), Generate (), "#5");
+
+			cres.Listener = new CodeSnippetExpression ("");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"RemoveHandler ., {0}", NewLine), Generate (), "#6");
+		}
+
+		[Test]
+		public void CodeSnippetStatementTest ()
+		{
+			CodeSnippetStatement css = new CodeSnippetStatement ();
+			statement = css;
+
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"{0}", NewLine), Generate (), "#1");
+
+			css.Value = "class";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"class{0}", NewLine), Generate (), "#2");
+
+			css.Value = null;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"{0}", NewLine), Generate (), "#3");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void CodeStatement ()
+		{
+			CodeStatement cs = new CodeStatement ();
+			statement = cs;
+
+			Generate ();
+		}
+
+		[Test]
+		public void CodeThrowExceptionStatementTest ()
+		{
+			CodeThrowExceptionStatement ctet = new CodeThrowExceptionStatement ();
+			statement = ctet;
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Throw{0}", NewLine), Generate (), "#1");
+
+			ctet.ToThrow = new CodeSnippetExpression ("whatever");
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Throw whatever{0}", NewLine), Generate (), "#2");
+		}
+
+		[Test]
+		public void CodeTryCatchFinallyStatementTest ()
 		{
 			CodeStatement cs = new CodeGotoStatement ("exit");
 			CodeCatchClause ccc1 = new CodeCatchClause ("ex1", new CodeTypeReference ("System.ArgumentException"));
@@ -168,50 +583,43 @@ namespace MonoTests.Microsoft.VisualBasic
 		}
 
 		[Test]
-		public void VariableDeclarationStatementTest ()
+		public void CodeVariableDeclarationStatementTest ()
 		{
-			statement = new CodeVariableDeclarationStatement ();
-			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-#if NET_2_0
-				"Dim __exception As System.Void{0}",
-#else
-				"Dim  As System.Void{0}",
-#endif
-				NewLine), Generate (), "#1");
+			CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement ();
+			statement = cvds;
 
-			statement = new CodeVariableDeclarationStatement ((string) null,
-				(string) null);
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 #if NET_2_0
-				"Dim __exception As System.Void{0}",
+				"Dim __exception As System.Void{0}", 
 #else
-				"Dim  As System.Void{0}",
+				"Dim  As System.Void{0}", 
 #endif
 				NewLine), Generate (), "#1");
 
+			cvds.Name = "class";
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Dim [class] As System.Void{0}", NewLine), Generate (), "#2");
 
-			statement = new CodeVariableDeclarationStatement ("A", (string) null);
+			cvds.Name = "A";
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-#if NET_2_0
-				"Dim __exception As A{0}",
-#else
-				"Dim  As A{0}",
-#endif
-				NewLine), Generate (), "#1");
+				"Dim A As System.Void{0}", NewLine), Generate (), "#3");
 
-			statement = new CodeVariableDeclarationStatement ((string) null, "B");
+			cvds.Type = new CodeTypeReference (typeof (int));
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"Dim B As System.Void{0}", NewLine), Generate (), "#4");
+				"Dim A As Integer{0}", NewLine), Generate (), "#4");
 
-			statement = new CodeVariableDeclarationStatement ("A", "B");
+			cvds.InitExpression = new CodePrimitiveExpression (25);
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"Dim B As A{0}", NewLine), Generate (), "#5");
+				"Dim A As Integer = 25{0}", NewLine), Generate (), "#5");
 
-			CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement ("A", "B");
-			cvds.InitExpression = new CodeSnippetExpression ("C");
-			statement = cvds;
+			cvds.Name = null;
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-				"Dim B As A = C{0}", NewLine), Generate (), "#6");
+#if NET_2_0
+				"Dim __exception As Integer = 25{0}", 
+#else
+				"Dim  As Integer = 25{0}", 
+#endif
+				NewLine), Generate (), "#6");
 		}
 	}
 }

+ 4 - 0
mcs/class/System/Test/System.CodeDom.Compiler/ChangeLog

@@ -1,3 +1,7 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* IndentedTextWriterTest.cs: Added tests for Indent property.
+
 2005-11-30  Sebastien Pouliot  <[email protected]>
 
 	* CodeCompilerCas.cs: MS doesn't demand EnvironmentPermission under 

+ 17 - 1
mcs/class/System/Test/System.CodeDom.Compiler/IndentedTextWriterTest.cs

@@ -9,6 +9,7 @@
 //
 
 using System.CodeDom.Compiler;
+using System.IO;
 
 using NUnit.Framework;
 
@@ -22,6 +23,21 @@ namespace MonoTests.System.CodeDom.Compiler
 		{
 			Assert.AreEqual (new string (' ', 4), IndentedTextWriter.DefaultTabString);
 		}
+
+		[Test]
+		public void IndentTest ()
+		{
+			StringWriter sw = new StringWriter ();
+			IndentedTextWriter indentedTextWriter = new IndentedTextWriter (sw);
+			Assert.AreEqual (0, indentedTextWriter.Indent, "#1");
+			indentedTextWriter.Indent++;
+			Assert.AreEqual (1, indentedTextWriter.Indent, "#2");
+			indentedTextWriter.Indent = int.MaxValue;
+			Assert.AreEqual (int.MaxValue, indentedTextWriter.Indent, "#3");
+			indentedTextWriter.Indent = -1;
+			Assert.AreEqual (0, indentedTextWriter.Indent, "#4");
+			indentedTextWriter.Indent = int.MinValue;
+			Assert.AreEqual (0, indentedTextWriter.Indent, "#5");
+		}
 	}
 }
-

+ 4 - 0
mcs/class/System/Test/System.CodeDom/ChangeLog

@@ -1,3 +1,7 @@
+2005-11-30  Gert Driesen  <[email protected]>
+
+	* CodeRemoveEventStatementTest.cs: Added tests for ctors.
+
 2005-11-20  Gert Driesen  <[email protected]>
 
 	* CodeTypeParameterCollectionTest.cs: Improve coverage of AddRange 

+ 98 - 0
mcs/class/System/Test/System.CodeDom/CodeRemoveEventStatementTest.cs

@@ -0,0 +1,98 @@
+//
+// CodeRemoveEventStatementTest.cs
+//	- Unit tests for System.CodeDom.CodeRemoveEventStatement 
+//
+// Author:
+//	Gert Driesen  <[email protected]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.CodeDom;
+
+namespace MonoTests.System.CodeDom
+{
+	[TestFixture]
+	public class CodeRemoveEventStatementTest
+	{
+		[Test]
+		public void Constructor0 ()
+		{
+			CodeRemoveEventStatement caes = new CodeRemoveEventStatement ();
+			Assert.IsNotNull (caes.Event, "#1");
+			Assert.IsNull (caes.Listener, "#2");
+			Assert.AreEqual (string.Empty, caes.Event.EventName, "#3");
+			Assert.IsNull (caes.Event.TargetObject, "#4");
+		}
+
+		[Test]
+		public void Constructor1 ()
+		{
+			CodeEventReferenceExpression eventref = new CodeEventReferenceExpression ();
+			CodeExpression listener = new CodeExpression ();
+
+			CodeRemoveEventStatement caes = new CodeRemoveEventStatement (eventref, listener);
+			Assert.AreSame (eventref, caes.Event, "#1");
+			Assert.AreEqual (string.Empty, caes.Event.EventName, "#2");
+			Assert.IsNull (caes.Event.TargetObject, "#3");
+			Assert.AreSame (listener, caes.Listener, "#4");
+
+			caes.Event = null;
+			Assert.IsNotNull (caes.Event, "#5");
+			Assert.AreEqual (string.Empty, caes.Event.EventName, "#6");
+			Assert.IsNull (caes.Event.TargetObject, "#7");
+			Assert.AreSame (listener, caes.Listener, "#8");
+
+			caes.Listener = null;
+			Assert.IsNull (caes.Listener, "#9");
+
+			caes.Event = eventref;
+			Assert.AreSame (eventref, caes.Event, "#10");
+
+			caes.Listener = listener;
+			Assert.AreSame (listener, caes.Listener, "#11");
+
+			caes = new CodeRemoveEventStatement ((CodeEventReferenceExpression) null, (CodeExpression) null);
+			Assert.IsNotNull (caes.Event, "#12");
+			Assert.IsNull (caes.Listener, "#13");
+			Assert.AreEqual (string.Empty, caes.Event.EventName, "#14");
+			Assert.IsNull (caes.Event.TargetObject, "#15");
+		}
+
+		[Test]
+		public void Constructor2 ()
+		{
+			CodeExpression targetObject = new CodeExpression ();
+			CodeExpression listener = new CodeExpression ();
+
+			CodeRemoveEventStatement caes = new CodeRemoveEventStatement (targetObject, "mono", listener);
+			Assert.IsNotNull (caes.Event, "#1");
+			Assert.AreEqual ("mono", caes.Event.EventName, "#2");
+			Assert.AreSame (targetObject, caes.Event.TargetObject, "#3");
+			Assert.AreSame (listener, caes.Listener, "#4");
+
+		}
+	}
+}