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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ParameterCanBeDemotedIssue/SupportsIndexingCriterionTests.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
// SupportsIndexingCriterionTests.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 System;
 
27
using NUnit.Framework;
 
28
using ICSharpCode.NRefactory.CSharp.CodeActions;
 
29
using ICSharpCode.NRefactory.TypeSystem;
 
30
using System.Collections.Generic;
 
31
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
32
using ICSharpCode.NRefactory.CSharp.Resolver;
 
33
 
 
34
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
 
35
{
 
36
        [TestFixture]
 
37
        public class SupportsIndexingCriterionTests
 
38
        {
 
39
                ITypeResolveContext typeResolveContext;
 
40
 
 
41
                IType intType;
 
42
 
 
43
                ICompilation compilation;
 
44
 
 
45
                [SetUp]
 
46
                public void SetUp()
 
47
                {
 
48
                        compilation = TestRefactoringContext.Create("").Compilation;
 
49
                        typeResolveContext = compilation.TypeResolveContext;
 
50
                        intType = GetIType<int>();
 
51
                }
 
52
 
 
53
                IType GetIType<T>()
 
54
                {
 
55
                        return typeof(T).ToTypeReference().Resolve(typeResolveContext);
 
56
                }
 
57
                
 
58
                void AssertMatches(IType candidateType, IType elementType, bool isWriteAccess, params IType[] indexTypes)
 
59
                {
 
60
                        var criterion = new SupportsIndexingCriterion(elementType, indexTypes, CSharpConversions.Get(compilation), isWriteAccess);
 
61
                        Assert.IsTrue(criterion.SatisfiedBy(candidateType));
 
62
                }
 
63
                
 
64
                void AssertDoesNotMatch(IType candidateType, IType elementType, bool isWriteAccess, params IType[] indexTypes)
 
65
                {
 
66
                        var criterion = new SupportsIndexingCriterion(elementType, indexTypes, CSharpConversions.Get(compilation), isWriteAccess);
 
67
                        Assert.IsFalse(criterion.SatisfiedBy(candidateType));
 
68
                }
 
69
                
 
70
                [Test]
 
71
                public void ListWithOneIntegerIndex()
 
72
                {
 
73
                        var intListType = GetIType<IList<int>>();
 
74
                        AssertMatches(intListType, intType, false, intType);
 
75
                        AssertMatches(intListType, intType, true, intType);
 
76
                }
 
77
 
 
78
                [Test]
 
79
                public void ListWithTwoIntegerIndexes()
 
80
                {
 
81
                        var intListType = GetIType<IList<int>>();
 
82
                        AssertDoesNotMatch(intListType, intType, false, intType, intType);
 
83
                        AssertDoesNotMatch(intListType, intType, true, intType, intType);
 
84
                }
 
85
                
 
86
                [Test]
 
87
                public void ObjectCandidate()
 
88
                {
 
89
                        AssertDoesNotMatch(GetIType<object>(), intType, false, intType);
 
90
                        AssertDoesNotMatch(GetIType<object>(), intType, true, intType);
 
91
                }
 
92
        }
 
93
}
 
94