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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.VB.Tests/Parser/Expressions/CastExpressionTests.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) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.IO;
 
6
using NUnit.Framework;
 
7
using ICSharpCode.NRefactory.VB.Parser;
 
8
using ICSharpCode.NRefactory.VB.Ast;
 
9
 
 
10
namespace ICSharpCode.NRefactory.VB.Tests.Ast
 
11
{
 
12
        [TestFixture]
 
13
        public class CastExpressionTests
 
14
        {
 
15
                #region VB.NET
 
16
                void TestSpecializedCast(string castExpression, Type castType)
 
17
                {
 
18
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>(castExpression);
 
19
                        Assert.AreEqual(castType.FullName, ce.CastTo.Type);
 
20
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
21
                        Assert.AreEqual(CastType.PrimitiveConversion, ce.CastType);
 
22
                }
 
23
                
 
24
                
 
25
                [Test]
 
26
                public void VBNetSimpleCastExpression()
 
27
                {
 
28
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>("CType(o, MyObject)");
 
29
                        Assert.AreEqual("MyObject", ce.CastTo.Type);
 
30
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
31
                        Assert.AreEqual(CastType.Conversion, ce.CastType);
 
32
                }
 
33
                
 
34
                [Test]
 
35
                public void VBNetGenericCastExpression()
 
36
                {
 
37
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>("CType(o, List(of T))");
 
38
                        Assert.AreEqual("List", ce.CastTo.Type);
 
39
                        Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type);
 
40
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
41
                        Assert.AreEqual(CastType.Conversion, ce.CastType);
 
42
                }
 
43
                
 
44
                [Test]
 
45
                public void VBNetSimpleDirectCastExpression()
 
46
                {
 
47
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>("DirectCast(o, MyObject)");
 
48
                        Assert.AreEqual("MyObject", ce.CastTo.Type);
 
49
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
50
                        Assert.AreEqual(CastType.Cast, ce.CastType);
 
51
                }
 
52
                
 
53
                [Test]
 
54
                public void VBNetGenericDirectCastExpression()
 
55
                {
 
56
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>("DirectCast(o, List(of T))");
 
57
                        Assert.AreEqual("List", ce.CastTo.Type);
 
58
                        Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type);
 
59
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
60
                        Assert.AreEqual(CastType.Cast, ce.CastType);
 
61
                }
 
62
                
 
63
                [Test]
 
64
                public void VBNetSimpleTryCastExpression()
 
65
                {
 
66
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>("TryCast(o, MyObject)");
 
67
                        Assert.AreEqual("MyObject", ce.CastTo.Type);
 
68
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
69
                        Assert.AreEqual(CastType.TryCast, ce.CastType);
 
70
                }
 
71
                
 
72
                [Test]
 
73
                public void VBNetGenericTryCastExpression()
 
74
                {
 
75
                        CastExpression ce = ParseUtil.ParseExpression<CastExpression>("TryCast(o, List(of T))");
 
76
                        Assert.AreEqual("List", ce.CastTo.Type);
 
77
                        Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type);
 
78
                        Assert.IsTrue(ce.Expression is SimpleNameExpression);
 
79
                        Assert.AreEqual(CastType.TryCast, ce.CastType);
 
80
                }
 
81
                
 
82
                [Test]
 
83
                public void VBNetSpecializedBoolCastExpression()
 
84
                {
 
85
                        TestSpecializedCast("CBool(o)", typeof(System.Boolean));
 
86
                }
 
87
                
 
88
                [Test]
 
89
                public void VBNetSpecializedCharCastExpression()
 
90
                {
 
91
                        TestSpecializedCast("CChar(o)", typeof(System.Char));
 
92
                }
 
93
                
 
94
                
 
95
                [Test]
 
96
                public void VBNetSpecializedStringCastExpression()
 
97
                {
 
98
                        TestSpecializedCast("CStr(o)", typeof(System.String));
 
99
                }
 
100
                
 
101
                [Test]
 
102
                public void VBNetSpecializedDateTimeCastExpression()
 
103
                {
 
104
                        TestSpecializedCast("CDate(o)", typeof(System.DateTime));
 
105
                }
 
106
                
 
107
                [Test]
 
108
                public void VBNetSpecializedDecimalCastExpression()
 
109
                {
 
110
                        TestSpecializedCast("CDec(o)", typeof(System.Decimal));
 
111
                }
 
112
                
 
113
                [Test]
 
114
                public void VBNetSpecializedSingleCastExpression()
 
115
                {
 
116
                        TestSpecializedCast("CSng(o)", typeof(System.Single));
 
117
                }
 
118
                
 
119
                [Test]
 
120
                public void VBNetSpecializedDoubleCastExpression()
 
121
                {
 
122
                        TestSpecializedCast("CDbl(o)", typeof(System.Double));
 
123
                }
 
124
                
 
125
                [Test]
 
126
                public void VBNetSpecializedByteCastExpression()
 
127
                {
 
128
                        TestSpecializedCast("CByte(o)", typeof(System.Byte));
 
129
                }
 
130
                
 
131
                [Test]
 
132
                public void VBNetSpecializedInt16CastExpression()
 
133
                {
 
134
                        TestSpecializedCast("CShort(o)", typeof(System.Int16));
 
135
                }
 
136
                
 
137
                [Test]
 
138
                public void VBNetSpecializedInt32CastExpression()
 
139
                {
 
140
                        TestSpecializedCast("CInt(o)", typeof(System.Int32));
 
141
                }
 
142
                
 
143
                [Test]
 
144
                public void VBNetSpecializedInt64CastExpression()
 
145
                {
 
146
                        TestSpecializedCast("CLng(o)", typeof(System.Int64));
 
147
                }
 
148
                
 
149
                [Test]
 
150
                public void VBNetSpecializedSByteCastExpression()
 
151
                {
 
152
                        TestSpecializedCast("CSByte(o)", typeof(System.SByte));
 
153
                }
 
154
                
 
155
                [Test]
 
156
                public void VBNetSpecializedUInt16CastExpression()
 
157
                {
 
158
                        TestSpecializedCast("CUShort(o)", typeof(System.UInt16));
 
159
                }
 
160
                
 
161
                [Test]
 
162
                public void VBNetSpecializedUInt32CastExpression()
 
163
                {
 
164
                        TestSpecializedCast("CUInt(o)", typeof(System.UInt32));
 
165
                }
 
166
                
 
167
                [Test]
 
168
                public void VBNetSpecializedUInt64CastExpression()
 
169
                {
 
170
                        TestSpecializedCast("CULng(o)", typeof(System.UInt64));
 
171
                }
 
172
                
 
173
                
 
174
                [Test]
 
175
                public void VBNetSpecializedObjectCastExpression()
 
176
                {
 
177
                        TestSpecializedCast("CObj(o)", typeof(System.Object));
 
178
                }
 
179
                #endregion
 
180
        }
 
181
}