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 @@ -413,8 +413,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var contextList = new CompletionDataWrapper (this);
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;
}
char prevCh = offset > 2 ? document.GetCharAt (offset - 2) : '\0';
char nextCh = offset < document.TextLength ? document.GetCharAt (offset) : ' ';
const string allowedChars = ";,[(){}+-*/%^?:&|~!<>=";
@ -431,7 +433,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -431,7 +433,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return null;
}
}
if (identifierStart == null)
return HandleAccessorContext () ?? DefaultControlSpaceItems ();
@ -1596,8 +1597,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -1596,8 +1597,14 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
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 mref = baseUnit.GetNodeAt<MemberReferenceExpression> (location);
if (mref == null){
var invoke = baseUnit.GetNodeAt<InvocationExpression> (location);
if (invoke != null)

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

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

Loading…
Cancel
Save