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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/FormatStringIssues/FormatStringTests.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
// FormatStringIssueTests.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.CodeActions;
 
28
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
29
 
 
30
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
 
31
{
 
32
        [TestFixture]
 
33
        public class FormatStringTests : InspectionActionTestBase
 
34
        {
 
35
                [Test]
 
36
                public void TooFewArguments()
 
37
                {
 
38
                        var input = @"
 
39
class TestClass
 
40
{
 
41
        void Foo()
 
42
        {
 
43
                string.Format(""{0}"");
 
44
        }
 
45
}";
 
46
                        
 
47
                        TestRefactoringContext context;
 
48
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
49
                        Assert.AreEqual (1, issues.Count);
 
50
                }
 
51
                
 
52
                [Test]
 
53
                public void SupportsFixedArguments()
 
54
                {
 
55
                        var input = @"
 
56
class TestClass
 
57
{
 
58
        void Foo()
 
59
        {
 
60
                Bar(""{0}"", 1);
 
61
        }
 
62
 
 
63
        void Bar(string format, string arg0)
 
64
        {
 
65
        }
 
66
}";
 
67
                        
 
68
                        TestRefactoringContext context;
 
69
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
70
                        Assert.AreEqual (0, issues.Count);
 
71
                }
 
72
 
 
73
                [Test]
 
74
                public void FormatItemIndexOutOfRangeOfArguments()
 
75
                {
 
76
                        var input = @"
 
77
class TestClass
 
78
{
 
79
        void Foo()
 
80
        {
 
81
                string.Format(""{1}"", 1);
 
82
        }
 
83
}";
 
84
                        
 
85
                        TestRefactoringContext context;
 
86
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
87
                        Assert.AreEqual (1, issues.Count);
 
88
                }
 
89
                
 
90
                [Test]
 
91
                public void FormatItemMissingEndBrace()
 
92
                {
 
93
                        var input = @"
 
94
class TestClass
 
95
{
 
96
        void Foo()
 
97
        {
 
98
                string.Format(""Text text text {0 text text text"", 1);
 
99
        }
 
100
}";
 
101
 
 
102
                        TestRefactoringContext context;
 
103
                        var issues = GetIssues(new FormatStringIssue(), input, out context);
 
104
                        Assert.AreEqual(1, issues.Count);
 
105
                }
 
106
                        
 
107
                [Test]
 
108
                public void UnescapedLeftBrace()
 
109
                {
 
110
                                var input = @"
 
111
class TestClass
 
112
{
 
113
        void Foo()
 
114
        {
 
115
                string.Format(""a { a"", 1);
 
116
        }
 
117
}";
 
118
 
 
119
                        TestRefactoringContext context;
 
120
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
121
                        Assert.AreEqual (1, issues.Count);
 
122
                }
 
123
 
 
124
                [Test]
 
125
                public void IgnoresStringWithGoodArguments()
 
126
                {
 
127
                        var input = @"
 
128
class TestClass
 
129
{
 
130
        void Foo()
 
131
        {
 
132
                string.Format(""{0}"", ""arg0"");
 
133
        }
 
134
}";
 
135
                        
 
136
                        TestRefactoringContext context;
 
137
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
138
                        Assert.AreEqual (0, issues.Count);
 
139
                }
 
140
 
 
141
                [Test]
 
142
                public void IgnoresNonFormattingCall()
 
143
                {
 
144
                        var input = @"
 
145
class TestClass
 
146
{
 
147
        void Foo()
 
148
        {
 
149
                string lower = string.ToLower(""{0}"");
 
150
        }
 
151
}";
 
152
                        
 
153
                        TestRefactoringContext context;
 
154
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
155
                        Assert.AreEqual (0, issues.Count);
 
156
                }
 
157
                
 
158
                [Test]
 
159
                public void HandlesCallsWithExtraArguments()
 
160
                {
 
161
                        var input = @"
 
162
class TestClass
 
163
{
 
164
        void Foo()
 
165
        {
 
166
                Foo(1);
 
167
        }
 
168
}";
 
169
                        
 
170
                        TestRefactoringContext context;
 
171
                        var issues = GetIssues (new FormatStringIssue (), input, out context);
 
172
                        Assert.AreEqual (0, issues.Count);
 
173
                }
 
174
        }
 
175
}
 
176