2 // CodeGeneratorTypeOutputTest.cs
5 // Gert Driesen <drieseng@users.sourceforge.net>
11 using System.CodeDom.Compiler;
13 using System.Collections.Generic;
16 using NUnit.Framework;
18 using Microsoft.CSharp;
20 namespace MonoTests.Microsoft.CSharp
23 public class CodeGeneratorTypeOutputTest
25 private ICodeGenerator gen;
30 gen = new CSharpCodeProvider ().CreateGenerator ();
34 // This test fails on 2.0 profile, because our CodeTypeReference does not
35 // parse basetype from right to left.
37 [Category ("NotWorking")]
38 public void GetTypeOutputFailure ()
40 Assert.AreEqual ("A[,,][,]", gen.GetTypeOutput (new CodeTypeReference ("A[,,][,]")), "#5");
41 Assert.AreEqual ("A<B, D>[,]", gen.GetTypeOutput (new CodeTypeReference ("A[B,,D][,]")), "#6");
46 public void GetTypeOutput ()
48 Assert.AreEqual ("A", gen.GetTypeOutput (new CodeTypeReference ("A")), "#1");
49 Assert.AreEqual ("A[]", gen.GetTypeOutput (new CodeTypeReference ("A[]")), "#2");
50 Assert.AreEqual ("int[]", gen.GetTypeOutput (new CodeTypeReference (typeof (int).FullName, 1)), "#3");
51 Assert.AreEqual ("int[,]", gen.GetTypeOutput (new CodeTypeReference (typeof (int).FullName, 2)), "#4");
53 Assert.AreEqual ("System.Nullable<int>", gen.GetTypeOutput (new CodeTypeReference (typeof (int?))), "#7");
54 Assert.AreEqual ("System.Collections.Generic.Dictionary<int, string>", gen.GetTypeOutput (new CodeTypeReference (typeof (Dictionary<int, string>))), "#8");
56 Assert.AreEqual ("A[,,][,]", gen.GetTypeOutput (new CodeTypeReference ("A[,,][,]")), "#5");
57 Assert.AreEqual ("A[B,,D][,]", gen.GetTypeOutput (new CodeTypeReference ("A[B,,D][,]")), "#6");
58 Assert.AreEqual ("System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
59 gen.GetTypeOutput (new CodeTypeReference ("System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")),
61 Assert.AreEqual ("System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
62 gen.GetTypeOutput (new CodeTypeReference ("System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")),
68 public void Shortcuts () {
69 Assert.AreEqual ("int", gen.GetTypeOutput (new CodeTypeReference (typeof(int))), "#1");
70 Assert.AreEqual ("int", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT32")), "#2");
71 Assert.AreEqual ("long", gen.GetTypeOutput (new CodeTypeReference (typeof(long))), "#3");
72 Assert.AreEqual ("long", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT64")), "#4");
73 Assert.AreEqual ("short", gen.GetTypeOutput (new CodeTypeReference (typeof(short))), "#5");
74 Assert.AreEqual ("short", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT16")), "#6");
75 Assert.AreEqual ("bool", gen.GetTypeOutput (new CodeTypeReference (typeof(bool))), "#7");
76 Assert.AreEqual ("bool", gen.GetTypeOutput (new CodeTypeReference ("systeM.BooLean")), "#8");
77 Assert.AreEqual ("char", gen.GetTypeOutput (new CodeTypeReference (typeof(char))), "#9");
78 Assert.AreEqual ("char", gen.GetTypeOutput (new CodeTypeReference ("systeM.cHar")), "#10");
79 Assert.AreEqual ("string", gen.GetTypeOutput (new CodeTypeReference (typeof(string))), "#11");
80 Assert.AreEqual ("string", gen.GetTypeOutput (new CodeTypeReference ("systeM.sTring")), "#12");
81 Assert.AreEqual ("object", gen.GetTypeOutput (new CodeTypeReference (typeof(object))), "#13");
82 Assert.AreEqual ("object", gen.GetTypeOutput (new CodeTypeReference ("systeM.oBject")), "#14");
83 Assert.AreEqual ("void", gen.GetTypeOutput (new CodeTypeReference (typeof(void))), "#15");
84 Assert.AreEqual ("void", gen.GetTypeOutput (new CodeTypeReference ("systeM.vOid")), "#16");
86 Assert.AreEqual ("byte", gen.GetTypeOutput (new CodeTypeReference (typeof(byte))), "#17");
87 Assert.AreEqual ("byte", gen.GetTypeOutput (new CodeTypeReference ("systeM.bYte")), "#18");
88 Assert.AreEqual ("sbyte", gen.GetTypeOutput (new CodeTypeReference (typeof(sbyte))), "#19");
89 Assert.AreEqual ("sbyte", gen.GetTypeOutput (new CodeTypeReference ("systeM.sBYte")), "#20");
90 Assert.AreEqual ("decimal", gen.GetTypeOutput (new CodeTypeReference (typeof(decimal))), "#21");
91 Assert.AreEqual ("decimal", gen.GetTypeOutput (new CodeTypeReference ("systeM.dEcimal")), "#22");
92 Assert.AreEqual ("double", gen.GetTypeOutput (new CodeTypeReference (typeof(double))), "#23");
93 Assert.AreEqual ("double", gen.GetTypeOutput (new CodeTypeReference ("systeM.dOuble")), "#24");
94 Assert.AreEqual ("float", gen.GetTypeOutput (new CodeTypeReference (typeof(float))), "#25");
95 Assert.AreEqual ("float", gen.GetTypeOutput (new CodeTypeReference ("systeM.SiNgle")), "#26");
96 Assert.AreEqual ("uint", gen.GetTypeOutput (new CodeTypeReference (typeof (uint))), "#27");
97 Assert.AreEqual ("uint", gen.GetTypeOutput (new CodeTypeReference ("systeM.UinT32")), "#28");
98 Assert.AreEqual ("ulong", gen.GetTypeOutput (new CodeTypeReference (typeof (ulong))), "#29");
99 Assert.AreEqual ("ulong", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT64")), "#30");
100 Assert.AreEqual ("ushort", gen.GetTypeOutput (new CodeTypeReference (typeof (ushort))), "#31");
101 Assert.AreEqual ("ushort", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT16")), "#32");
103 Assert.AreEqual (typeof (byte).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (byte))), "#17");
104 Assert.AreEqual ("systeM.bYte", gen.GetTypeOutput (new CodeTypeReference ("systeM.bYte")), "#18");
105 Assert.AreEqual (typeof (sbyte).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (sbyte))), "#19");
106 Assert.AreEqual ("systeM.sBYte", gen.GetTypeOutput (new CodeTypeReference ("systeM.sBYte")), "#20");
107 Assert.AreEqual (typeof (decimal).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (decimal))), "#21");
108 Assert.AreEqual ("systeM.dEcimal", gen.GetTypeOutput (new CodeTypeReference ("systeM.dEcimal")), "#22");
109 Assert.AreEqual (typeof (double).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (double))), "#23");
110 Assert.AreEqual ("systeM.dOuble", gen.GetTypeOutput (new CodeTypeReference ("systeM.dOuble")), "#24");
111 Assert.AreEqual (typeof (float).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (float))), "#25");
112 Assert.AreEqual ("systeM.SiNgle", gen.GetTypeOutput (new CodeTypeReference ("systeM.SiNgle")), "#26");
113 Assert.AreEqual (typeof (uint).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (uint))), "#27");
114 Assert.AreEqual ("systeM.UinT32", gen.GetTypeOutput (new CodeTypeReference ("systeM.UinT32")), "#28");
115 Assert.AreEqual (typeof (ulong).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (ulong))), "#29");
116 Assert.AreEqual ("systeM.uinT64", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT64")), "#30");
117 Assert.AreEqual (typeof (ushort).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (ushort))), "#31");
118 Assert.AreEqual ("systeM.uinT16", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT16")), "#32");