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)
4
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
6
using ICSharpCode.AvalonEdit;
7
using ICSharpCode.Core;
10
namespace ICSharpCode.VBNetBinding.Tests
13
/// Tests that Operator overrides have "End Operator" added after the user presses the return key.
16
public class EndOperatorTests
19
public void SetUpFixture()
21
if (!PropertyService.Initialized) {
22
PropertyService.InitializeService(String.Empty, String.Empty, "VBNetBindingTests");
27
/// Checks that when the user presses the return key after the Operator line that the
28
/// expected code is generated.
30
void RunFormatLineTest(string code, string expectedCode, int expectedOffset)
32
string foo = "As Foo\r\n";
33
int cursorOffset = code.IndexOf(foo) + foo.Length;
35
AvalonEditTextEditorAdapter editor = new AvalonEditTextEditorAdapter(new TextEditor());
36
editor.Document.Text = code;
37
editor.Caret.Offset = cursorOffset;
38
VBNetFormattingStrategy formattingStrategy = new VBNetFormattingStrategy();
39
formattingStrategy.FormatLine(editor, '\n');
41
Assert.AreEqual(expectedCode, editor.Document.Text);
42
Assert.AreEqual(expectedOffset, editor.Caret.Offset);
46
public void AdditionOperator()
48
string code = "Public Class Foo\r\n" +
49
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
50
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
53
string expectedCode = "Public Class Foo\r\n" +
54
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
56
"\tEnd Operator\r\n" +
59
int expectedOffset = ("Public Class Foo\r\n" +
60
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
63
RunFormatLineTest(code, expectedCode, expectedOffset);
67
public void AdditionOperatorWithExistingEndOperator()
69
string code = "Public Class Foo\r\n" +
70
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
71
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
72
"\tEnd Operator\r\n" +
75
string expectedCode = "Public Class Foo\r\n" +
76
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
78
"\tEnd Operator\r\n" +
81
int expectedOffset = ("Public Class Foo\r\n" +
82
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
85
RunFormatLineTest(code, expectedCode, expectedOffset);
89
public void ExistingEndOperatorHasWhitespaceInbetween()
91
string code = "Public Class Foo\r\n" +
92
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
93
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
94
"\tEnd Operator\r\n" +
97
string expectedCode = "Public Class Foo\r\n" +
98
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
100
"\tEnd Operator\r\n" +
103
int expectedOffset = ("Public Class Foo\r\n" +
104
"\tPublic Shared Operator +(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
107
RunFormatLineTest(code, expectedCode, expectedOffset);
111
public void AdditionOperatorHasWhitespaceAfterOperator()
113
string code = "Public Class Foo\r\n" +
114
"\tPublic Shared Operator + (ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
115
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
118
string expectedCode = "Public Class Foo\r\n" +
119
"\tPublic Shared Operator + (ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
121
"\tEnd Operator\r\n" +
124
int expectedOffset = ("Public Class Foo\r\n" +
125
"\tPublic Shared Operator + (ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
128
RunFormatLineTest(code, expectedCode, expectedOffset);
132
public void AdditionOperatorWithNoWhitespace()
134
string code = "Public Class Foo\r\n" +
135
"\tPublic Shared Operator+(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
136
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
139
string expectedCode = "Public Class Foo\r\n" +
140
"\tPublic Shared Operator+(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
142
"\tEnd Operator\r\n" +
145
int expectedOffset = ("Public Class Foo\r\n" +
146
"\tPublic Shared Operator+(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
149
RunFormatLineTest(code, expectedCode, expectedOffset);
153
public void SubtractionOperator()
155
string code = "Public Class Foo\r\n" +
156
"\tPublic Shared Operator -(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
157
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
160
string expectedCode = "Public Class Foo\r\n" +
161
"\tPublic Shared Operator -(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
163
"\tEnd Operator\r\n" +
166
int expectedOffset = ("Public Class Foo\r\n" +
167
"\tPublic Shared Operator -(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
170
RunFormatLineTest(code, expectedCode, expectedOffset);
174
public void IsTrueOperator()
176
string code = "Public Class Foo\r\n" +
177
"\tPublic Shared Operator IsTrue(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
178
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
181
string expectedCode = "Public Class Foo\r\n" +
182
"\tPublic Shared Operator IsTrue(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
184
"\tEnd Operator\r\n" +
187
int expectedOffset = ("Public Class Foo\r\n" +
188
"\tPublic Shared Operator IsTrue(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
191
RunFormatLineTest(code, expectedCode, expectedOffset);
195
public void MultiplicationOperator()
197
string code = "Public Class Foo\r\n" +
198
"\tPublic Shared Operator *(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
199
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
202
string expectedCode = "Public Class Foo\r\n" +
203
"\tPublic Shared Operator *(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
205
"\tEnd Operator\r\n" +
208
int expectedOffset = ("Public Class Foo\r\n" +
209
"\tPublic Shared Operator *(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
212
RunFormatLineTest(code, expectedCode, expectedOffset);
216
public void DivisionOperator()
218
string code = "Public Class Foo\r\n" +
219
"\tPublic Shared Operator /(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
220
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
223
string expectedCode = "Public Class Foo\r\n" +
224
"\tPublic Shared Operator /(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
226
"\tEnd Operator\r\n" +
229
int expectedOffset = ("Public Class Foo\r\n" +
230
"\tPublic Shared Operator /(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
233
RunFormatLineTest(code, expectedCode, expectedOffset);
237
public void IntegerDivisionOperator()
239
string code = "Public Class Foo\r\n" +
240
"\tPublic Shared Operator \\(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
241
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
244
string expectedCode = "Public Class Foo\r\n" +
245
"\tPublic Shared Operator \\(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
247
"\tEnd Operator\r\n" +
250
int expectedOffset = ("Public Class Foo\r\n" +
251
"\tPublic Shared Operator \\(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
254
RunFormatLineTest(code, expectedCode, expectedOffset);
258
public void StringConcatenationOperator()
260
string code = "Public Class Foo\r\n" +
261
"\tPublic Shared Operator &(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
262
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
265
string expectedCode = "Public Class Foo\r\n" +
266
"\tPublic Shared Operator &(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
268
"\tEnd Operator\r\n" +
271
int expectedOffset = ("Public Class Foo\r\n" +
272
"\tPublic Shared Operator &(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
275
RunFormatLineTest(code, expectedCode, expectedOffset);
279
public void ExponentationcationOperator()
281
string code = "Public Class Foo\r\n" +
282
"\tPublic Shared Operator ^(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
283
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
286
string expectedCode = "Public Class Foo\r\n" +
287
"\tPublic Shared Operator ^(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
289
"\tEnd Operator\r\n" +
292
int expectedOffset = ("Public Class Foo\r\n" +
293
"\tPublic Shared Operator ^(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
296
RunFormatLineTest(code, expectedCode, expectedOffset);
300
public void EqualityOperator()
302
string code = "Public Class Foo\r\n" +
303
"\tPublic Shared Operator =(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
304
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
307
string expectedCode = "Public Class Foo\r\n" +
308
"\tPublic Shared Operator =(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
310
"\tEnd Operator\r\n" +
313
int expectedOffset = ("Public Class Foo\r\n" +
314
"\tPublic Shared Operator =(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
317
RunFormatLineTest(code, expectedCode, expectedOffset);
321
public void GreaterThanOperator()
323
string code = "Public Class Foo\r\n" +
324
"\tPublic Shared Operator >(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
325
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
328
string expectedCode = "Public Class Foo\r\n" +
329
"\tPublic Shared Operator >(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
331
"\tEnd Operator\r\n" +
334
int expectedOffset = ("Public Class Foo\r\n" +
335
"\tPublic Shared Operator >(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
338
RunFormatLineTest(code, expectedCode, expectedOffset);
342
public void LessThanOperator()
344
string code = "Public Class Foo\r\n" +
345
"\tPublic Shared Operator <(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
346
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
349
string expectedCode = "Public Class Foo\r\n" +
350
"\tPublic Shared Operator <(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
352
"\tEnd Operator\r\n" +
355
int expectedOffset = ("Public Class Foo\r\n" +
356
"\tPublic Shared Operator <(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
359
RunFormatLineTest(code, expectedCode, expectedOffset);
363
public void InequalityOperator()
365
string code = "Public Class Foo\r\n" +
366
"\tPublic Shared Operator <>(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
367
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
370
string expectedCode = "Public Class Foo\r\n" +
371
"\tPublic Shared Operator <>(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
373
"\tEnd Operator\r\n" +
376
int expectedOffset = ("Public Class Foo\r\n" +
377
"\tPublic Shared Operator <>(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
380
RunFormatLineTest(code, expectedCode, expectedOffset);
384
/// Check that a method that starts with "Operator" is ignored.
387
public void MethodStartsWithOperatorString()
389
string code = "Public Class Foo\r\n" +
390
"\tPublic Shared OperatorIgnore(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
391
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
394
string expectedCode = "Public Class Foo\r\n" +
395
"\tPublic Shared OperatorIgnore(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
399
int expectedOffset = ("Public Class Foo\r\n" +
400
"\tPublic Shared OperatorIgnore(ByVal lhs As Foo, ByVal rhs As Foo) As Foo\r\n" +
403
RunFormatLineTest(code, expectedCode, expectedOffset);