Browse Source

fixed insertion bugs in XAML code completion and added unit tests

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5669 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
65e2ff4868
  1. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/CodeCompletionTests.cs
  2. 92
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/CodeInsertionTests.cs
  3. 24
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/TextEditorBasedTests.cs
  4. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/XamlBinding.Tests.csproj
  5. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs
  6. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopCompletionWindow.cs
  7. 5
      src/Main/Base/Project/Src/Editor/CodeCompletion/CompletionContext.cs

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/CodeCompletionTests.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

92
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/CodeInsertionTests.cs

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision: 5529 $</version>
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using NUnit.Framework;
namespace ICSharpCode.XamlBinding.Tests
{
[TestFixture]
[RequiresSTA]
public class CodeInsertionTests : TextEditorBasedTests
{
#region TextInsertionTests
[Test]
public void CtrlSpaceClosingAttributeValueWithEqualsInsertionTest()
{
string fileHeader = @"<Window x:Class='ICSharpCode.XamlBinding.Tests.CompletionTestsBase'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Grid>
<Button ";
string fileFooter = @"
</Grid>
</Window>";
TestCtrlSpace(fileHeader, fileFooter, true,
list => {
Assert.AreEqual(0, list.PreselectionLength);
Assert.IsNull(list.SuggestedItem);
Assert.IsTrue(list.Items.Any());
TestTextInsert(fileHeader, fileFooter, '=', list, list.Items.First(i => i.Text == "Content"), "Content=\"\"", "Content=\"".Length);
});
}
[Test]
public void CtrlSpaceInsertionTest()
{
string fileHeader = @"<Window x:Class='ICSharpCode.XamlBinding.Tests.CompletionTestsBase'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Grid>
";
string fileFooter = @"
</Grid>
</Window>";
TestCtrlSpace(fileHeader, fileFooter, true,
list => {
Assert.AreEqual(0, list.PreselectionLength);
Assert.IsNull(list.SuggestedItem);
Assert.IsTrue(list.Items.Any());
TestTextInsert(fileHeader, fileFooter, '\n', list, list.Items.First(i => i.Text == "!--"), "<!-- -->", "<!-- ".Length);
TestTextInsert(fileHeader, fileFooter, '\n', list, list.Items.First(i => i.Text == "Button"), "<Button", "<Button".Length);
TestTextInsert(fileHeader, fileFooter, '\n', list, list.Items.First(i => i.Text == "/Grid"), "</Grid>", "</Grid>".Length);
});
}
[Test]
public void CtrlSpaceClosingTagWithGreaterThanInsertionTest()
{
string fileHeader = @"<Window x:Class='ICSharpCode.XamlBinding.Tests.CompletionTestsBase'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Grid>
";
string fileFooter = @"
</Grid>
</Window>";
TestCtrlSpace(fileHeader, fileFooter, true,
list => {
Assert.AreEqual(0, list.PreselectionLength);
Assert.IsNull(list.SuggestedItem);
Assert.IsTrue(list.Items.Any());
TestTextInsert(fileHeader, fileFooter, '>', list, list.Items.First(i => i.Text == "/Grid"), "</Grid>", "</Grid>".Length);
});
}
#endregion
}
}

24
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/TextEditorBasedTests.cs

@ -51,5 +51,29 @@ namespace ICSharpCode.XamlBinding.Tests @@ -51,5 +51,29 @@ namespace ICSharpCode.XamlBinding.Tests
constraint(list);
}
protected void TestTextInsert(string fileHeader, string fileFooter, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
{
this.textEditor.Document.Text = fileHeader + fileFooter;
this.textEditor.Caret.Offset = fileHeader.Length;
this.textEditor.CreateParseInformation();
CompletionContext context = new CompletionContext() {
Editor = this.textEditor,
CompletionChar = completionChar,
StartOffset = textEditor.Caret.Offset,
EndOffset = textEditor.Caret.Offset
};
list.Complete(context, item);
if (!context.CompletionCharHandled && context.CompletionChar != '\n')
this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
string insertedText = this.textEditor.Document.GetText(fileHeader.Length, this.textEditor.Document.TextLength - fileHeader.Length - fileFooter.Length);
Assert.AreEqual(expectedOutput, insertedText);
Assert.AreEqual(fileHeader.Length + expectedOffset, textEditor.Caret.Offset);
}
}
}

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/XamlBinding.Tests.csproj

@ -70,6 +70,7 @@ @@ -70,6 +70,7 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="CodeCompletionTests.cs" />
<Compile Include="CodeInsertionTests.cs" />
<Compile Include="CompletionTestsBase.xaml.cs">
<DependentUpon>CompletionTestsBase.xaml</DependentUpon>
<SubType>Code</SubType>

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

@ -74,6 +74,7 @@ namespace ICSharpCode.XamlBinding @@ -74,6 +74,7 @@ namespace ICSharpCode.XamlBinding
if (cItem.Entity is IProperty || cItem.Entity is IEvent) {
if (xamlContext.Description == XamlContextDescription.InTag) {
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.CompletionCharHandled = context.CompletionChar == '=';
context.Editor.Caret.Offset--;
XamlCodeCompletionBinding.Instance.CtrlSpace(context.Editor);
} else if (xamlContext.Description == XamlContextDescription.InMarkupExtension && !string.IsNullOrEmpty(xamlContext.RawAttributeValue)) {
@ -140,6 +141,7 @@ namespace ICSharpCode.XamlBinding @@ -140,6 +141,7 @@ namespace ICSharpCode.XamlBinding
if (item.Text.StartsWith("/", StringComparison.OrdinalIgnoreCase)) {
context.Editor.Document.Insert(context.EndOffset, ">");
context.CompletionCharHandled = context.CompletionChar == '>';
context.Editor.Caret.Offset++;
}
}

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopCompletionWindow.cs

@ -182,6 +182,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -182,6 +182,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
else if (kea != null && kea.Key == Key.Tab)
context.CompletionChar = '\t';
window.ItemList.Complete(context, item);
if (context.CompletionCharHandled && txea != null)
txea.Handled = true;
}
}
}

5
src/Main/Base/Project/Src/Editor/CodeCompletion/CompletionContext.cs

@ -39,5 +39,10 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -39,5 +39,10 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
/// This property is '\0' when completion was triggered using the mouse.
/// </summary>
public char CompletionChar { get; set; }
/// <summary>
/// Gets/Sets whether the CompletionChar was already inserted.
/// </summary>
public bool CompletionCharHandled { get; set; }
}
}

Loading…
Cancel
Save