Browse Source

Normalize newlines

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
4ccc313d46
  1. 228
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/PreProcessorDirective.cs
  2. 4
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  3. 198
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/EnumContextTests.cs
  4. 472
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/KeywordTests.cs
  5. 536
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs
  6. 120
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/PreProcessorTests.cs
  7. 212
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/VariableDeclarationStatementTests.cs
  8. 94
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ContextActionTestBase.cs
  9. 417
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/TestRefactoringContext.cs
  10. 156
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/UseExplicitTypeTests.cs
  11. 158
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/UseVarKeywordTests.cs
  12. 7
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  13. 4
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  14. 3
      NRefactory.sln

228
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/PreProcessorDirective.cs

@ -1,114 +1,114 @@ @@ -1,114 +1,114 @@
//
// PreProcessorDirective.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public enum PreProcessorDirectiveType : byte
{
Invalid = 0,
Region = 1,
Endregion = 2,
If = 3,
Endif = 4,
Elif = 5,
Else = 6,
Define = 7,
Undef = 8,
Error = 9,
Warning = 10,
Pragma = 11,
Line = 12
}
public class PreProcessorDirective : AstNode, IRelocatable
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public PreProcessorDirectiveType Type {
get;
set;
}
public string Argument {
get;
set;
}
public bool Take {
get;
set;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
TextLocation endLocation;
public override TextLocation EndLocation {
get {
return endLocation;
}
}
public PreProcessorDirective (PreProcessorDirectiveType type, TextLocation startLocation, TextLocation endLocation)
{
this.Type = type;
this.startLocation = startLocation;
this.endLocation = endLocation;
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
{
int lineDelta = startLocation.Line - this.startLocation.Line;
endLocation = new TextLocation (endLocation.Line + lineDelta, lineDelta != 0 ? endLocation.Column : endLocation.Column + startLocation.Column - this.startLocation.Column);
this.startLocation = startLocation;
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
{
return visitor.VisitPreProcessorDirective (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
PreProcessorDirective o = other as PreProcessorDirective;
return o != null && Type == o.Type;
}
}
}
//
// PreProcessorDirective.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public enum PreProcessorDirectiveType : byte
{
Invalid = 0,
Region = 1,
Endregion = 2,
If = 3,
Endif = 4,
Elif = 5,
Else = 6,
Define = 7,
Undef = 8,
Error = 9,
Warning = 10,
Pragma = 11,
Line = 12
}
public class PreProcessorDirective : AstNode, IRelocatable
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public PreProcessorDirectiveType Type {
get;
set;
}
public string Argument {
get;
set;
}
public bool Take {
get;
set;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
TextLocation endLocation;
public override TextLocation EndLocation {
get {
return endLocation;
}
}
public PreProcessorDirective (PreProcessorDirectiveType type, TextLocation startLocation, TextLocation endLocation)
{
this.Type = type;
this.startLocation = startLocation;
this.endLocation = endLocation;
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
{
int lineDelta = startLocation.Line - this.startLocation.Line;
endLocation = new TextLocation (endLocation.Line + lineDelta, lineDelta != 0 ? endLocation.Column : endLocation.Column + startLocation.Column - this.startLocation.Column);
this.startLocation = startLocation;
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
{
return visitor.VisitPreProcessorDirective (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
PreProcessorDirective o = other as PreProcessorDirective;
return o != null && Type == o.Type;
}
}
}

4
ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -743,9 +743,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -743,9 +743,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
m.IsShadowing = (modifiers & Modifiers.New) != 0;
m.IsStatic = (modifiers & Modifiers.Static) != 0;
m.IsVirtual = (modifiers & Modifiers.Virtual) != 0;
m.IsPartial = (modifiers & Modifiers.Partial) != 0;
//m.IsPartial = (modifiers & Modifiers.Partial) != 0;
}
static Accessibility? GetAccessibility(Modifiers modifiers)

198
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/EnumContextTests.cs

@ -1,99 +1,99 @@ @@ -1,99 +1,99 @@
//
// EnumContextTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
[TestFixture()]
public class EnumContextTests : TestBase
{
/// <summary>
/// Bug 2142 - Enum member list triggers completion
/// </summary>
[Test()]
public void Test2142 ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"enum Name {
$p$
}
", provider => {
Assert.AreEqual (0, provider.Count);
});
}
[Test()]
public void TestEnumAssignment ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"enum Name {
Member
$, B = M$
}
", provider => {
Assert.IsNotNull (provider.Find ("Member"), "value 'Member' not found.");
Assert.IsNotNull (provider.Find ("Name"), "type 'Name' not found.");
});
}
[Test()]
public void TestEnumFlags ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
[Flags]
enum Name {
Flag1,
Flag2,
Combined = Flag1 $| F$
}
", provider => {
Assert.IsNotNull (provider.Find ("Flag1"), "value 'Flag1' not found.");
Assert.IsNotNull (provider.Find ("Flag2"), "value 'Flag2' not found.");
Assert.IsNotNull (provider.Find ("Name"), "type 'Name' not found.");
});
}
[Test()]
public void TestEnumInitializerContinuation ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
[Flags]
enum Name {
Flag1,
Flag2,
Combined $= Name.$
}
", provider => {
Assert.IsNotNull (provider.Find ("Flag1"), "value 'Flag1' not found.");
Assert.IsNotNull (provider.Find ("Flag2"), "value 'Flag2' not found.");
});
}
}
}
//
// EnumContextTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
[TestFixture()]
public class EnumContextTests : TestBase
{
/// <summary>
/// Bug 2142 - Enum member list triggers completion
/// </summary>
[Test()]
public void Test2142 ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"enum Name {
$p$
}
", provider => {
Assert.AreEqual (0, provider.Count);
});
}
[Test()]
public void TestEnumAssignment ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"enum Name {
Member
$, B = M$
}
", provider => {
Assert.IsNotNull (provider.Find ("Member"), "value 'Member' not found.");
Assert.IsNotNull (provider.Find ("Name"), "type 'Name' not found.");
});
}
[Test()]
public void TestEnumFlags ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
[Flags]
enum Name {
Flag1,
Flag2,
Combined = Flag1 $| F$
}
", provider => {
Assert.IsNotNull (provider.Find ("Flag1"), "value 'Flag1' not found.");
Assert.IsNotNull (provider.Find ("Flag2"), "value 'Flag2' not found.");
Assert.IsNotNull (provider.Find ("Name"), "type 'Name' not found.");
});
}
[Test()]
public void TestEnumInitializerContinuation ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
[Flags]
enum Name {
Flag1,
Flag2,
Combined $= Name.$
}
", provider => {
Assert.IsNotNull (provider.Find ("Flag1"), "value 'Flag1' not found.");
Assert.IsNotNull (provider.Find ("Flag2"), "value 'Flag2' not found.");
});
}
}
}

472
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/KeywordTests.cs

@ -1,236 +1,236 @@ @@ -1,236 +1,236 @@
//
// KeywordTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
[TestFixture()]
public class KeywordTests : TestBase
{
[Test()]
public void CaseKeywordTest ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class Class
{
void Test (string t)
{
switch (t) {
$c$
}
}
}
");
Assert.IsNotNull (provider, "provider == null");
Assert.IsNotNull (provider.Find ("case"), "keyword 'case' not found.");
}
[Test()]
public void CaseKeywordTestCase2 ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class Class
{
void Test (string t)
{
$c$
}
}
");
}
[Test()]
public void CaseKeywordTestCase3 ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class Class
{
void Test (string t)
{
switch (t) {
case ""test"":
$c$
}
}
}
");
Assert.IsNotNull (provider, "provider == null");
Assert.IsNotNull (provider.Find ("case"), "keyword 'case' not found.");
}
[Test()]
public void ModifierKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
$p$
", provider => {
Assert.IsNotNull (provider.Find ("public"), "keyword 'public' not found.");
Assert.IsNotNull (provider.Find ("namespace"), "keyword 'namespace' not found.");
});
}
[Test()]
public void ModifierKeywordTestCase2 ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
class Test
{
$p$
}
", provider => {
Assert.IsNotNull (provider.Find ("public"), "keyword 'public' not found.");
Assert.IsNull (provider.Find ("namespace"), "keyword 'namespace' found.");
});
}
[Test()]
public void GetSetKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class Test
{
public int MyProperty {
$g$
}
", provider => {
Assert.IsNotNull (provider.Find ("public"), "keyword 'public' not found.");
Assert.IsNotNull (provider.Find ("get"), "keyword 'get' not found.");
Assert.IsNotNull (provider.Find ("set"), "keyword 'set' not found.");
});
}
[Test()]
public void GetSetKeywordTestAfterModifier ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class Test
{
public int MyProperty {
internal $g$
}
", provider => {
Assert.IsNotNull (provider.Find ("get"), "keyword 'get' not found.");
Assert.IsNotNull (provider.Find ("set"), "keyword 'set' not found.");
});
}
[Test()]
public void AddRemoveKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
class Test
{
public event EventHandler MyProperty {
$g$
}
", (provider) => {
Assert.AreEqual (2, provider.Count);
Assert.IsNotNull (provider.Find ("add"), "keyword 'add' not found.");
Assert.IsNotNull (provider.Find ("remove"), "keyword 'remove' not found.");
});
}
[Ignore("needs to be fixed in parser.")]
[Test()]
public void IsAsKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
class Test
{
public void Method ()
{
void TestMe (object o)
{
if (o $i$
}
}
}
", (provider) => {
Assert.IsNotNull (provider, "provider == null");
Assert.IsNotNull (provider.Find ("is"), "keyword 'is' not found.");
Assert.IsNotNull (provider.Find ("as"), "keyword 'as' not found.");
});
}
[Test()]
public void PublicClassContextTest ()
{
CodeCompletionBugTests.CombinedProviderTest (@"$c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
Assert.IsNotNull (provider.Find ("static"), "keyword 'static' not found.");
Assert.IsNotNull (provider.Find ("sealed"), "keyword 'sealed' not found.");
});
}
[Ignore()]
[Test()]
public void PublicClassContextTest2 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"public $c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
Assert.IsNotNull (provider.Find ("static"), "keyword 'static' not found.");
Assert.IsNotNull (provider.Find ("sealed"), "keyword 'sealed' not found.");
});
}
[Ignore()]
[Test()]
public void PublicClassContextTestContinuation1 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"public static $c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
});
}
[Ignore()]
[Test()]
public void PublicClassContextTestContinuation2 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"public sealed $c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
});
}
}
}
//
// KeywordTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
[TestFixture()]
public class KeywordTests : TestBase
{
[Test()]
public void CaseKeywordTest ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class Class
{
void Test (string t)
{
switch (t) {
$c$
}
}
}
");
Assert.IsNotNull (provider, "provider == null");
Assert.IsNotNull (provider.Find ("case"), "keyword 'case' not found.");
}
[Test()]
public void CaseKeywordTestCase2 ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class Class
{
void Test (string t)
{
$c$
}
}
");
}
[Test()]
public void CaseKeywordTestCase3 ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class Class
{
void Test (string t)
{
switch (t) {
case ""test"":
$c$
}
}
}
");
Assert.IsNotNull (provider, "provider == null");
Assert.IsNotNull (provider.Find ("case"), "keyword 'case' not found.");
}
[Test()]
public void ModifierKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
$p$
", provider => {
Assert.IsNotNull (provider.Find ("public"), "keyword 'public' not found.");
Assert.IsNotNull (provider.Find ("namespace"), "keyword 'namespace' not found.");
});
}
[Test()]
public void ModifierKeywordTestCase2 ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
class Test
{
$p$
}
", provider => {
Assert.IsNotNull (provider.Find ("public"), "keyword 'public' not found.");
Assert.IsNull (provider.Find ("namespace"), "keyword 'namespace' found.");
});
}
[Test()]
public void GetSetKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class Test
{
public int MyProperty {
$g$
}
", provider => {
Assert.IsNotNull (provider.Find ("public"), "keyword 'public' not found.");
Assert.IsNotNull (provider.Find ("get"), "keyword 'get' not found.");
Assert.IsNotNull (provider.Find ("set"), "keyword 'set' not found.");
});
}
[Test()]
public void GetSetKeywordTestAfterModifier ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class Test
{
public int MyProperty {
internal $g$
}
", provider => {
Assert.IsNotNull (provider.Find ("get"), "keyword 'get' not found.");
Assert.IsNotNull (provider.Find ("set"), "keyword 'set' not found.");
});
}
[Test()]
public void AddRemoveKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
class Test
{
public event EventHandler MyProperty {
$g$
}
", (provider) => {
Assert.AreEqual (2, provider.Count);
Assert.IsNotNull (provider.Find ("add"), "keyword 'add' not found.");
Assert.IsNotNull (provider.Find ("remove"), "keyword 'remove' not found.");
});
}
[Ignore("needs to be fixed in parser.")]
[Test()]
public void IsAsKeywordTest ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
class Test
{
public void Method ()
{
void TestMe (object o)
{
if (o $i$
}
}
}
", (provider) => {
Assert.IsNotNull (provider, "provider == null");
Assert.IsNotNull (provider.Find ("is"), "keyword 'is' not found.");
Assert.IsNotNull (provider.Find ("as"), "keyword 'as' not found.");
});
}
[Test()]
public void PublicClassContextTest ()
{
CodeCompletionBugTests.CombinedProviderTest (@"$c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
Assert.IsNotNull (provider.Find ("static"), "keyword 'static' not found.");
Assert.IsNotNull (provider.Find ("sealed"), "keyword 'sealed' not found.");
});
}
[Ignore()]
[Test()]
public void PublicClassContextTest2 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"public $c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
Assert.IsNotNull (provider.Find ("static"), "keyword 'static' not found.");
Assert.IsNotNull (provider.Find ("sealed"), "keyword 'sealed' not found.");
});
}
[Ignore()]
[Test()]
public void PublicClassContextTestContinuation1 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"public static $c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
});
}
[Ignore()]
[Test()]
public void PublicClassContextTestContinuation2 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"public sealed $c$",
provider => {
Assert.IsNotNull (provider.Find ("class"), "keyword 'class' not found.");
});
}
}
}

536
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs

@ -1,269 +1,269 @@ @@ -1,269 +1,269 @@
//
// ObjectInitializerTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
public class ObjectInitializerTests : TestBase
{
/// <summary>
/// Bug 487236 - Object initializer completion uses wrong type
/// </summary>
[Test()]
public void TestBug487236 ()
{
CompletionDataList provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
public class A
{
public string Name { get; set; }
}
class MyTest
{
public void Test ()
{
$var x = new A () { $
}
}
");
Assert.IsNotNull (provider, "provider not found.");
Assert.IsNotNull (provider.Find ("Name"), "property 'Name' not found.");
}
/// <summary>
/// Bug 487236 - Object initializer completion uses wrong type
/// </summary>
[Test()]
public void TestBug487236B ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
public class A
{
public string Name { get; set; }
}
class MyTest
{
public void Test ()
{
$A x = new NotExists () { $
}
}
");
Assert.IsNotNull (provider, "provider not found.");
Assert.IsNull (provider.Find ("Name"), "property 'Name' found, but shouldn't'.");
}
[Test()]
public void TestField ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
public class A
{
public int Test;
}
class MyTest
{
public void Test ()
{
$new A () { T$
}
}
", provider => {
Assert.IsNotNull (provider.Find ("Test"), "field 'Test' not found.");
});
}
[Test()]
public void TestProperty ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
public class A
{
public int Test { get; set; }
}
class MyTest
{
public void Test ()
{
$new A () { T$
}
}
", provider => {
Assert.IsNotNull (provider.Find ("Test"), "property 'Test' not found.");
});
}
/// <summary>
/// Bug 526667 - wrong code completion in object initialisation (new O() {...};)
/// </summary>
[Test()]
public void TestBug526667 ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
using System;
using System.Collections.Generic;
public class O
{
public string X {
get;
set;
}
public string Y {
get;
set;
}
public List<string> Z {
get;
set;
}
public static O A ()
{
return new O {
X = ""x"",
Z = new List<string> (new string[] {
""abc"",
""def""
})
$, $
};
}
}
");
Assert.IsNotNull (provider, "provider not found.");
Assert.IsNotNull (provider.Find ("Y"), "property 'Y' not found.");
}
[Test()]
public void TestObjectInitializer ()
{
//
// ObjectInitializerTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
public class ObjectInitializerTests : TestBase
{
/// <summary>
/// Bug 487236 - Object initializer completion uses wrong type
/// </summary>
[Test()]
public void TestBug487236 ()
{
CompletionDataList provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
public class A
{
public string Name { get; set; }
}
class MyTest
{
public void Test ()
{
$var x = new A () { $
}
}
");
Assert.IsNotNull (provider, "provider not found.");
Assert.IsNotNull (provider.Find ("Name"), "property 'Name' not found.");
}
/// <summary>
/// Bug 487236 - Object initializer completion uses wrong type
/// </summary>
[Test()]
public void TestBug487236B ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
public class A
{
public string Name { get; set; }
}
class MyTest
{
public void Test ()
{
$A x = new NotExists () { $
}
}
");
Assert.IsNotNull (provider, "provider not found.");
Assert.IsNull (provider.Find ("Name"), "property 'Name' found, but shouldn't'.");
}
[Test()]
public void TestField ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class foo {
public string bar { get; set; }
public string baz { get; set; }
}
class test {
public void testcc ()
{
foo f = new foo () {
$b$
};
}
}
", provider => {
Assert.IsNotNull (provider.Find ("bar"), "property 'bar' not found.");
Assert.IsNotNull (provider.Find ("baz"), "property 'baz' not found.");
});
}
/// <summary>
/// Bug 1745 - [New Resolver] Invalid completion in class initialization
/// </summary>
[Test()]
public void TestBug1745 ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class Test {
public int TF1 { get; set; }
}
class CCTest {
void TestMethod ()
{
$new Test () { TF1 = T$
}
}
", provider => {
Assert.IsNull (provider.Find ("TF1"));
Assert.IsNotNull (provider.Find ("Test"));
});
}
[Test()]
public void TestBugAfterBracketContext ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"class Test {
public int TF1 { get; set; }
}
class CCTest {
void TestMethod ()
{
$new Test () {$
}
}
");
Assert.IsTrue (provider == null || provider.Count == 0);
}
/// <summary>
/// Bug 487236 - Object initializer completion uses wrong type
/// </summary>
[Test()]
public void TestObjectInitializerContinuation ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
public class A
{
public string Name { get; set; }
}
class MyTest
{
static string Str = ""hello"";
public void Test ()
{
$var x = new A () { Name = MyTest.$
}
}
", provider => {
Assert.IsNotNull (provider.Find ("Str"), "field 'Str' not found.");
});
}
}
}
@"
public class A
{
public int Test;
}
class MyTest
{
public void Test ()
{
$new A () { T$
}
}
", provider => {
Assert.IsNotNull (provider.Find ("Test"), "field 'Test' not found.");
});
}
[Test()]
public void TestProperty ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
public class A
{
public int Test { get; set; }
}
class MyTest
{
public void Test ()
{
$new A () { T$
}
}
", provider => {
Assert.IsNotNull (provider.Find ("Test"), "property 'Test' not found.");
});
}
/// <summary>
/// Bug 526667 - wrong code completion in object initialisation (new O() {...};)
/// </summary>
[Test()]
public void TestBug526667 ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
using System;
using System.Collections.Generic;
public class O
{
public string X {
get;
set;
}
public string Y {
get;
set;
}
public List<string> Z {
get;
set;
}
public static O A ()
{
return new O {
X = ""x"",
Z = new List<string> (new string[] {
""abc"",
""def""
})
$, $
};
}
}
");
Assert.IsNotNull (provider, "provider not found.");
Assert.IsNotNull (provider.Find ("Y"), "property 'Y' not found.");
}
[Test()]
public void TestObjectInitializer ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class foo {
public string bar { get; set; }
public string baz { get; set; }
}
class test {
public void testcc ()
{
foo f = new foo () {
$b$
};
}
}
", provider => {
Assert.IsNotNull (provider.Find ("bar"), "property 'bar' not found.");
Assert.IsNotNull (provider.Find ("baz"), "property 'baz' not found.");
});
}
/// <summary>
/// Bug 1745 - [New Resolver] Invalid completion in class initialization
/// </summary>
[Test()]
public void TestBug1745 ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"class Test {
public int TF1 { get; set; }
}
class CCTest {
void TestMethod ()
{
$new Test () { TF1 = T$
}
}
", provider => {
Assert.IsNull (provider.Find ("TF1"));
Assert.IsNotNull (provider.Find ("Test"));
});
}
[Test()]
public void TestBugAfterBracketContext ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"class Test {
public int TF1 { get; set; }
}
class CCTest {
void TestMethod ()
{
$new Test () {$
}
}
");
Assert.IsTrue (provider == null || provider.Count == 0);
}
/// <summary>
/// Bug 487236 - Object initializer completion uses wrong type
/// </summary>
[Test()]
public void TestObjectInitializerContinuation ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"
public class A
{
public string Name { get; set; }
}
class MyTest
{
static string Str = ""hello"";
public void Test ()
{
$var x = new A () { Name = MyTest.$
}
}
", provider => {
Assert.IsNotNull (provider.Find ("Str"), "field 'Str' not found.");
});
}
}
}

120
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/PreProcessorTests.cs

@ -1,60 +1,60 @@ @@ -1,60 +1,60 @@
//
// PreProcessorTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
public class PreProcessorTests: TestBase
{
[Test()]
public void TestPreProcessorContext ()
{
CodeCompletionBugTests.CombinedProviderTest (@"$#$", provider => {
Assert.IsNotNull (provider.Find ("if"), "directive 'if' not found.");
Assert.IsNotNull (provider.Find ("region"), "directive 'region' not found.");
});
}
[Test()]
public void TestPreProcessorContext2 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"// $#$", provider => {
Assert.IsNull (provider.Find ("if"), "directive 'if' not found.");
Assert.IsNull (provider.Find ("region"), "directive 'region' not found.");
});
}
[Test()]
public void TestIfContext ()
{
CodeCompletionBugTests.CombinedProviderTest (@"$#if $", provider => {
Assert.IsNotNull (provider.Find ("DEBUG"), "define 'DEBUG' not found.");
});
}
}
}
//
// PreProcessorTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
public class PreProcessorTests: TestBase
{
[Test()]
public void TestPreProcessorContext ()
{
CodeCompletionBugTests.CombinedProviderTest (@"$#$", provider => {
Assert.IsNotNull (provider.Find ("if"), "directive 'if' not found.");
Assert.IsNotNull (provider.Find ("region"), "directive 'region' not found.");
});
}
[Test()]
public void TestPreProcessorContext2 ()
{
CodeCompletionBugTests.CombinedProviderTest (@"// $#$", provider => {
Assert.IsNull (provider.Find ("if"), "directive 'if' not found.");
Assert.IsNull (provider.Find ("region"), "directive 'region' not found.");
});
}
[Test()]
public void TestIfContext ()
{
CodeCompletionBugTests.CombinedProviderTest (@"$#if $", provider => {
Assert.IsNotNull (provider.Find ("DEBUG"), "define 'DEBUG' not found.");
});
}
}
}

212
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/VariableDeclarationStatementTests.cs

@ -1,106 +1,106 @@ @@ -1,106 +1,106 @@
//
// VariableDeclarationStatementTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
public class VariableDeclarationStatementTests : TestBase
{
[Test()]
public void TestDefaultBehavior ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class MyTest
{
public void Test ()
{
$var v$
}
}
");
Assert.IsTrue (provider == null || provider.Count == 0, "provider should be empty.");
}
[Test()]
public void TestIntNameProposal ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
class MyTest
{
public void Test ()
{
$int $
}
}
");
Assert.IsNotNull (provider.Find ("i"), "name proposal 'i' not found.");
Assert.IsNotNull (provider.Find ("j"), "name proposal 'j' not found.");
Assert.IsNotNull (provider.Find ("k"), "name proposal 'k' not found.");
}
[Test()]
public void TestNameProposal ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
class MyTest
{
public void Test ()
{
$MyTest $
}
}
");
Assert.IsNotNull (provider.Find ("myTest"), "name proposal 'myTest' not found.");
Assert.IsNotNull (provider.Find ("test"), "name proposal 'test' not found.");
}
/// <summary>
/// Bug 1799 - [New Resolver] Invalid code completion when typing name of variable
/// </summary>
[Test()]
public void TestBug1799 ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class MyTest
{
public void Test ()
{
for (int n=0;n<10;n++) {
$string d$
}
}
}
");
Assert.IsTrue (provider == null || provider.Count == 0, "provider should be empty.");
}
}
}
//
// VariableDeclarationStatementTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
public class VariableDeclarationStatementTests : TestBase
{
[Test()]
public void TestDefaultBehavior ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class MyTest
{
public void Test ()
{
$var v$
}
}
");
Assert.IsTrue (provider == null || provider.Count == 0, "provider should be empty.");
}
[Test()]
public void TestIntNameProposal ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
class MyTest
{
public void Test ()
{
$int $
}
}
");
Assert.IsNotNull (provider.Find ("i"), "name proposal 'i' not found.");
Assert.IsNotNull (provider.Find ("j"), "name proposal 'j' not found.");
Assert.IsNotNull (provider.Find ("k"), "name proposal 'k' not found.");
}
[Test()]
public void TestNameProposal ()
{
var provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
@"
class MyTest
{
public void Test ()
{
$MyTest $
}
}
");
Assert.IsNotNull (provider.Find ("myTest"), "name proposal 'myTest' not found.");
Assert.IsNotNull (provider.Find ("test"), "name proposal 'test' not found.");
}
/// <summary>
/// Bug 1799 - [New Resolver] Invalid code completion when typing name of variable
/// </summary>
[Test()]
public void TestBug1799 ()
{
var provider = CodeCompletionBugTests.CreateProvider (
@"
class MyTest
{
public void Test ()
{
for (int n=0;n<10;n++) {
$string d$
}
}
}
");
Assert.IsTrue (provider == null || provider.Count == 0, "provider should be empty.");
}
}
}

94
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ContextActionTestBase.cs

@ -1,48 +1,48 @@ @@ -1,48 +1,48 @@
//
// ContextActionTestBase.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
public abstract class ContextActionTestBase
//
// ContextActionTestBase.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
public abstract class ContextActionTestBase
{
protected static string RunContextAction (IContextAction action, string input)
{
var context = new TestRefactoringContext (input);
if (!action.IsValid (context))
Console.WriteLine ("invalid node is:" + context.GetNode ());
Assert.IsTrue (action.IsValid (context), action.GetType () + " is invalid.");
action.Run (context);
return context.doc.Text;
}
}
}
protected static string RunContextAction (IContextAction action, string input)
{
var context = new TestRefactoringContext (input);
if (!action.IsValid (context))
Console.WriteLine ("invalid node is:" + context.GetNode ());
Assert.IsTrue (action.IsValid (context), action.GetType () + " is invalid.");
action.Run (context);
return context.doc.Text;
}
}
}

417
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/TestRefactoringContext.cs

@ -1,211 +1,208 @@ @@ -1,211 +1,208 @@
//
// TestRefactoringContext.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.FormattingTests;
using System.Linq;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
class TestRefactoringContext : RefactoringContext
{
internal IDocument doc;
CSharpParsedFile file;
SimpleProjectContent ctx = new SimpleProjectContent ();
public override ITypeResolveContext TypeResolveContext {
get {
return ctx;
}
}
public override bool HasCSharp3Support {
get {
return true;
}
}
public override CSharpFormattingOptions FormattingOptions {
get {
return new CSharpFormattingOptions ();
}
}
public override AstType CreateShortType (IType fullType)
{
var csResolver = new CSharpResolver (TypeResolveContext, System.Threading.CancellationToken.None);
csResolver.CurrentMember = file.GetMember (Location);
csResolver.CurrentTypeDefinition = file.GetInnermostTypeDefinition (Location);
csResolver.CurrentUsingScope = file.GetUsingScope (Location);
var builder = new TypeSystemAstBuilder (csResolver);
return builder.ConvertType (fullType);
}
public override void ReplaceReferences (IMember member, MemberDeclaration replaceWidth)
{
throw new NotImplementedException ();
}
class MyScript : Script
{
TestRefactoringContext trc;
public MyScript (TestRefactoringContext trc) : base (trc)
{
this.trc = trc;
}
public override void Dispose ()
{
trc.doc = new ReadOnlyDocument (TestBase.ApplyChanges (trc.doc.Text, new List<TextReplaceAction> (Actions.Cast<TextReplaceAction>())));
}
public override void InsertWithCursor (string operation, AstNode node, InsertPosition defaultPosition)
{
throw new NotImplementedException ();
}
}
public override Script StartScript ()
{
return new MyScript (this);
}
#region Text stuff
public override string EolMarker { get { return Environment.NewLine; } }
public override bool IsSomethingSelected { get { return SelectionStart >= 0; } }
public override string SelectedText { get { return IsSomethingSelected ? doc.GetText (SelectionStart, SelectionLength) : ""; } }
int selectionStart;
public override int SelectionStart { get { return selectionStart; } }
int selectionEnd;
public override int SelectionEnd { get { return selectionEnd; } }
public override int SelectionLength { get { return IsSomethingSelected ? SelectionEnd - SelectionStart : 0; } }
public override int GetOffset (TextLocation location)
{
return doc.GetOffset (location);
}
public override TextLocation GetLocation (int offset)
{
return doc.GetLocation (offset);
}
public override string GetText (int offset, int length)
{
return doc.GetText (offset, length);
}
#endregion
#region Resolving
public override ResolveResult Resolve (AstNode node)
{
var csResolver = new CSharpResolver (TypeResolveContext, System.Threading.CancellationToken.None);
var navigator = new NodeListResolveVisitorNavigator (new[] { node });
var visitor = new ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor (csResolver, file, navigator);
visitor.Scan (Unit);
return visitor.GetResolveResult (node);
}
#endregion
public TestRefactoringContext (string content)
{
int idx = content.IndexOf ("$");
//
// TestRefactoringContext.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.FormattingTests;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
class TestRefactoringContext : RefactoringContext
{
internal IDocument doc;
CSharpParsedFile parsedFile;
ICompilation compilation;
CSharpAstResolver resolver;
public override bool HasCSharp3Support {
get {
return true;
}
}
public override CSharpFormattingOptions FormattingOptions {
get {
return new CSharpFormattingOptions ();
}
}
public override AstType CreateShortType (IType fullType)
{
throw new NotImplementedException();
/*var csResolver = new CSharpResolver (TypeResolveContext, System.Threading.CancellationToken.None);
csResolver.CurrentMember = file.GetMember (Location);
csResolver.CurrentTypeDefinition = file.GetInnermostTypeDefinition (Location);
csResolver.CurrentUsingScope = file.GetUsingScope (Location);
var builder = new TypeSystemAstBuilder (csResolver);
return builder.ConvertType (fullType);*/
}
public override void ReplaceReferences (IMember member, MemberDeclaration replaceWidth)
{
throw new NotImplementedException ();
}
class MyScript : Script
{
TestRefactoringContext trc;
public MyScript (TestRefactoringContext trc) : base (trc)
{
this.trc = trc;
}
public override void Dispose ()
{
trc.doc = new ReadOnlyDocument (TestBase.ApplyChanges (trc.doc.Text, new List<TextReplaceAction> (Actions.Cast<TextReplaceAction>())));
}
public override void InsertWithCursor (string operation, AstNode node, InsertPosition defaultPosition)
{
throw new NotImplementedException ();
}
}
public override Script StartScript ()
{
return new MyScript (this);
}
#region Text stuff
public override string EolMarker { get { return Environment.NewLine; } }
public override bool IsSomethingSelected { get { return SelectionStart >= 0; } }
public override string SelectedText { get { return IsSomethingSelected ? doc.GetText (SelectionStart, SelectionLength) : ""; } }
int selectionStart;
public override int SelectionStart { get { return selectionStart; } }
int selectionEnd;
public override int SelectionEnd { get { return selectionEnd; } }
public override int SelectionLength { get { return IsSomethingSelected ? SelectionEnd - SelectionStart : 0; } }
public override int GetOffset (TextLocation location)
{
return doc.GetOffset (location);
}
public override TextLocation GetLocation (int offset)
{
return doc.GetLocation (offset);
}
public override string GetText (int offset, int length)
{
return doc.GetText (offset, length);
}
#endregion
#region Resolving
public override ResolveResult Resolve (AstNode node)
{
return resolver.Resolve(node);
}
#endregion
public TestRefactoringContext (string content)
{
int idx = content.IndexOf ("$");
if (idx >= 0)
content = content.Substring (0, idx) + content.Substring (idx + 1);
doc = new ReadOnlyDocument (content);
var parser = new CSharpParser ();
Unit = parser.Parse (content);
if (parser.HasErrors)
parser.ErrorPrinter.Errors.ForEach (e => Console.WriteLine (e.Message));
Assert.IsFalse (parser.HasErrors, "File contains parsing errors.");
file = new TypeSystemConvertVisitor (ctx, "program.cs").Convert (Unit);
ctx.UpdateProjectContent (null, file);
if (idx >= 0)
Location = doc.GetLocation (idx);
}
internal static void Print (AstNode node)
{
var v = new CSharpOutputVisitor (Console.Out, new CSharpFormattingOptions ());
node.AcceptVisitor (v, null);
}
#region IActionFactory implementation
public override TextReplaceAction CreateTextReplaceAction (int offset, int removedChars, string insertedText)
{
return new TestBase.TestTextReplaceAction (offset, removedChars, insertedText);
}
public override NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output)
{
return new TestNodeOutputAction (offset, removedChars, output);
}
public override NodeSelectionAction CreateNodeSelectionAction (AstNode node)
{
throw new NotImplementedException ();
}
public override FormatTextAction CreateFormatTextAction (Func<RefactoringContext, AstNode> callback)
{
throw new NotImplementedException ();
}
public override CreateLinkAction CreateLinkAction (IEnumerable<AstNode> linkedNodes)
{
throw new NotImplementedException ();
}
public class TestNodeOutputAction : NodeOutputAction
{
public TestNodeOutputAction (int offset, int removedChars, NodeOutput output) : base (offset, removedChars, output)
{
}
public override void Perform (Script script)
{
}
}
#endregion
}
}
content = content.Substring (0, idx) + content.Substring (idx + 1);
doc = new ReadOnlyDocument (content);
var parser = new CSharpParser ();
Unit = parser.Parse (content, "program.cs");
if (parser.HasErrors)
parser.ErrorPrinter.Errors.ForEach (e => Console.WriteLine (e.Message));
Assert.IsFalse (parser.HasErrors, "File contains parsing errors.");
parsedFile = Unit.ToTypeSystem();
IProjectContent pc = new CSharpProjectContent();
pc = pc.UpdateProjectContent(null, parsedFile);
pc = pc.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
compilation = pc.CreateCompilation();
resolver = new CSharpAstResolver(compilation, Unit, parsedFile);
if (idx >= 0)
Location = doc.GetLocation (idx);
}
internal static void Print (AstNode node)
{
var v = new CSharpOutputVisitor (Console.Out, new CSharpFormattingOptions ());
node.AcceptVisitor (v, null);
}
#region IActionFactory implementation
public override TextReplaceAction CreateTextReplaceAction (int offset, int removedChars, string insertedText)
{
return new TestBase.TestTextReplaceAction (offset, removedChars, insertedText);
}
public override NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output)
{
return new TestNodeOutputAction (offset, removedChars, output);
}
public override NodeSelectionAction CreateNodeSelectionAction (AstNode node)
{
throw new NotImplementedException ();
}
public override FormatTextAction CreateFormatTextAction (Func<RefactoringContext, AstNode> callback)
{
throw new NotImplementedException ();
}
public override CreateLinkAction CreateLinkAction (IEnumerable<AstNode> linkedNodes)
{
throw new NotImplementedException ();
}
public class TestNodeOutputAction : NodeOutputAction
{
public TestNodeOutputAction (int offset, int removedChars, NodeOutput output) : base (offset, removedChars, output)
{
}
public override void Perform (Script script)
{
}
}
#endregion
}
}

156
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/UseExplicitTypeTests.cs

@ -1,78 +1,78 @@ @@ -1,78 +1,78 @@
//
// UseVarKeywordTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class UseExplicitTypeTests : ContextActionTestBase
{
[Test()]
public void SimpleVarDeclaration ()
{
string result = RunContextAction (new UseExplicitType (),
@"class TestClass
{
void Test ()
{
$var aVar = this;
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
TestClass aVar = this;
}
}", result);
}
[Test()]
public void ForeachDeclaration ()
{
string result = RunContextAction (new UseExplicitType (),
@"class TestClass
{
void Test ()
{
foreach ($var aVar in new TestClass[] { }) {
}
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
foreach (TestClass aVar in new TestClass[] { }) {
}
}
}", result);
}
}
}
//
// UseVarKeywordTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class UseExplicitTypeTests : ContextActionTestBase
{
[Test()]
public void SimpleVarDeclaration ()
{
string result = RunContextAction (new UseExplicitType (),
@"class TestClass
{
void Test ()
{
$var aVar = this;
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
TestClass aVar = this;
}
}", result);
}
[Test()]
public void ForeachDeclaration ()
{
string result = RunContextAction (new UseExplicitType (),
@"class TestClass
{
void Test ()
{
foreach ($var aVar in new TestClass[] { }) {
}
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
foreach (TestClass aVar in new TestClass[] { }) {
}
}
}", result);
}
}
}

158
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/UseVarKeywordTests.cs

@ -1,79 +1,79 @@ @@ -1,79 +1,79 @@
//
// UseVarKeywordTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class UseVarKeywordTests : ContextActionTestBase
{
[Test()]
public void SimpleVarDeclaration ()
{
string result = RunContextAction (new UseVarKeyword (),
@"class TestClass
{
void Test ()
{
$TestClass aVar = this;
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
var aVar = this;
}
}", result);
}
[Test()]
public void ForeachDeclaration ()
{
string result = RunContextAction (new UseVarKeyword (),
@"class TestClass
{
void Test ()
{
foreach ($TestClass aVar in this) {
}
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
foreach (var aVar in this) {
}
}
}", result);
}
}
}
//
// UseVarKeywordTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class UseVarKeywordTests : ContextActionTestBase
{
[Test()]
public void SimpleVarDeclaration ()
{
string result = RunContextAction (new UseVarKeyword (),
@"class TestClass
{
void Test ()
{
$TestClass aVar = this;
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
var aVar = this;
}
}", result);
}
[Test()]
public void ForeachDeclaration ()
{
string result = RunContextAction (new UseVarKeyword (),
@"class TestClass
{
void Test ()
{
foreach ($TestClass aVar in this) {
}
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
foreach (var aVar in this) {
}
}
}", result);
}
}
}

7
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{63D3B27A-D966-4902-90B3-30290E1692F1}</ProjectGuid>
@ -187,15 +187,10 @@ @@ -187,15 +187,10 @@
<Compile Include="Utils\TreeTraversalTests.cs" />
<Compile Include="FormattingTests\TextEditorTestAdapter.cs" />
<Compile Include="FormattingTests\TestBlankLineFormatting.cs" />
<Compile Include="CSharp\CodeCompletion\KeywordTests.cs" />
<Compile Include="CSharp\CodeCompletion\ObjectInitializerTests.cs" />
<Compile Include="CSharp\CodeCompletion\VariableDeclarationStatementTests.cs" />
<Compile Include="CSharp\CodeCompletion\PreProcessorTests.cs" />
<Compile Include="CSharp\ContextAction\UseVarKeywordTests.cs" />
<Compile Include="CSharp\ContextAction\TestRefactoringContext.cs" />
<Compile Include="CSharp\ContextAction\ContextActionTestBase.cs" />
<Compile Include="CSharp\ContextAction\UseExplicitTypeTests.cs" />
<Compile Include="CSharp\CodeCompletion\EnumContextTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">

4
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</ProjectGuid>
@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
<RunCodeAnalysis>False</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1026;-Microsoft.Security#CA2104</CodeAnalysisRules>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
<DocumentationFile>bin\Release\ICSharpCode.NRefactory.xml</DocumentationFile>

3
NRefactory.sln

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.2.0.8212-alpha
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DC98210E-1646-483B-819A-2BB8272461E4}"
ProjectSection(SolutionItems) = preProject
README = README
@ -86,8 +87,6 @@ Global @@ -86,8 +87,6 @@ Global
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.ActiveCfg = net_4_0_Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.Build.0 = net_4_0_Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ICSharpCode.NRefactory.Demo\ICSharpCode.NRefactory.Demo.csproj
EndGlobalSection

Loading…
Cancel
Save