1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using ICSharpCode.SharpDevelop.Editor;
6
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
11
namespace ICSharpCode.XamlBinding.Tests
14
public class ExtensionsTests
17
public void StringReplaceTest1()
19
string text = "Hello World!";
22
string newText = "Bye";
24
string result = text.Replace(index, length, newText);
25
string expected = "Bye World!";
27
Assert.AreEqual(expected, result);
31
public void StringReplaceTest2()
33
string text = "My Hello World!";
36
string newText = "Bye";
38
string result = text.Replace(index, length, newText);
39
string expected = "My Bye World!";
41
Assert.AreEqual(expected, result);
45
public void StringReplaceTest3()
47
string text = "Hello World!";
50
string newText = "Byte";
52
string result = text.Replace(index, length, newText);
53
string expected = "Hello Byte!";
55
Assert.AreEqual(expected, result);
59
public void StringReplaceTest4()
61
string text = "Hello World!";
66
string result = text.Replace(index, length, newText);
67
string expected = "Hello World?";
69
Assert.AreEqual(expected, result);
74
public void GetWordBeforeCaretExtendedTest1()
76
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
77
editor.Document.Text = "<Test />";
78
editor.Caret.Offset = 6;
79
string text = editor.GetWordBeforeCaretExtended();
80
Assert.AreEqual(string.Empty, text);
85
public void GetWordBeforeCaretExtendedTest2()
87
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
88
editor.Document.Text = "<Test value=\"\" />";
89
editor.Caret.Offset = 6;
90
string text = editor.GetWordBeforeCaretExtended();
91
Assert.AreEqual(string.Empty, text);
96
public void GetWordBeforeCaretExtendedTest3()
98
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
99
editor.Document.Text = "<Test value=\"\" />";
100
editor.Caret.Offset = 14;
101
string text = editor.GetWordBeforeCaretExtended();
102
Assert.AreEqual(string.Empty, text);
107
public void GetWordBeforeCaretExtendedTest4()
109
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
110
editor.Document.Text = "<Test value=\"\" />";
111
editor.Caret.Offset = 11;
112
string text = editor.GetWordBeforeCaretExtended();
113
Assert.AreEqual("value", text);
118
public void GetWordBeforeCaretExtendedTest5()
120
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
121
editor.Document.Text = "<Test member.value=\"\" />";
122
editor.Caret.Offset = 12;
123
string text = editor.GetWordBeforeCaretExtended();
124
Assert.AreEqual("member", text);
129
public void GetWordBeforeCaretExtendedTest6()
131
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
132
editor.Document.Text = "<Test member.value=\"\" />";
133
editor.Caret.Offset = 13;
134
string text = editor.GetWordBeforeCaretExtended();
135
Assert.AreEqual("member.", text);
140
public void GetWordBeforeCaretExtendedTest7()
142
ITextEditor editor = new AvalonEditTextEditorAdapter(new AvalonEdit.TextEditor());
143
editor.Document.Text = "<Test member.value=\"\" />";
144
editor.Caret.Offset = 14;
145
string text = editor.GetWordBeforeCaretExtended();
146
Assert.AreEqual("member.v", text);
150
public void MoveBeforeTest1()
152
string xml = "<Test value=\"A\"><Item value=\"B\" /><Item value=\"C\" /></Test>";
153
XElement parent = XElement.Parse(xml);
154
XElement item = parent.Elements().ElementAt(0);
155
XElement itemToMove = parent.Elements().ElementAt(1);
156
itemToMove.MoveBefore(item);
157
Assert.AreEqual(itemToMove, parent.Elements().First());