~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
 
2
// 
 
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:
 
8
// 
 
9
// The above copyright notice and this permission notice shall be included in all copies or
 
10
// substantial portions of the Software.
 
11
// 
 
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.
 
18
 
 
19
using System;
 
20
using NUnit.Framework;
 
21
 
 
22
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
 
23
{
 
24
        [TestFixture]
 
25
        public class TypeOfExpressionTests
 
26
        {
 
27
                [Test]
 
28
                public void SimpleTypeOfExpressionTest()
 
29
                {
 
30
                        ParseUtilCSharp.AssertExpression(
 
31
                                "typeof(MyNamespace.N1.MyType)",
 
32
                                new TypeOfExpression {
 
33
                                        Type = new MemberType {
 
34
                                                Target = new MemberType {
 
35
                                                        Target = new SimpleType("MyNamespace"),
 
36
                                                        MemberName = "N1"
 
37
                                                },
 
38
                                                MemberName = "MyType"
 
39
                                        }});
 
40
                }
 
41
                
 
42
                [Test]
 
43
                public void GlobalTypeOfExpressionTest()
 
44
                {
 
45
                        ParseUtilCSharp.AssertExpression(
 
46
                                "typeof(global::System.Console)",
 
47
                                new TypeOfExpression {
 
48
                                        Type = new MemberType {
 
49
                                                Target = new MemberType {
 
50
                                                        Target = new SimpleType("global"),
 
51
                                                        IsDoubleColon = true,
 
52
                                                        MemberName = "System"
 
53
                                                },
 
54
                                                MemberName = "Console"
 
55
                                        }});
 
56
                }
 
57
                
 
58
                [Test]
 
59
                public void PrimitiveTypeOfExpressionTest()
 
60
                {
 
61
                        TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(int)");
 
62
                        Assert.AreEqual("int", ((PrimitiveType)toe.Type).Keyword);
 
63
                }
 
64
                
 
65
                [Test]
 
66
                public void VoidTypeOfExpressionTest()
 
67
                {
 
68
                        TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(void)");
 
69
                        Assert.AreEqual("void", ((PrimitiveType)toe.Type).Keyword);
 
70
                }
 
71
                
 
72
                [Test]
 
73
                public void ArrayTypeOfExpressionTest()
 
74
                {
 
75
                        ParseUtilCSharp.AssertExpression(
 
76
                                "typeof(MyType[])",
 
77
                                new TypeOfExpression {
 
78
                                        Type = new SimpleType("MyType").MakeArrayType()
 
79
                                });
 
80
                }
 
81
                
 
82
                [Test]
 
83
                public void GenericTypeOfExpressionTest()
 
84
                {
 
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"),
 
91
                                                        MemberName = "N1"
 
92
                                                },
 
93
                                                MemberName = "MyType",
 
94
                                                TypeArguments = { new PrimitiveType("string") }
 
95
                                        }});
 
96
                }
 
97
                
 
98
                [Test]
 
99
                public void NestedGenericTypeOfExpressionTest()
 
100
                {
 
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") }
 
109
                                                },
 
110
                                                MemberName = "InnerInnerClass"
 
111
                                        }});
 
112
                }
 
113
                
 
114
                [Test]
 
115
                public void NullableTypeOfExpressionTest()
 
116
                {
 
117
                        ParseUtilCSharp.AssertExpression(
 
118
                                "typeof(MyStruct?)",
 
119
                                new TypeOfExpression {
 
120
                                        Type = new ComposedType {
 
121
                                                BaseType = new SimpleType("MyStruct"),
 
122
                                                HasNullableSpecifier = true
 
123
                                        }});
 
124
                }
 
125
                
 
126
                [Test]
 
127
                public void UnboundTypeOfExpressionTest()
 
128
                {
 
129
                        var type = new SimpleType("MyType");
 
130
                        type.AddChild (new SimpleType (), Roles.TypeArgument);
 
131
                        type.AddChild (new SimpleType (), Roles.TypeArgument);
 
132
                        ParseUtilCSharp.AssertExpression(
 
133
                                "typeof(MyType<,>)",
 
134
                                new TypeOfExpression {
 
135
                                        Type = type
 
136
                                });
 
137
                }
 
138
                
 
139
                [Test]
 
140
                public void NestedArraysTest()
 
141
                {
 
142
                        ParseUtilCSharp.AssertExpression(
 
143
                                "typeof(int[,][])",
 
144
                                new TypeOfExpression {
 
145
                                        Type = new ComposedType {
 
146
                                                BaseType = new PrimitiveType("int"),
 
147
                                                ArraySpecifiers = {
 
148
                                                        new ArraySpecifier(2),
 
149
                                                        new ArraySpecifier(1)
 
150
                                                }
 
151
                                        }});
 
152
                }
 
153
        }
 
154
}