1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
20
using NUnit.Framework;
22
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
25
public class TypeOfExpressionTests
28
public void SimpleTypeOfExpressionTest()
30
ParseUtilCSharp.AssertExpression(
31
"typeof(MyNamespace.N1.MyType)",
32
new TypeOfExpression {
33
Type = new MemberType {
34
Target = new MemberType {
35
Target = new SimpleType("MyNamespace"),
43
public void GlobalTypeOfExpressionTest()
45
ParseUtilCSharp.AssertExpression(
46
"typeof(global::System.Console)",
47
new TypeOfExpression {
48
Type = new MemberType {
49
Target = new MemberType {
50
Target = new SimpleType("global"),
54
MemberName = "Console"
59
public void PrimitiveTypeOfExpressionTest()
61
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(int)");
62
Assert.AreEqual("int", ((PrimitiveType)toe.Type).Keyword);
66
public void VoidTypeOfExpressionTest()
68
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(void)");
69
Assert.AreEqual("void", ((PrimitiveType)toe.Type).Keyword);
73
public void ArrayTypeOfExpressionTest()
75
ParseUtilCSharp.AssertExpression(
77
new TypeOfExpression {
78
Type = new SimpleType("MyType").MakeArrayType()
83
public void GenericTypeOfExpressionTest()
85
ParseUtilCSharp.AssertExpression(
86
"typeof(MyNamespace.N1.MyType<string>)",
87
new TypeOfExpression {
88
Type = new MemberType {
89
Target = new MemberType {
90
Target = new SimpleType("MyNamespace"),
93
MemberName = "MyType",
94
TypeArguments = { new PrimitiveType("string") }
99
public void NestedGenericTypeOfExpressionTest()
101
ParseUtilCSharp.AssertExpression(
102
"typeof(MyType<string>.InnerClass<int>.InnerInnerClass)",
103
new TypeOfExpression {
104
Type = new MemberType {
105
Target = new MemberType {
106
Target = new SimpleType("MyType") { TypeArguments = { new PrimitiveType("string") } },
107
MemberName = "InnerClass",
108
TypeArguments = { new PrimitiveType("int") }
110
MemberName = "InnerInnerClass"
115
public void NullableTypeOfExpressionTest()
117
ParseUtilCSharp.AssertExpression(
119
new TypeOfExpression {
120
Type = new ComposedType {
121
BaseType = new SimpleType("MyStruct"),
122
HasNullableSpecifier = true
127
public void UnboundTypeOfExpressionTest()
129
var type = new SimpleType("MyType");
130
type.AddChild (new SimpleType (), Roles.TypeArgument);
131
type.AddChild (new SimpleType (), Roles.TypeArgument);
132
ParseUtilCSharp.AssertExpression(
134
new TypeOfExpression {
140
public void NestedArraysTest()
142
ParseUtilCSharp.AssertExpression(
144
new TypeOfExpression {
145
Type = new ComposedType {
146
BaseType = new PrimitiveType("int"),
148
new ArraySpecifier(2),
149
new ArraySpecifier(1)