2
// FormatStringIssueTests.cs
5
// Simon Lindgren <simon.n.lindgren@gmail.com>
7
// Copyright (c) 2012 Simon Lindgren
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
26
using NUnit.Framework;
27
using ICSharpCode.NRefactory.CSharp.CodeActions;
28
using ICSharpCode.NRefactory.CSharp.Refactoring;
30
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
33
public class FormatStringTests : InspectionActionTestBase
36
public void TooFewArguments()
43
string.Format(""{0}"");
47
TestRefactoringContext context;
48
var issues = GetIssues (new FormatStringIssue (), input, out context);
49
Assert.AreEqual (1, issues.Count);
53
public void SupportsFixedArguments()
63
void Bar(string format, string arg0)
68
TestRefactoringContext context;
69
var issues = GetIssues (new FormatStringIssue (), input, out context);
70
Assert.AreEqual (0, issues.Count);
74
public void FormatItemIndexOutOfRangeOfArguments()
81
string.Format(""{1}"", 1);
85
TestRefactoringContext context;
86
var issues = GetIssues (new FormatStringIssue (), input, out context);
87
Assert.AreEqual (1, issues.Count);
91
public void FormatItemMissingEndBrace()
98
string.Format(""Text text text {0 text text text"", 1);
102
TestRefactoringContext context;
103
var issues = GetIssues(new FormatStringIssue(), input, out context);
104
Assert.AreEqual(1, issues.Count);
108
public void UnescapedLeftBrace()
115
string.Format(""a { a"", 1);
119
TestRefactoringContext context;
120
var issues = GetIssues (new FormatStringIssue (), input, out context);
121
Assert.AreEqual (1, issues.Count);
125
public void IgnoresStringWithGoodArguments()
132
string.Format(""{0}"", ""arg0"");
136
TestRefactoringContext context;
137
var issues = GetIssues (new FormatStringIssue (), input, out context);
138
Assert.AreEqual (0, issues.Count);
142
public void IgnoresNonFormattingCall()
149
string lower = string.ToLower(""{0}"");
153
TestRefactoringContext context;
154
var issues = GetIssues (new FormatStringIssue (), input, out context);
155
Assert.AreEqual (0, issues.Count);
159
public void HandlesCallsWithExtraArguments()
170
TestRefactoringContext context;
171
var issues = GetIssues (new FormatStringIssue (), input, out context);
172
Assert.AreEqual (0, issues.Count);