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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateFieldTests.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
// 
 
2
// CreateFieldTests.cs
 
3
//  
 
4
// Author:
 
5
//       Mike KrĆ¼ger <mkrueger@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2012 Xamarin <http://xamarin.com>
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using NUnit.Framework;
 
28
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
29
 
 
30
namespace ICSharpCode.NRefactory.CSharp.CodeActions
 
31
{
 
32
        [TestFixture]
 
33
        public class CreateFieldTests : ContextActionTestBase
 
34
        {
 
35
        [Test()]
 
36
                public void TestWrongContext2 ()
 
37
                {
 
38
                        TestWrongContext<CreateFieldAction> (
 
39
                                "using System;" + Environment.NewLine +
 
40
                                        "class TestClass" + Environment.NewLine +
 
41
                                        "{" + Environment.NewLine +
 
42
                                        "       void Test ()" + Environment.NewLine +
 
43
                                        "       {" + Environment.NewLine +
 
44
                                        "               Console.WriteLine ($Foo());" + Environment.NewLine +
 
45
                                        "       }" + Environment.NewLine +
 
46
                                        "}"
 
47
                        );
 
48
                }
 
49
 
 
50
                [Test()]
 
51
                public void TestWrongContext3 ()
 
52
                {
 
53
                        // May be syntactically possible, but very unlikely.
 
54
                        TestWrongContext<CreateFieldAction> (
 
55
                                "using System;" + Environment.NewLine +
 
56
                                        "class TestClass" + Environment.NewLine +
 
57
                                        "{" + Environment.NewLine +
 
58
                                        "       void Test ()" + Environment.NewLine +
 
59
                                        "       {" + Environment.NewLine +
 
60
                                        "               $foo();" + Environment.NewLine +
 
61
                                        "       }" + Environment.NewLine +
 
62
                                        "}"
 
63
                        );
 
64
                }
 
65
 
 
66
                [Test()]
 
67
                public void TestSimpleMethodCall ()
 
68
                {
 
69
                        string result = RunContextAction (
 
70
                                new CreateFieldAction (),
 
71
                                "using System;" + Environment.NewLine +
 
72
                                        "class TestClass" + Environment.NewLine +
 
73
                                        "{" + Environment.NewLine +
 
74
                                        "       void Test ()" + Environment.NewLine +
 
75
                                        "       {" + Environment.NewLine +
 
76
                                        "               Console.WriteLine ($foo);" + Environment.NewLine +
 
77
                                        "       }" + Environment.NewLine +
 
78
                                        "}"
 
79
                        );
 
80
                        Console.WriteLine (result);
 
81
                        Assert.AreEqual (
 
82
                                "using System;" + Environment.NewLine +
 
83
                                "class TestClass" + Environment.NewLine +
 
84
                                "{" + Environment.NewLine +
 
85
                                "       object foo;" + Environment.NewLine +
 
86
                                "       void Test ()" + Environment.NewLine +
 
87
                                "       {" + Environment.NewLine +
 
88
                                "               Console.WriteLine (foo);" + Environment.NewLine +
 
89
                                "       }" + Environment.NewLine +
 
90
                                "}", result);
 
91
                }
 
92
 
 
93
                [Test()]
 
94
                public void TestAssignment ()
 
95
                {
 
96
                        string result = RunContextAction (
 
97
                                new CreateFieldAction (),
 
98
                                "using System;" + Environment.NewLine +
 
99
                                        "class TestClass" + Environment.NewLine +
 
100
                                        "{" + Environment.NewLine +
 
101
                                        "       void Test ()" + Environment.NewLine +
 
102
                                        "       {" + Environment.NewLine +
 
103
                                        "               $foo = 0x10;" + Environment.NewLine +
 
104
                                        "       }" + Environment.NewLine +
 
105
                                        "}"
 
106
                        );
 
107
 
 
108
                        Assert.AreEqual (
 
109
                                "using System;" + Environment.NewLine +
 
110
                                "class TestClass" + Environment.NewLine +
 
111
                                "{" + Environment.NewLine +
 
112
                                "       int foo;" + Environment.NewLine +
 
113
                                "       void Test ()" + Environment.NewLine +
 
114
                                "       {" + Environment.NewLine +
 
115
                                "               foo = 0x10;" + Environment.NewLine +
 
116
                                "       }" + Environment.NewLine +
 
117
                                "}", result);
 
118
                }
 
119
 
 
120
                [Test()]
 
121
                public void TestOutParamCall ()
 
122
                {
 
123
                        string result = RunContextAction (
 
124
                                new CreateFieldAction (),
 
125
                                "using System;" + Environment.NewLine +
 
126
                                        "class TestClass" + Environment.NewLine +
 
127
                                        "{" + Environment.NewLine +
 
128
                                        "       void FooBar(out string par) {}" + Environment.NewLine +
 
129
                                        "       void Test ()" + Environment.NewLine +
 
130
                                        "       {" + Environment.NewLine +
 
131
                                        "               FooBar(out $foo);" + Environment.NewLine +
 
132
                                        "       }" + Environment.NewLine +
 
133
                                        "}"
 
134
                        );
 
135
                        
 
136
                        Assert.AreEqual (
 
137
                                "using System;" + Environment.NewLine +
 
138
                                "class TestClass" + Environment.NewLine +
 
139
                                "{" + Environment.NewLine +
 
140
                                "       void FooBar(out string par) {}" + Environment.NewLine +
 
141
                                "       string foo;" + Environment.NewLine +
 
142
                                "       void Test ()" + Environment.NewLine +
 
143
                                "       {" + Environment.NewLine +
 
144
                                "               FooBar(out foo);" + Environment.NewLine +
 
145
                                "       }" + Environment.NewLine +
 
146
                                "}", result);
 
147
                }
 
148
 
 
149
                [Test()]
 
150
                public void TestStaticClassField ()
 
151
                {
 
152
                        // Not 100% correct input code, but should work in that case as well.
 
153
                        Test<CreateFieldAction> (@"static class TestClass
 
154
{
 
155
        public TestClass ()
 
156
        {
 
157
                $foo = 5;
 
158
        }
 
159
}", @"static class TestClass
 
160
{
 
161
        static int foo;
 
162
        public TestClass ()
 
163
        {
 
164
                foo = 5;
 
165
        }
 
166
}");
 
167
                }
 
168
 
 
169
                [Test]
 
170
                public void TestEnumCase()
 
171
                {
 
172
                        TestWrongContext<CreateFieldAction>(@"
 
173
enum AEnum { A }
 
174
class Foo
 
175
{
 
176
        public void Test ()
 
177
        {
 
178
                AEnum e;
 
179
                e.$foo = 2;
 
180
        }
 
181
}
 
182
");
 
183
                }
 
184
 
 
185
                [Test()]
 
186
                public void TestThisMemberReferenceCreation ()
 
187
                {
 
188
                        string result = RunContextAction (
 
189
                                new CreateFieldAction (),
 
190
                                "using System;" + Environment.NewLine +
 
191
                                        "class TestClass" + Environment.NewLine +
 
192
                                        "{" + Environment.NewLine +
 
193
                                        "       void Test ()" + Environment.NewLine +
 
194
                                        "       {" + Environment.NewLine +
 
195
                                        "               this.$foo = 0x10;" + Environment.NewLine +
 
196
                                        "       }" + Environment.NewLine +
 
197
                                        "}"
 
198
                        );
 
199
 
 
200
                        Assert.AreEqual (
 
201
                                "using System;" + Environment.NewLine +
 
202
                                "class TestClass" + Environment.NewLine +
 
203
                                "{" + Environment.NewLine +
 
204
                                "       int foo;" + Environment.NewLine +
 
205
                                "       void Test ()" + Environment.NewLine +
 
206
                                "       {" + Environment.NewLine +
 
207
                                "               this.foo = 0x10;" + Environment.NewLine +
 
208
                                "       }" + Environment.NewLine +
 
209
                                "}", result);
 
210
                }
 
211
 
 
212
                [Test()]
 
213
                public void TestObjectInitializer ()
 
214
                {
 
215
                        // Not 100% correct input code, but should work in that case as well.
 
216
                        Test<CreateFieldAction> (@"class TestClass
 
217
{
 
218
        void TestMethod ()
 
219
        {
 
220
                new TestClass {
 
221
                        $NonExistantProperty = 5
 
222
                };
 
223
        }
 
224
}", @"class TestClass
 
225
{
 
226
        int NonExistantProperty;
 
227
        void TestMethod ()
 
228
        {
 
229
                new TestClass {
 
230
                        NonExistantProperty = 5
 
231
                };
 
232
        }
 
233
}");
 
234
                }
 
235
 
 
236
                [Test()]
 
237
                public void TestObjectInitializerInStaticMethod ()
 
238
                {
 
239
                        // Not 100% correct input code, but should work in that case as well.
 
240
                        Test<CreateFieldAction> (@"class TestClass
 
241
{
 
242
        static void TestMethod ()
 
243
        {
 
244
                new TestClass {
 
245
                        $NonExistantProperty = 5
 
246
                };
 
247
        }
 
248
}", @"class TestClass
 
249
{
 
250
        int NonExistantProperty;
 
251
        static void TestMethod ()
 
252
        {
 
253
                new TestClass {
 
254
                        NonExistantProperty = 5
 
255
                };
 
256
        }
 
257
}");
 
258
                }
 
259
 
 
260
        }
 
261
}
 
 
b'\\ No newline at end of file'