5 // Marek Safar <marek.safar@gmail.com>
7 // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
32 using System.Collections;
34 namespace MonoTests.EvaluatorTest
37 public class TypesTest : EvaluatorFixture
40 public void SimpleTypeStaticMethod ()
43 Evaluator.Run ("class Y { public static int Test () { return 5; }}");
44 res = Evaluator.Evaluate ("Y.Test ();");
45 Assert.AreEqual (5, res, "#1");
49 public void SameTypeNameRedefinition ()
51 Evaluator.Run ("class X { }");
52 Evaluator.Run ("class X { public static void Foo () { throw new System.ApplicationException (); } }");
53 Evaluator.Run ("class X {}");
54 Evaluator.Run ("class X { public static string Foo () { return \"Test\"; } }");
55 object res = Evaluator.Evaluate ("X.Foo ();");
56 Assert.AreEqual ("Test", res, "#1");
57 Evaluator.Run ("class X { public static int Foo () { return 5; } }");
58 res = Evaluator.Evaluate ("X.Foo ();");
59 Assert.AreEqual (5, res, "#2");
63 public void SimpleConstructor ()
65 Evaluator.Run ("class Y2 { public int Value; public Y2 (){ Value = 99; } }");
66 Evaluator.Run ("var a = new Y2 ();");
67 object res = Evaluator.Evaluate ("a.Value;");
68 Assert.AreEqual (99, res);
72 public void TypeOfType ()
74 Evaluator.Run ("struct Z { }");
75 object res = Evaluator.Evaluate ("typeof (Z);");
76 Assert.AreEqual ("Z", res.ToString ());
80 public void UsingAfterType ()
82 Evaluator.Run ("struct Z { }");
83 Evaluator.Run ("using System;");
84 Evaluator.Run ("struct Z { }");
88 public void MoreThanOneType ()
90 Evaluator.Run ("public class D { int x; public int X { get { return x; } set { x = value;} } };");
91 Evaluator.Run ("public class C { public int Speed{get;set;}};");
95 public void StructType ()
97 Evaluator.Run ("class C { }");
98 Evaluator.Run ("struct B { public string foo; public int bar; }");
99 Evaluator.Run ("B aStruct = new B { foo = \"foo\", bar = 1 };");
103 public void NestedType ()
105 Evaluator.Run ("class A { class B { } }");
106 Evaluator.Run ("var x = new A ();");
110 public void DelegateType ()
112 Evaluator.Run ("public delegate int D();");
113 Evaluator.Run ("D d = delegate () { return 7; };");
114 object res = Evaluator.Evaluate ("d();");
115 Assert.AreEqual (7, res);
119 public void ClassWithAttribute ()
121 Evaluator.Run ("public class A : System.Attribute { }");
122 Evaluator.Run ("[A] public class B {}");
123 Evaluator.Run ("var attr = new B().GetType().GetCustomAttributes(false)[0];");
125 object res = Evaluator.Evaluate ("attr.GetType().Name;");
126 Assert.AreEqual ("A", res);