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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/Analysis/AbiComparerTests.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
// AbiComparerTests.cs
 
3
//
 
4
// Author:
 
5
//       Mike Krüger <mkrueger@xamarin.com>
 
6
//
 
7
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
 
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
 
 
27
using System;
 
28
using System.IO;
 
29
using System.Linq;
 
30
using System.Threading;
 
31
using ICSharpCode.NRefactory.CSharp.Resolver;
 
32
using ICSharpCode.NRefactory.TypeSystem;
 
33
using ICSharpCode.NRefactory.TypeSystem.Implementation;
 
34
using NUnit.Framework;
 
35
using ICSharpCode.NRefactory.CSharp.CodeCompletion;
 
36
 
 
37
namespace ICSharpCode.NRefactory.CSharp.Analysis
 
38
{
 
39
        [TestFixture]
 
40
        public class AbiComparerTests
 
41
        {
 
42
                AbiCompatibility Check (string before, string after)
 
43
                {
 
44
                        IProjectContent oldPctx, newPctx;
 
45
                        SyntaxTree tree;
 
46
                        ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpUnresolvedFile file;
 
47
                        CodeCompletionBugTests.CreateCompilation (before, out oldPctx, out tree, out file, false);
 
48
                        CodeCompletionBugTests.CreateCompilation (after, out newPctx, out tree, out file, false);
 
49
                        return new AbiComparer ().Check (oldPctx.CreateCompilation (), newPctx.CreateCompilation ());
 
50
                }
 
51
 
 
52
                [Test]
 
53
                public void CheckEquality()
 
54
                {
 
55
                        string a1 = @"namespace Foo { public class Bar { public void FooBar () {} public int Bar2 { get; set;} int removed; } class Removed {} }";
 
56
                        string a2 = @"namespace Foo { public class Bar { public void FooBar () {} public int Bar2 { get {} set{}} void Added () {} } class Added {} } namespace Added { class Test { } }";
 
57
                        Assert.AreEqual (AbiCompatibility.Equal, Check (a1, a2));
 
58
                }
 
59
 
 
60
                [Test]
 
61
                public void CheckBigger()
 
62
                {
 
63
                        string a1 = @"namespace Foo { public class Bar { public void FooBar () {} } }";
 
64
                        string a2 = @"namespace Foo { public class Bar { public void FooBar () {} public void BarFoo () {} } }";
 
65
                        Assert.AreEqual (AbiCompatibility.Bigger, Check (a1, a2));
 
66
                }
 
67
 
 
68
                [Test]
 
69
                public void CheckIncompatible()
 
70
                {
 
71
                        string a1 = @"namespace Foo { public class Bar { public void FooBar () {} } }";
 
72
                        string a2 = @"namespace Foo { public class Bar { public void FooBar (int bar) {} } }";
 
73
                        Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
 
74
                }
 
75
 
 
76
                [Test]
 
77
                public void CheckIncompatibleInterfaceChange()
 
78
                {
 
79
                        string a1 = @"public interface IFoo {}";
 
80
                        string a2 = @"public interface IFoo { void Bar (); }";
 
81
                        Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
 
82
                }
 
83
 
 
84
                [Test]
 
85
                public void CheckTypeConstraintChange()
 
86
                {
 
87
                        string a1 = @"public class IFoo<T> {}";
 
88
                        string a2 = @"public class IFoo<T> where T : System.IDisposable {}";
 
89
                        Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
 
90
                }
 
91
 
 
92
                [Test]
 
93
                public void CheckTypeConstraintChangeCase2()
 
94
                {
 
95
                        string a1 = @"public class IFoo<T> {}";
 
96
                        string a2 = @"public class IFoo<T> where T : class {}";
 
97
                        Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
 
98
                }
 
99
 
 
100
                [Test]
 
101
                public void CheckMethodConstraintChange()
 
102
                {
 
103
                        string a1 = @"public class IFoo { public void Bar<T> () {} }";
 
104
                        string a2 = @"public class IFoo { public void Bar<T> () where T : System.IDisposable {} }";
 
105
                        Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
 
106
                }
 
107
        }
 
108
}