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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantNullCheckTests.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
// RedundantNullCheckTests.cs
 
3
//  
 
4
// Author:
 
5
//       Ji Kun <jikun.nus@gmail.com>
 
6
// 
 
7
// Copyright (c) 2013 Ji Kun
 
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
using ICSharpCode.NRefactory.CSharp.CodeActions;
 
30
 
 
31
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
 
32
{
 
33
        [TestFixture]
 
34
        public class RedundantNullCheckTests : InspectionActionTestBase
 
35
        {
 
36
                [Test]
 
37
                public void TestInspectorCase1()
 
38
                {
 
39
                        var input = @"using System;class Test {public void test(){int a = 0;if(a is int && a != null){a = 1;}}}";
 
40
 
 
41
                        TestRefactoringContext context;
 
42
                        var issues = GetIssues(new RedundantNullCheckIssue(), input, out context);
 
43
                        Assert.AreEqual(1, issues.Count);
 
44
 
 
45
                        
 
46
                        CheckFix(context, issues, @"using System;class Test {public void test(){int a = 0;
 
47
                if (a is int) {
 
48
                        a = 1;
 
49
                }}}");
 
50
                }
 
51
 
 
52
                [Test]
 
53
                public void TestResharperDisable()
 
54
                {
 
55
                        var input = @"using System;
 
56
class Test {
 
57
        public void test(){
 
58
        int a = 0;
 
59
        //Resharper disable RedundantNullCheck
 
60
        if(a is int && a != null)
 
61
        {a = 1;}
 
62
        //Resharper restore RedundantNullCheck
 
63
        }       
 
64
        }";
 
65
                        
 
66
                        TestRefactoringContext context;
 
67
                        var issues = GetIssues(new RedundantNullCheckIssue(), input, out context);
 
68
                        Assert.AreEqual(0, issues.Count);
 
69
                }
 
70
 
 
71
                [Test]
 
72
                public void TestInspectorCase2()
 
73
                {
 
74
                        var input = @"using System;class Test {public void test(){int a = 0;while(a != null && a is int){a = 1;}}}";
 
75
 
 
76
                        TestRefactoringContext context;
 
77
                        var issues = GetIssues(new RedundantNullCheckIssue(), input, out context);
 
78
                        Assert.AreEqual(1, issues.Count);
 
79
                        CheckFix(context, issues, @"using System;class Test {public void test(){int a = 0;
 
80
                while (a is int) {
 
81
                        a = 1;
 
82
                }}}");
 
83
                }
 
84
 
 
85
                [Ignore("Missing")]
 
86
                [Test]
 
87
                public void TestCaseWithFullParens()
 
88
                {
 
89
                        var input = 
 
90
                                @"using System;
 
91
class TestClass
 
92
{
 
93
        public void Test(object o)
 
94
        {
 
95
                if (!((o is int) && (o != null))) {
 
96
                }
 
97
        }
 
98
}";
 
99
 
 
100
                        TestRefactoringContext context;
 
101
                        var issues = GetIssues(new RedundantNullCheckIssue(), input, out context);
 
102
                        Assert.AreEqual(1, issues.Count);
 
103
                        CheckFix(context, issues, @"using System;
 
104
class TestClass
 
105
{
 
106
        public void Test(object o)
 
107
        {
 
108
                if (!(o is int)) {
 
109
                }
 
110
        }
 
111
}");
 
112
                }
 
113
 
 
114
                [Ignore("Extended version")]
 
115
                [Test]
 
116
                public void TestNegatedCase()
 
117
                {
 
118
                        var input = 
 
119
                                @"using System;
 
120
class TestClass
 
121
{
 
122
        public void Test(object o)
 
123
        {
 
124
                if (null == o || !(o is int)) {
 
125
                }
 
126
        }
 
127
}";
 
128
 
 
129
                        TestRefactoringContext context;
 
130
                        var issues = GetIssues(new RedundantNullCheckIssue(), input, out context);
 
131
                        Assert.AreEqual(1, issues.Count);
 
132
                        CheckFix(context, issues, @"using System;
 
133
class TestClass
 
134
{
 
135
        public void Test(object o)
 
136
        {
 
137
                if (!(o is int)) {
 
138
                }
 
139
        }
 
140
}");
 
141
                }
 
142
        }
 
143
}
 
 
b'\\ No newline at end of file'