Browse Source

Fixed unit test.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
af6ba7d756
  1. 11
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 51
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs

11
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -413,8 +413,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var contextList = new CompletionDataWrapper (this); var contextList = new CompletionDataWrapper (this);
var identifierStart = GetExpressionAtCursor (); var identifierStart = GetExpressionAtCursor ();
if (!(char.IsLetter (completionChar) || completionChar == '_') && (identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) if (!(char.IsLetter (completionChar) || completionChar == '_') && (!controlSpace || identifierStart == null || !(identifierStart.Item2 is ArrayInitializerExpression))) {
return controlSpace ? HandleAccessorContext () ?? DefaultControlSpaceItems () : null; return controlSpace ? HandleAccessorContext () ?? DefaultControlSpaceItems () : null;
}
char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : '\0'; char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : '\0';
char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' '; char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' ';
const string allowedChars = ";,[(){}+-*/%^?:&|~!<>="; const string allowedChars = ";,[(){}+-*/%^?:&|~!<>=";
@ -431,7 +433,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return null; return null;
} }
} }
if (identifierStart == null) if (identifierStart == null)
return HandleAccessorContext () ?? DefaultControlSpaceItems (); return HandleAccessorContext () ?? DefaultControlSpaceItems ();
@ -1596,8 +1597,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
} }
baseUnit = ParseStub ("a()"); baseUnit = ParseStub ("a()");
// Hack for handle object initializer continuation expressions
if (baseUnit.GetNodeAt (location) is AttributedNode) {
baseUnit = ParseStub ("a()};");
}
var memberLocation = currentMember != null ? currentMember.Region.Begin : currentType.Region.Begin; var memberLocation = currentMember != null ? currentMember.Region.Begin : currentType.Region.Begin;
var mref = baseUnit.GetNodeAt<MemberReferenceExpression> (location); var mref = baseUnit.GetNodeAt<MemberReferenceExpression> (location);
if (mref == null){ if (mref == null){
var invoke = baseUnit.GetNodeAt<InvocationExpression> (location); var invoke = baseUnit.GetNodeAt<InvocationExpression> (location);
if (invoke != null) if (invoke != null)

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

@ -185,7 +185,7 @@ class test {
public void testcc () public void testcc ()
{ {
foo f = new foo () { foo f = new foo () {
$$ $b$
}; };
} }
} }
@ -203,7 +203,7 @@ class test {
public void TestBug1745 () public void TestBug1745 ()
{ {
CodeCompletionBugTests.CombinedProviderTest ( CodeCompletionBugTests.CombinedProviderTest (
@"class Test { @"class Test {
public int TF1 { get; set; } public int TF1 { get; set; }
} }
@ -218,7 +218,52 @@ class CCTest {
Assert.IsNull (provider.Find ("TF1")); Assert.IsNull (provider.Find ("TF1"));
Assert.IsNotNull (provider.Find ("Test")); 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.");
});
}
} }
} }

Loading…
Cancel
Save