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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.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
// MoveToOuterScopeTests.cs
 
3
//
 
4
// Author:
 
5
//       Simon Lindgren <simon.n.lindgren@gmail.com>
 
6
//
 
7
// Copyright (c) 2012 Simon Lindgren
 
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 NUnit.Framework;
 
27
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
28
 
 
29
namespace ICSharpCode.NRefactory.CSharp.CodeActions
 
30
{
 
31
        [TestFixture]
 
32
        public class MoveToOuterScopeTests : ContextActionTestBase
 
33
        {
 
34
                void TestStatements (string input, string output) 
 
35
                {
 
36
                        Test<MoveToOuterScopeAction>(@"
 
37
class A
 
38
{
 
39
        void F()
 
40
        {"
 
41
         + input + 
 
42
@"      }
 
43
}", @"
 
44
class A
 
45
{
 
46
        void F()
 
47
        {"
 
48
     + output + 
 
49
@"      }
 
50
}");
 
51
                }
 
52
 
 
53
                [Test]
 
54
                public void SimpleCase()
 
55
                {
 
56
                        TestStatements(@"
 
57
        while (true) {
 
58
                int $i = 2;
 
59
        }
 
60
", @"
 
61
                int i = 2;
 
62
        while (true) {
 
63
        }
 
64
");
 
65
                }
 
66
                
 
67
                [Test]
 
68
                public void IgnoresDeclarationsDirectlyInABody()
 
69
                {
 
70
                        TestWrongContext<MoveToOuterScopeAction>(@"
 
71
class A
 
72
{
 
73
        void F()
 
74
        {
 
75
                int $i = 2;
 
76
        }
 
77
}");
 
78
                }
 
79
 
 
80
                [Test]
 
81
                public void MovesOnlyTheCurrentVariableInitialization()
 
82
                {
 
83
                        TestStatements(@"
 
84
        while (true) {
 
85
                int $i = 2, j = 3;
 
86
        }
 
87
", @"
 
88
        int i = 2;
 
89
        while (true) {
 
90
                        int j = 3;
 
91
        }
 
92
");
 
93
                }
 
94
                
 
95
                [Test]
 
96
                public void MovesAllInitializersWhenOnType()
 
97
                {
 
98
                        TestStatements(@"
 
99
        while (true) {
 
100
                i$nt i = 2, j = 3;
 
101
        }
 
102
", @"
 
103
                int i = 2, j = 3;
 
104
        while (true) {
 
105
        }
 
106
");
 
107
                }
 
108
                
 
109
                [Test]
 
110
                public void OnlyMovesDeclarationWhenInitializerDependsOnOtherStatements()
 
111
                {
 
112
                        TestStatements(@"
 
113
        while (true) {
 
114
                int i = 2;
 
115
                int j$ = i;
 
116
        }
 
117
", @"
 
118
                int j;
 
119
        while (true) {
 
120
                int i = 2;
 
121
                j = i;
 
122
        }
 
123
");
 
124
                }
 
125
                
 
126
                [Test]
 
127
                public void HandlesLambdaDelegate()
 
128
                {
 
129
                        TestStatements(@"
 
130
        var action = new Action<int>(i => {
 
131
                int j$ = 2;
 
132
        });
 
133
", @"
 
134
                int j = 2;
 
135
        var action = new Action<int>(i => {
 
136
        });
 
137
");
 
138
                }
 
139
                
 
140
                [Test]
 
141
                public void IgnoresDeclarationDirectlyInConstructorBody()
 
142
                {
 
143
                        TestWrongContext<MoveToOuterScopeAction>(@"
 
144
class A
 
145
{
 
146
        public A()
 
147
        {
 
148
                int $i = 2;
 
149
        }
 
150
}");
 
151
                }
 
152
        }
 
153
}
 
154