Author: gert
Date: 2008-01-16 13:15:25 -0500 (Wed, 16 Jan 2008)
New Revision: 93075
Modified:
trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
trunk/mcs/class/System/Microsoft.CSharp/ChangeLog
trunk/mcs/class/System/Microsoft.VisualBasic/ChangeLog
trunk/mcs/class/System/Microsoft.VisualBasic/VBCodeGenerator.cs
trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromNamespaceTest.cs
trunk/mcs/class/System/Test/Microsoft.VisualBasic/ChangeLog
trunk/mcs/class/System/Test/Microsoft.VisualBasic/CodeGeneratorFromNamespaceTest.cs
Log:
* CodeGeneratorFromCompileUnitTest.cs: Avoid using "", and use
Assert instead of Assertion.
* CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
* CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
* CSharpCodeGenerator.cs: Cosmetic changes to the code emitted for
type constraints. Allows our unit tests to pass on both Mono and MS.
* VBCodeGenerator.cs: Implement support for type parameters.
Modified: trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
===================================================================
--- trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
2008-01-16 18:13:35 UTC (rev 93074)
+++ trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
2008-01-16 18:15:25 UTC (rev 93075)
@@ -1503,31 +1503,42 @@
if (count == 0)
return;
- ++Indent;
- foreach (CodeTypeParameter p in parameters) {
- if (p.Constraints.Count == 0 &&
!p.HasConstructorConstraint)
+ bool indented = false;
+
+ for (int i = 0; i < count; i++) {
+ CodeTypeParameter p = parameters [i];
+ bool hasConstraints = (p.Constraints.Count !=
0);
+ Output.WriteLine ();
+ if (!hasConstraints &&
!p.HasConstructorConstraint)
continue;
- Output.WriteLine ();
+
+ if (!indented) {
+ ++Indent;
+ indented = true;
+ }
+
Output.Write ("where ");
Output.Write (p.Name);
Output.Write (" : ");
- bool is_first = true;
- foreach (CodeTypeReference r in p.Constraints) {
- if (is_first)
- is_first = false;
- else
+ for (int j = 0; j < p.Constraints.Count; j++) {
+ if (j > 0)
Output.Write (", ");
- OutputType (r);
+ OutputType (p.Constraints [j]);
}
+
if (p.HasConstructorConstraint) {
- if (!is_first)
+ if (hasConstraints)
Output.Write (", ");
- Output.Write ("new ()");
+ Output.Write ("new");
+ if (hasConstraints)
+ Output.Write (" ");
+ Output.Write ("()");
}
+ }
- }
- --Indent;
+ if (indented)
+ --Indent;
}
string GetTypeArguments (CodeTypeReferenceCollection collection)
Modified: trunk/mcs/class/System/Microsoft.CSharp/ChangeLog
===================================================================
--- trunk/mcs/class/System/Microsoft.CSharp/ChangeLog 2008-01-16 18:13:35 UTC
(rev 93074)
+++ trunk/mcs/class/System/Microsoft.CSharp/ChangeLog 2008-01-16 18:15:25 UTC
(rev 93075)
@@ -1,3 +1,8 @@
+2008-01-16 Gert Driesen <[EMAIL PROTECTED]>
+
+ * CSharpCodeGenerator.cs: Cosmetic changes to the code emitted for
+ type constraints. Allows our unit tests to pass on both Mono and MS.
+
2008-01-16 Juraj Skripsky <[EMAIL PROTECTED]>
* CSharpCodeGenerator.cs (GenerateGenericsConstraints): Take
Modified: trunk/mcs/class/System/Microsoft.VisualBasic/ChangeLog
===================================================================
--- trunk/mcs/class/System/Microsoft.VisualBasic/ChangeLog 2008-01-16
18:13:35 UTC (rev 93074)
+++ trunk/mcs/class/System/Microsoft.VisualBasic/ChangeLog 2008-01-16
18:15:25 UTC (rev 93075)
@@ -1,3 +1,7 @@
+2008-01-16 Gert Driesen <[EMAIL PROTECTED]>
+
+ * VBCodeGenerator.cs: Implement support for type parameters.
+
2007-12-21 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* VBCodeGenerator.cs: Split array of keywords in two, one for 1.1 and
one
Modified: trunk/mcs/class/System/Microsoft.VisualBasic/VBCodeGenerator.cs
===================================================================
--- trunk/mcs/class/System/Microsoft.VisualBasic/VBCodeGenerator.cs
2008-01-16 18:13:35 UTC (rev 93074)
+++ trunk/mcs/class/System/Microsoft.VisualBasic/VBCodeGenerator.cs
2008-01-16 18:15:25 UTC (rev 93075)
@@ -814,6 +814,11 @@
output.Write ("Function ");
output.Write (GetMethodName(method));
+
+#if NET_2_0
+ OutputTypeParameters (method.TypeParameters);
+#endif
+
output.Write ('(');
OutputParameters (method.Parameters);
output.Write (')');
@@ -1020,6 +1025,9 @@
}
output.Write (CreateEscapedIdentifier
(delegateDecl.Name));
+#if NET_2_0
+ OutputTypeParameters
(delegateDecl.TypeParameters);
+#endif
output.Write ("(");
OutputParameters (delegateDecl.Parameters);
Output.Write (")");
@@ -1030,8 +1038,10 @@
Output.WriteLine ("");
} else {
OutputTypeAttributes (declaration);
-
output.Write (CreateEscapedIdentifier
(declaration.Name));
+#if NET_2_0
+ OutputTypeParameters
(declaration.TypeParameters);
+#endif
if (IsCurrentEnum) {
if (declaration.BaseTypes.Count > 0) {
@@ -1444,6 +1454,54 @@
}
}
+#if NET_2_0
+ void OutputTypeParameters (CodeTypeParameterCollection
parameters)
+ {
+ int count = parameters.Count;
+ if (count == 0)
+ return;
+
+ Output.Write ("(Of ");
+ for (int i = 0; i < count; ++i) {
+ if (i > 0)
+ Output.Write (", ");
+ CodeTypeParameter p = parameters [i];
+ Output.Write (p.Name);
+ OutputTypeParameterConstraints (p);
+ }
+ Output.Write (')');
+ }
+
+ void OutputTypeParameterConstraints (CodeTypeParameter
parameter)
+ {
+ int constraint_count = parameter.Constraints.Count +
+ (parameter.HasConstructorConstraint ? 1 : 0);
+
+ if (constraint_count == 0)
+ return;
+
+ Output.Write (" As ");
+
+ if (constraint_count > 1)
+ Output.Write (" {");
+
+ for (int i = 0; i < parameter.Constraints.Count; i++) {
+ if (i > 0)
+ Output.Write (", ");
+ OutputType (parameter.Constraints [i]);
+ }
+
+ if (parameter.HasConstructorConstraint) {
+ if (constraint_count > 1)
+ Output.Write (", ");
+ Output.Write ("New");
+ }
+
+ if (constraint_count > 1)
+ Output.Write ("}");
+ }
+#endif
+
protected override void OutputTypeNamePair (CodeTypeReference
typeRef, String name)
{
#if NET_2_0
Modified: trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog 2008-01-16
18:13:35 UTC (rev 93074)
+++ trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog 2008-01-16
18:15:25 UTC (rev 93075)
@@ -1,3 +1,9 @@
+2008-01-16 Gert Driesen <[EMAIL PROTECTED]>
+
+ * CodeGeneratorFromCompileUnitTest.cs: Avoid using "", and use
+ Assert instead of Assertion.
+ * CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
+
2007-12-21 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* CodeGeneratorFromTypeTest.cs: Added PartialTypeTest.
Modified:
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs
===================================================================
---
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs
2008-01-16 18:13:35 UTC (rev 93074)
+++
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs
2008-01-16 18:15:25 UTC (rev 93075)
@@ -24,8 +24,8 @@
[TestFixture]
public class CodeGeneratorFromCompileUnitTest : CodeGeneratorTestBase
{
- private string codeUnitHeader = "";
- private CodeCompileUnit codeUnit = null;
+ private string codeUnitHeader = string.Empty;
+ private CodeCompileUnit codeUnit;
public CodeGeneratorFromCompileUnitTest ()
{
@@ -53,7 +53,7 @@
[Test]
public void DefaultCodeUnitTest ()
{
- Assert.AreEqual ("", Generate ());
+ Assert.AreEqual (string.Empty, Generate ());
}
[Test]
@@ -68,7 +68,7 @@
public void ReferencedTest ()
{
codeUnit.ReferencedAssemblies.Add ("System.dll");
- Assertion.AssertEquals ("", Generate ());
+ Assert.AreEqual (string.Empty, Generate ());
}
[Test]
Modified:
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromNamespaceTest.cs
===================================================================
---
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromNamespaceTest.cs
2008-01-16 18:13:35 UTC (rev 93074)
+++
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromNamespaceTest.cs
2008-01-16 18:15:25 UTC (rev 93075)
@@ -24,7 +24,7 @@
[TestFixture]
public class CodeGeneratorFromNamespaceTest : CodeGeneratorTestBase
{
- CodeNamespace codeNamespace = null;
+ CodeNamespace codeNamespace;
[SetUp]
public void Init ()
@@ -168,5 +168,369 @@
" }}{0}" +
"}}{0}", NewLine), Generate (options), "#B2");
}
+
+#if NET_2_0
+ [Test]
+ public void Type_TypeParameters ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+ type.TypeParameters.Add (new CodeTypeParameter ("T"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T>{0}" +
+ " {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#1");
+
+ type.TypeParameters.Add (new CodeTypeParameter ("as"));
+ type.TypeParameters.Add (new CodeTypeParameter ("is"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T, as, is>{0}" +
+ " {0}" +
+ " {0}" +
+ " {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#2");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ type.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T, as, is, R>{0}" +
+ " {0}" +
+ " {0}" +
+ " {0}" +
+ " where R : System.IComparable {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#3");
+
+ type.TypeParameters.Add (new CodeTypeParameter ("S"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T, as, is, R,
S>{0}" +
+ " {0}" +
+ " {0}" +
+ " {0}" +
+ " where R : System.IComparable{0}" +
+ " {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#4");
+ }
+
+
+ [Test]
+ public void Type_TypeParameters_Constraints ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeTypeParameter typeParamT = new CodeTypeParameter
("T");
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ type.TypeParameters.Add (typeParamT);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T>{0}" +
+ " where T : System.IComparable {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#1");
+
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (ICloneable)));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T>{0}" +
+ " where T : System.IComparable,
System.ICloneable {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#2");
+
+ typeParamT.HasConstructorConstraint = true;
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T>{0}" +
+ " where T : System.IComparable,
System.ICloneable, new () {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#3");
+
+ CodeTypeParameter typeParamS = new CodeTypeParameter
("S");
+ typeParamS.Constraints.Add (new CodeTypeReference
(typeof (IDisposable)));
+ type.TypeParameters.Add (typeParamS);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T, S>{0}" +
+ " where T : System.IComparable,
System.ICloneable, new (){0}" +
+ " where S : System.IDisposable {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#4");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.HasConstructorConstraint = true;
+ type.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T, S, R>{0}" +
+ " where T : System.IComparable,
System.ICloneable, new (){0}" +
+ " where S : System.IDisposable{0}" +
+ " where R : new() {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#5");
+ }
+
+ [Test]
+ public void Type_TypeParameters_ConstructorConstraint ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeTypeParameter typeParam = new CodeTypeParameter
("T");
+ typeParam.HasConstructorConstraint = true;
+ type.TypeParameters.Add (typeParam);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass<T>{0}" +
+ " where T : new() {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate ());
+ }
+
+ [Test]
+ public void Method_TypeParameters ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "SomeMethod";
+ type.Members.Add (method);
+
+ method.TypeParameters.Add (new CodeTypeParameter ("T"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T>(){0}" +
+ " {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#1");
+
+ method.TypeParameters.Add (new CodeTypeParameter
("as"));
+ method.TypeParameters.Add (new CodeTypeParameter
("is"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T, as,
is>(){0}" +
+ " {0}" +
+ " {0}" +
+ " {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#2");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ method.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T, as, is,
R>(){0}" +
+ " {0}" +
+ " {0}" +
+ " {0}" +
+ " where R : System.IComparable
{{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#3");
+
+ method.TypeParameters.Add (new CodeTypeParameter ("S"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T, as, is, R,
S>(){0}" +
+ " {0}" +
+ " {0}" +
+ " {0}" +
+ " where R : System.IComparable{0}" +
+ " {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#4");
+ }
+
+ [Test]
+ public void Method_TypeParameters_Constraints ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "SomeMethod";
+ type.Members.Add (method);
+
+ CodeTypeParameter typeParamT = new CodeTypeParameter
("T");
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ method.TypeParameters.Add (typeParamT);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T>(){0}" +
+ " where T : System.IComparable
{{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#1");
+
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (ICloneable)));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T>(){0}" +
+ " where T : System.IComparable,
System.ICloneable {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#2");
+
+ typeParamT.HasConstructorConstraint = true;
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T>(){0}" +
+ " where T : System.IComparable,
System.ICloneable, new () {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#3");
+
+ CodeTypeParameter typeParamS = new CodeTypeParameter
("S");
+ typeParamS.Constraints.Add (new CodeTypeReference
(typeof (IDisposable)));
+ method.TypeParameters.Add (typeParamS);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T, S>(){0}" +
+ " where T : System.IComparable,
System.ICloneable, new (){0}" +
+ " where S : System.IDisposable
{{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#4");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.HasConstructorConstraint = true;
+ method.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T, S, R>(){0}"
+
+ " where T : System.IComparable,
System.ICloneable, new (){0}" +
+ " where S : System.IDisposable{0}" +
+ " where R : new() {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate (), "#5");
+ }
+
+ [Test] // bug #353921
+ public void Method_TypeParameters_ConstructorConstraint ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "SomeMethod";
+ type.Members.Add (method);
+
+ CodeTypeParameter typeParam = new CodeTypeParameter
("T");
+ typeParam.HasConstructorConstraint = true;
+ method.TypeParameters.Add (typeParam);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "namespace SomeNS {{{0}" +
+ " {0}" +
+ " {0}" +
+ " public class SomeClass {{{0}" +
+ " {0}" +
+ " private void SomeMethod<T>(){0}" +
+ " where T : new() {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), Generate ());
+ }
+#endif
}
}
Modified: trunk/mcs/class/System/Test/Microsoft.VisualBasic/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/Microsoft.VisualBasic/ChangeLog 2008-01-16
18:13:35 UTC (rev 93074)
+++ trunk/mcs/class/System/Test/Microsoft.VisualBasic/ChangeLog 2008-01-16
18:15:25 UTC (rev 93075)
@@ -1,3 +1,7 @@
+2008-01-16 Gert Driesen <[EMAIL PROTECTED]>
+
+ * CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
+
2007-12-21 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* CodeGeneratorFromTypeTest.cs: Added PartialTypeTest.
Modified:
trunk/mcs/class/System/Test/Microsoft.VisualBasic/CodeGeneratorFromNamespaceTest.cs
===================================================================
---
trunk/mcs/class/System/Test/Microsoft.VisualBasic/CodeGeneratorFromNamespaceTest.cs
2008-01-16 18:13:35 UTC (rev 93074)
+++
trunk/mcs/class/System/Test/Microsoft.VisualBasic/CodeGeneratorFromNamespaceTest.cs
2008-01-16 18:15:25 UTC (rev 93075)
@@ -160,5 +160,324 @@
" End Class{0}" +
"End Namespace{0}", NewLine), Generate
(options), "#B2");
}
+
+#if NET_2_0
+ [Test]
+ public void Type_TypeParameters ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+ type.TypeParameters.Add (new CodeTypeParameter ("T"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#1");
+
+ type.TypeParameters.Add (new CodeTypeParameter ("As"));
+ type.TypeParameters.Add (new CodeTypeParameter ("New"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T, As, New){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#2");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ type.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T, As, New, R As
System.IComparable){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#3");
+
+ type.TypeParameters.Add (new CodeTypeParameter ("S"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T, As, New, R As
System.IComparable, S){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#4");
+ }
+
+ [Test]
+ public void Type_TypeParameters_Constraints ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeTypeParameter typeParamT = new CodeTypeParameter
("T");
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ type.TypeParameters.Add (typeParamT);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T As
System.IComparable){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#1");
+
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (ICloneable)));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T As
{{System.IComparable, System.ICloneable}}){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#2");
+
+ typeParamT.HasConstructorConstraint = true;
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T As
{{System.IComparable, System.ICloneable, New}}){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#3");
+
+ CodeTypeParameter typeParamS = new CodeTypeParameter
("S");
+ typeParamS.Constraints.Add (new CodeTypeReference
(typeof (IDisposable)));
+ type.TypeParameters.Add (typeParamS);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T As
{{System.IComparable, System.ICloneable, New}}, S As System.IDisposable){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#4");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.HasConstructorConstraint = true;
+ type.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T As
{{System.IComparable, System.ICloneable, New}}, S As System.IDisposable, R As
New){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#5");
+ }
+
+ [Test]
+ public void Type_TypeParameters_ConstructorConstraint ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeTypeParameter typeParam = new CodeTypeParameter
("T");
+ typeParam.HasConstructorConstraint = true;
+ type.TypeParameters.Add (typeParam);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass(Of T As New){0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate ());
+ }
+
+ [Test]
+ public void Method_TypeParameters ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "SomeMethod";
+ type.Members.Add (method);
+
+ method.TypeParameters.Add (new CodeTypeParameter ("T"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#1");
+
+ method.TypeParameters.Add (new CodeTypeParameter
("As"));
+ method.TypeParameters.Add (new CodeTypeParameter
("New"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T, As,
New)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#2");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ method.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T, As, New,
R As System.IComparable)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#3");
+
+ method.TypeParameters.Add (new CodeTypeParameter ("S"));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T, As, New,
R As System.IComparable, S)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#4");
+ }
+
+ [Test]
+ public void Method_TypeParameters_Constraints ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "SomeMethod";
+ type.Members.Add (method);
+
+ CodeTypeParameter typeParamT = new CodeTypeParameter
("T");
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (IComparable)));
+ method.TypeParameters.Add (typeParamT);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T As
System.IComparable)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#1");
+
+ typeParamT.Constraints.Add (new CodeTypeReference
(typeof (ICloneable)));
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T As
{{System.IComparable, System.ICloneable}})(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#2");
+
+ typeParamT.HasConstructorConstraint = true;
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T As
{{System.IComparable, System.ICloneable, New}})(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#3");
+
+ CodeTypeParameter typeParamS = new CodeTypeParameter
("S");
+ typeParamS.Constraints.Add (new CodeTypeReference
(typeof (IDisposable)));
+ method.TypeParameters.Add (typeParamS);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T As
{{System.IComparable, System.ICloneable, New}}, S As System.IDisposable)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#4");
+
+ CodeTypeParameter typeParamR = new CodeTypeParameter
("R");
+ typeParamR.HasConstructorConstraint = true;
+ method.TypeParameters.Add (typeParamR);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T As
{{System.IComparable, System.ICloneable, New}}, S As System.IDisposable, R As
New)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate (),
"#5");
+ }
+
+ [Test]
+ public void Method_TypeParameters_ConstructorConstraint ()
+ {
+ codeNamespace.Name = "SomeNS";
+
+ CodeTypeDeclaration type = new CodeTypeDeclaration
("SomeClass");
+ codeNamespace.Types.Add (type);
+
+ CodeMemberMethod method = new CodeMemberMethod ();
+ method.Name = "SomeMethod";
+ type.Members.Add (method);
+
+ CodeTypeParameter typeParam = new CodeTypeParameter
("T");
+ typeParam.HasConstructorConstraint = true;
+ method.TypeParameters.Add (typeParam);
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}" +
+ "Namespace SomeNS{0}" +
+ " {0}" +
+ " Public Class SomeClass{0}" +
+ " {0}" +
+ " Private Sub SomeMethod(Of T As
New)(){0}" +
+ " End Sub{0}" +
+ " End Class{0}" +
+ "End Namespace{0}", NewLine), Generate ());
+ }
+#endif
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches