New test.
[mono.git] / mcs / class / System / Test / Microsoft.CSharp / CodeGeneratorFromNamespaceTest.cs
index bf1c1d433f5c9a670117f9a807caeb122a64589e..cba64f69e951f08506b7c367253e6e0dd5868701 100644 (file)
@@ -9,6 +9,7 @@
 using System;
 using System.CodeDom;
 using System.CodeDom.Compiler;
+using System.Globalization;
 using System.IO;
 using System.Text;
 
@@ -93,5 +94,79 @@ namespace MonoTests.Microsoft.CSharp
                        codeNamespace.Comments.Add (comment);
                        Assert.AreEqual ("// a\n\n", Generate ());
                }
+
+               [Test]
+               public void ImportsTest ()
+               {
+                       codeNamespace.Imports.Add (new CodeNamespaceImport ("System"));
+                       codeNamespace.Imports.Add (new CodeNamespaceImport ("System.Collections"));
+
+                       Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+                               "using System;{0}" +
+                               "using System.Collections;{0}" +
+                               "{0}", NewLine), Generate (), "#1");
+
+                       codeNamespace.Name = "A";
+
+                       Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+                               "namespace A {{{0}" +
+                               "    using System;{0}" +
+                               "    using System.Collections;{0}" +
+                               "    {0}" +
+                               "}}{0}", NewLine), Generate (), "#2");
+
+                       codeNamespace.Name = null;
+                       codeNamespace.Comments.Add (new CodeCommentStatement ("a"));
+
+                       Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+                               "// a{0}" +
+                               "using System;{0}" +
+                               "using System.Collections;{0}" +
+                               "{0}", NewLine), Generate (), "#3");
+
+                       codeNamespace.Name = "A";
+
+                       Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+                               "// a{0}" +
+                               "namespace A {{{0}" +
+                               "    using System;{0}" +
+                               "    using System.Collections;{0}" +
+                               "    {0}" +
+                               "}}{0}", NewLine), Generate (), "#4");
+               }
+
+               [Test]
+               public void TypeTest ()
+               {
+                       codeNamespace.Types.Add (new CodeTypeDeclaration ("Person"));
+                       Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
+                               "{0}" +
+                               "{0}" +
+                               "public class Person {{{0}" +
+                               "}}{0}", NewLine), Generate (), "#A1");
+
+                       CodeGeneratorOptions options = new CodeGeneratorOptions ();
+                       options.BlankLinesBetweenMembers = false;
+                       Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
+                               "{0}" +
+                               "public class Person {{{0}" +
+                               "}}{0}", NewLine), Generate (options), "#A2");
+
+                       codeNamespace.Name = "A";
+                       Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
+                               "namespace A {{{0}" +
+                               "    {0}" +
+                               "    {0}" +
+                               "    public class Person {{{0}" +
+                               "    }}{0}" +
+                               "}}{0}", NewLine), Generate (), "#B1");
+
+                       Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+                               "namespace A {{{0}" +
+                               "    {0}" +
+                               "    public class Person {{{0}" +
+                               "    }}{0}" +
+                               "}}{0}", NewLine), Generate (options), "#B2");
+               }
        }
 }