~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/GuiException/tests/CSharpParser/TestLexer.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ****************************************************************
2
 
// This is free software licensed under the NUnit license. You may
3
 
// obtain a copy of the license at http://nunit.org
4
 
// ****************************************************************
5
 
 
6
 
using System;
7
 
using System.Text;
8
 
using NUnit.Framework;
9
 
using NUnit.UiException.CodeFormatters;
10
 
 
11
 
namespace NUnit.UiException.Tests.CodeFormatters
12
 
{
13
 
    [TestFixture]
14
 
    public class TestLexer
15
 
    {
16
 
        private TestingLexer _lexer;
17
 
 
18
 
        [SetUp]
19
 
        public void SetUp()
20
 
        {
21
 
            _lexer = new TestingLexer();
22
 
 
23
 
            return;
24
 
        }
25
 
 
26
 
        [Test]
27
 
        public void Test_Default()
28
 
        {
29
 
            Assert.That(_lexer.CurrentToken, Is.Null);
30
 
            Assert.That(_lexer.HasNext(), Is.False);
31
 
            Assert.That(_lexer.Next(), Is.False);
32
 
 
33
 
            return;
34
 
        }
35
 
 
36
 
        [Test]
37
 
        [ExpectedException(typeof(ArgumentNullException))]
38
 
        public void Test_SetText_Throws_NullArgumentException()
39
 
        {
40
 
            _lexer.Parse(null); // throws exception
41
 
        }
42
 
 
43
 
        private void _checkOutput(string sequence, LexToken[] expected)
44
 
        {
45
 
            Lexer lexer;
46
 
            StringBuilder recognized;
47
 
            string error;
48
 
            int i;
49
 
            int j;
50
 
 
51
 
            lexer = new Lexer();
52
 
            lexer.Parse(sequence);
53
 
 
54
 
            recognized = new StringBuilder();
55
 
 
56
 
            i = 0;
57
 
            while (lexer.Next())
58
 
            {
59
 
                recognized.Append(lexer.CurrentToken.Text);
60
 
 
61
 
                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
62
 
                    expected[i],
63
 
                    lexer.CurrentToken,
64
 
                    recognized.ToString());
65
 
 
66
 
                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);
67
 
 
68
 
                i++;
69
 
            }
70
 
 
71
 
            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");
72
 
 
73
 
            error = "missing ";
74
 
            j = i;
75
 
            while (j < expected.Length)
76
 
            {
77
 
                error += expected[j].ToString();
78
 
                error += ", ";
79
 
                ++j;
80
 
            }
81
 
 
82
 
            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);
83
 
 
84
 
            return;
85
 
        }
86
 
 
87
 
        [Test]
88
 
        public void Test_Split_Words()
89
 
        {
90
 
            _checkOutput("one two three\r\n'",
91
 
                new LexToken[] {
92
 
                    new TestingToken("one", 0, LexerTag.Text),
93
 
                    new TestingToken(" ", 3, LexerTag.Separator),
94
 
                    new TestingToken("two", 4, LexerTag.Text),
95
 
                    new TestingToken(" ", 7, LexerTag.Separator),
96
 
                    new TestingToken("three", 8, LexerTag.Text),
97
 
                    new TestingToken("\r", 13, LexerTag.Separator),
98
 
                    new TestingToken("\n", 14, LexerTag.EndOfLine),
99
 
                    new TestingToken("'", 15, LexerTag.SingleQuote)
100
 
                });
101
 
 
102
 
            return;
103
 
        }
104
 
 
105
 
        [Test]
106
 
        public void Test_Split_SingleQuote()
107
 
        {
108
 
            _checkOutput("'hello'",
109
 
                new LexToken[] {
110
 
                    new TestingToken("'", 0, LexerTag.SingleQuote),
111
 
                    new TestingToken("hello", 1, LexerTag.Text),
112
 
                    new TestingToken("'", 6, LexerTag.SingleQuote)
113
 
                });
114
 
 
115
 
            return;
116
 
        }
117
 
 
118
 
        [Test]
119
 
        public void Test_Split_DoubleQuote()
120
 
        {
121
 
            _checkOutput("\"hello\"",
122
 
                new LexToken[] {
123
 
                    new TestingToken("\"", 0, LexerTag.DoubleQuote),
124
 
                    new TestingToken("hello", 1, LexerTag.Text),
125
 
                    new TestingToken("\"", 6, LexerTag.DoubleQuote)
126
 
                });
127
 
 
128
 
            // test to fail
129
 
            // lexer should not be confused by escapment character \"
130
 
            // expecting:
131
 
            //  - \"
132
 
            //  - \\\"
133
 
            //  - hello
134
 
            //  - \\\"
135
 
            //  - \"
136
 
 
137
 
            _checkOutput("\"\"hello\"\"",
138
 
                new LexToken[] {
139
 
                    new TestingToken("\"", 0, LexerTag.DoubleQuote),
140
 
                    new TestingToken("\"", 1, LexerTag.DoubleQuote),
141
 
                    new TestingToken("hello", 2, LexerTag.Text),
142
 
                    new TestingToken("\"", 7, LexerTag.DoubleQuote),
143
 
                    new TestingToken("\"", 8, LexerTag.DoubleQuote)
144
 
                });
145
 
 
146
 
            // test to fail
147
 
            // lexer should not be confused by escapment character \'
148
 
            // expecting:
149
 
            //  - \"
150
 
            //  - \\\'
151
 
            //  - A
152
 
            //  - \\\'
153
 
            //  - \"
154
 
 
155
 
            _checkOutput("\"\'A\'\"",
156
 
                new LexToken[] {
157
 
                    new TestingToken("\"", 0, LexerTag.DoubleQuote),
158
 
                    new TestingToken("\'", 1, LexerTag.SingleQuote),
159
 
                    new TestingToken("A", 2, LexerTag.Text),
160
 
                    new TestingToken("\'", 3, LexerTag.SingleQuote),
161
 
                    new TestingToken("\"", 4, LexerTag.DoubleQuote)
162
 
                });
163
 
 
164
 
            return;
165
 
        }
166
 
 
167
 
        [Test]
168
 
        public void Test_Split_NumberSign()
169
 
        {
170
 
            _checkOutput("#hello#",
171
 
                new LexToken[] {
172
 
                    new TestingToken("#", 0, LexerTag.Separator),
173
 
                    new TestingToken("hello", 1, LexerTag.Text),
174
 
                    new TestingToken("#", 6, LexerTag.Separator)
175
 
                });
176
 
 
177
 
            return;
178
 
        }
179
 
 
180
 
        [Test]
181
 
        public void Test_Dot_Character()
182
 
        {
183
 
            _checkOutput("this.Something",
184
 
                new LexToken[] {
185
 
                    new TestingToken("this", 0, LexerTag.Text),
186
 
                    new TestingToken(".", 4, LexerTag.Separator),
187
 
                    new TestingToken("Something", 5, LexerTag.Text)
188
 
                });
189
 
 
190
 
            return;
191
 
        }
192
 
 
193
 
        [Test]
194
 
        public void Test_Split_ColonCharacter()
195
 
        {
196
 
            _checkOutput(":a:",
197
 
                new LexToken[] {
198
 
                    new TestingToken(":", 0, LexerTag.Separator),
199
 
                    new TestingToken("a", 1, LexerTag.Text),
200
 
                    new TestingToken(":", 2, LexerTag.Separator)
201
 
                });
202
 
 
203
 
            _checkOutput("<a<",
204
 
                new LexToken[] {
205
 
                    new TestingToken("<", 0, LexerTag.Separator),
206
 
                    new TestingToken("a", 1, LexerTag.Text),
207
 
                    new TestingToken("<", 2, LexerTag.Separator)
208
 
                });
209
 
 
210
 
            _checkOutput(">a>",
211
 
                new LexToken[] {
212
 
                    new TestingToken(">", 0, LexerTag.Separator),
213
 
                    new TestingToken("a", 1, LexerTag.Text),
214
 
                    new TestingToken(">", 2, LexerTag.Separator)
215
 
                });
216
 
 
217
 
            _checkOutput(",a,",
218
 
                new LexToken[] {
219
 
                    new TestingToken(",", 0, LexerTag.Separator),
220
 
                    new TestingToken("a", 1, LexerTag.Text),
221
 
                    new TestingToken(",", 2, LexerTag.Separator)
222
 
                });
223
 
 
224
 
            return;
225
 
        }
226
 
 
227
 
        [Test]
228
 
        public void Test_Split_Equals()
229
 
        {
230
 
            _checkOutput("=a=",
231
 
                new LexToken[] {
232
 
                    new TestingToken("=", 0, LexerTag.Separator),
233
 
                    new TestingToken("a", 1, LexerTag.Text),
234
 
                    new TestingToken("=", 2, LexerTag.Separator)
235
 
                });
236
 
 
237
 
            return;
238
 
        }
239
 
 
240
 
        [Test]
241
 
        public void Test_Split_New_Line()
242
 
        {
243
 
            _checkOutput("\none\n",
244
 
                new LexToken[] {
245
 
                    new TestingToken("\n", 0, LexerTag.EndOfLine),
246
 
                    new TestingToken("one", 1, LexerTag.Text),
247
 
                    new TestingToken("\n", 4, LexerTag.EndOfLine)
248
 
                });
249
 
 
250
 
            return;
251
 
        }
252
 
 
253
 
        [Test]
254
 
        public void Test_Split_WhiteSpaces()
255
 
        {
256
 
            // test with space
257
 
 
258
 
            _checkOutput(" hello ",
259
 
                new LexToken[] {
260
 
                    new TestingToken(" ", 0, LexerTag.Separator),
261
 
                    new TestingToken("hello", 1, LexerTag.Text),
262
 
                    new TestingToken(" ", 6, LexerTag.Separator)
263
 
                });
264
 
 
265
 
            /// test with '\r'
266
 
 
267
 
            _checkOutput("\rhello\r",
268
 
                new LexToken[] {
269
 
                    new TestingToken("\r", 0, LexerTag.Separator),
270
 
                    new TestingToken("hello", 1, LexerTag.Text),
271
 
                    new TestingToken("\r", 6, LexerTag.Separator)
272
 
            });
273
 
 
274
 
            // test with ';'
275
 
 
276
 
            _checkOutput(";hello;",
277
 
                new LexToken[] {
278
 
                    new TestingToken(";", 0, LexerTag.Separator),
279
 
                    new TestingToken("hello", 1, LexerTag.Text),
280
 
                    new TestingToken(";", 6, LexerTag.Separator)
281
 
                });
282
 
 
283
 
            // test with '['
284
 
 
285
 
            _checkOutput("[hello[",
286
 
                new LexToken[] {
287
 
                    new TestingToken("[", 0, LexerTag.Separator),
288
 
                    new TestingToken("hello", 1, LexerTag.Text),
289
 
                    new TestingToken("[", 6, LexerTag.Separator)
290
 
                });
291
 
 
292
 
            // test with ']'
293
 
 
294
 
            _checkOutput("]hello]",
295
 
                new LexToken[] {
296
 
                    new TestingToken("]", 0, LexerTag.Separator),
297
 
                    new TestingToken("hello", 1, LexerTag.Text),
298
 
                    new TestingToken("]", 6, LexerTag.Separator)
299
 
                });
300
 
 
301
 
            // test with '('
302
 
 
303
 
            _checkOutput("(hello(",
304
 
                new LexToken[] {
305
 
                    new TestingToken("(", 0, LexerTag.Separator),
306
 
                    new TestingToken("hello", 1, LexerTag.Text),
307
 
                    new TestingToken("(", 6, LexerTag.Separator)
308
 
                });
309
 
 
310
 
            // test with ')'
311
 
 
312
 
            _checkOutput(")hello)",
313
 
                new LexToken[] {
314
 
                    new TestingToken(")", 0, LexerTag.Separator),
315
 
                    new TestingToken("hello", 1, LexerTag.Text),
316
 
                    new TestingToken(")", 6, LexerTag.Separator)
317
 
                });
318
 
 
319
 
            return;
320
 
        }
321
 
 
322
 
        [Test]
323
 
        public void Test_Split_CommentC()
324
 
        {
325
 
            _checkOutput("/*plop/*",
326
 
                new LexToken[] {
327
 
                    new TestingToken("/*", 0, LexerTag.CommentC_Open),
328
 
                    new TestingToken("plop", 2, LexerTag.Text),
329
 
                    new TestingToken("/*", 6, LexerTag.CommentC_Open)
330
 
                });
331
 
 
332
 
            // test with */
333
 
            _checkOutput("*/plop*/",
334
 
                new LexToken[] {
335
 
                new TestingToken("*/", 0, LexerTag.CommentC_Close),
336
 
                new TestingToken("plop", 2, LexerTag.Text),
337
 
                new TestingToken("*/", 6, LexerTag.CommentC_Close)
338
 
                });
339
 
 
340
 
            return;
341
 
        }
342
 
 
343
 
        [Test]
344
 
        public void Test_Split_CommentCpp()
345
 
        {
346
 
            _checkOutput("//plop//",
347
 
                new LexToken[] {
348
 
                    new TestingToken("//", 0, LexerTag.CommentCpp),
349
 
                    new TestingToken("plop", 2, LexerTag.Text),
350
 
                    new TestingToken("//", 6, LexerTag.CommentCpp)
351
 
                });
352
 
 
353
 
            return;
354
 
        }
355
 
 
356
 
        #region TestingLexer
357
 
 
358
 
        /// <summary>
359
 
        /// Subclasses Lexer to access and test internal methods.
360
 
        /// </summary>
361
 
        class TestingLexer :
362
 
            Lexer
363
 
        {
364
 
            public TestingLexer()
365
 
            {
366
 
            }
367
 
 
368
 
            public new void Clear()
369
 
            {
370
 
                base.Clear();
371
 
            }
372
 
        }
373
 
 
374
 
        #endregion
375
 
 
376
 
        #region TestingToken
377
 
 
378
 
        class TestingToken :
379
 
            LexToken
380
 
        {
381
 
            public TestingToken(string text, int index, LexerTag tag)
382
 
            {
383
 
                _text = text;
384
 
                _start = index;
385
 
                _tag = tag;
386
 
 
387
 
                return;
388
 
            }
389
 
        }
390
 
 
391
 
        #endregion
392
 
    }
393
 
}
 
1
// ****************************************************************
 
2
// This is free software licensed under the NUnit license. You may
 
3
// obtain a copy of the license at http://nunit.org
 
4
// ****************************************************************
 
5
 
 
6
using System;
 
7
using System.Text;
 
8
using NUnit.Framework;
 
9
using NUnit.UiException.CodeFormatters;
 
10
 
 
11
namespace NUnit.UiException.Tests.CodeFormatters
 
12
{
 
13
    [TestFixture]
 
14
    public class TestLexer
 
15
    {
 
16
        private TestingLexer _lexer;
 
17
 
 
18
        [SetUp]
 
19
        public void SetUp()
 
20
        {
 
21
            _lexer = new TestingLexer();
 
22
 
 
23
            return;
 
24
        }
 
25
 
 
26
        [Test]
 
27
        public void Test_Default()
 
28
        {
 
29
            Assert.That(_lexer.CurrentToken, Is.Null);
 
30
            Assert.That(_lexer.HasNext(), Is.False);
 
31
            Assert.That(_lexer.Next(), Is.False);
 
32
 
 
33
            return;
 
34
        }
 
35
 
 
36
        [Test]
 
37
        [ExpectedException(typeof(ArgumentNullException))]
 
38
        public void Test_SetText_Throws_NullArgumentException()
 
39
        {
 
40
            _lexer.Parse(null); // throws exception
 
41
        }
 
42
 
 
43
        private void _checkOutput(string sequence, LexToken[] expected)
 
44
        {
 
45
            Lexer lexer;
 
46
            StringBuilder recognized;
 
47
            string error;
 
48
            int i;
 
49
            int j;
 
50
 
 
51
            lexer = new Lexer();
 
52
            lexer.Parse(sequence);
 
53
 
 
54
            recognized = new StringBuilder();
 
55
 
 
56
            i = 0;
 
57
            while (lexer.Next())
 
58
            {
 
59
                recognized.Append(lexer.CurrentToken.Text);
 
60
 
 
61
                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
 
62
                    expected[i],
 
63
                    lexer.CurrentToken,
 
64
                    recognized.ToString());
 
65
 
 
66
                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);
 
67
 
 
68
                i++;
 
69
            }
 
70
 
 
71
            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");
 
72
 
 
73
            error = "missing ";
 
74
            j = i;
 
75
            while (j < expected.Length)
 
76
            {
 
77
                error += expected[j].ToString();
 
78
                error += ", ";
 
79
                ++j;
 
80
            }
 
81
 
 
82
            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);
 
83
 
 
84
            return;
 
85
        }
 
86
 
 
87
        [Test]
 
88
        public void Test_Split_Words()
 
89
        {
 
90
            _checkOutput("one two three\r\n'",
 
91
                new LexToken[] {
 
92
                    new TestingToken("one", 0, LexerTag.Text),
 
93
                    new TestingToken(" ", 3, LexerTag.Separator),
 
94
                    new TestingToken("two", 4, LexerTag.Text),
 
95
                    new TestingToken(" ", 7, LexerTag.Separator),
 
96
                    new TestingToken("three", 8, LexerTag.Text),
 
97
                    new TestingToken("\r", 13, LexerTag.Separator),
 
98
                    new TestingToken("\n", 14, LexerTag.EndOfLine),
 
99
                    new TestingToken("'", 15, LexerTag.SingleQuote)
 
100
                });
 
101
 
 
102
            return;
 
103
        }
 
104
 
 
105
        [Test]
 
106
        public void Test_Split_SingleQuote()
 
107
        {
 
108
            _checkOutput("'hello'",
 
109
                new LexToken[] {
 
110
                    new TestingToken("'", 0, LexerTag.SingleQuote),
 
111
                    new TestingToken("hello", 1, LexerTag.Text),
 
112
                    new TestingToken("'", 6, LexerTag.SingleQuote)
 
113
                });
 
114
 
 
115
            return;
 
116
        }
 
117
 
 
118
        [Test]
 
119
        public void Test_Split_DoubleQuote()
 
120
        {
 
121
            _checkOutput("\"hello\"",
 
122
                new LexToken[] {
 
123
                    new TestingToken("\"", 0, LexerTag.DoubleQuote),
 
124
                    new TestingToken("hello", 1, LexerTag.Text),
 
125
                    new TestingToken("\"", 6, LexerTag.DoubleQuote)
 
126
                });
 
127
 
 
128
            // test to fail
 
129
            // lexer should not be confused by escapment character \"
 
130
            // expecting:
 
131
            //  - \"
 
132
            //  - \\\"
 
133
            //  - hello
 
134
            //  - \\\"
 
135
            //  - \"
 
136
 
 
137
            _checkOutput("\"\"hello\"\"",
 
138
                new LexToken[] {
 
139
                    new TestingToken("\"", 0, LexerTag.DoubleQuote),
 
140
                    new TestingToken("\"", 1, LexerTag.DoubleQuote),
 
141
                    new TestingToken("hello", 2, LexerTag.Text),
 
142
                    new TestingToken("\"", 7, LexerTag.DoubleQuote),
 
143
                    new TestingToken("\"", 8, LexerTag.DoubleQuote)
 
144
                });
 
145
 
 
146
            // test to fail
 
147
            // lexer should not be confused by escapment character \'
 
148
            // expecting:
 
149
            //  - \"
 
150
            //  - \\\'
 
151
            //  - A
 
152
            //  - \\\'
 
153
            //  - \"
 
154
 
 
155
            _checkOutput("\"\'A\'\"",
 
156
                new LexToken[] {
 
157
                    new TestingToken("\"", 0, LexerTag.DoubleQuote),
 
158
                    new TestingToken("\'", 1, LexerTag.SingleQuote),
 
159
                    new TestingToken("A", 2, LexerTag.Text),
 
160
                    new TestingToken("\'", 3, LexerTag.SingleQuote),
 
161
                    new TestingToken("\"", 4, LexerTag.DoubleQuote)
 
162
                });
 
163
 
 
164
            return;
 
165
        }
 
166
 
 
167
        [Test]
 
168
        public void Test_Split_NumberSign()
 
169
        {
 
170
            _checkOutput("#hello#",
 
171
                new LexToken[] {
 
172
                    new TestingToken("#", 0, LexerTag.Separator),
 
173
                    new TestingToken("hello", 1, LexerTag.Text),
 
174
                    new TestingToken("#", 6, LexerTag.Separator)
 
175
                });
 
176
 
 
177
            return;
 
178
        }
 
179
 
 
180
        [Test]
 
181
        public void Test_Dot_Character()
 
182
        {
 
183
            _checkOutput("this.Something",
 
184
                new LexToken[] {
 
185
                    new TestingToken("this", 0, LexerTag.Text),
 
186
                    new TestingToken(".", 4, LexerTag.Separator),
 
187
                    new TestingToken("Something", 5, LexerTag.Text)
 
188
                });
 
189
 
 
190
            return;
 
191
        }
 
192
 
 
193
        [Test]
 
194
        public void Test_Split_ColonCharacter()
 
195
        {
 
196
            _checkOutput(":a:",
 
197
                new LexToken[] {
 
198
                    new TestingToken(":", 0, LexerTag.Separator),
 
199
                    new TestingToken("a", 1, LexerTag.Text),
 
200
                    new TestingToken(":", 2, LexerTag.Separator)
 
201
                });
 
202
 
 
203
            _checkOutput("<a<",
 
204
                new LexToken[] {
 
205
                    new TestingToken("<", 0, LexerTag.Separator),
 
206
                    new TestingToken("a", 1, LexerTag.Text),
 
207
                    new TestingToken("<", 2, LexerTag.Separator)
 
208
                });
 
209
 
 
210
            _checkOutput(">a>",
 
211
                new LexToken[] {
 
212
                    new TestingToken(">", 0, LexerTag.Separator),
 
213
                    new TestingToken("a", 1, LexerTag.Text),
 
214
                    new TestingToken(">", 2, LexerTag.Separator)
 
215
                });
 
216
 
 
217
            _checkOutput(",a,",
 
218
                new LexToken[] {
 
219
                    new TestingToken(",", 0, LexerTag.Separator),
 
220
                    new TestingToken("a", 1, LexerTag.Text),
 
221
                    new TestingToken(",", 2, LexerTag.Separator)
 
222
                });
 
223
 
 
224
            return;
 
225
        }
 
226
 
 
227
        [Test]
 
228
        public void Test_Split_Equals()
 
229
        {
 
230
            _checkOutput("=a=",
 
231
                new LexToken[] {
 
232
                    new TestingToken("=", 0, LexerTag.Separator),
 
233
                    new TestingToken("a", 1, LexerTag.Text),
 
234
                    new TestingToken("=", 2, LexerTag.Separator)
 
235
                });
 
236
 
 
237
            return;
 
238
        }
 
239
 
 
240
        [Test]
 
241
        public void Test_Split_New_Line()
 
242
        {
 
243
            _checkOutput("\none\n",
 
244
                new LexToken[] {
 
245
                    new TestingToken("\n", 0, LexerTag.EndOfLine),
 
246
                    new TestingToken("one", 1, LexerTag.Text),
 
247
                    new TestingToken("\n", 4, LexerTag.EndOfLine)
 
248
                });
 
249
 
 
250
            return;
 
251
        }
 
252
 
 
253
        [Test]
 
254
        public void Test_Split_WhiteSpaces()
 
255
        {
 
256
            // test with space
 
257
 
 
258
            _checkOutput(" hello ",
 
259
                new LexToken[] {
 
260
                    new TestingToken(" ", 0, LexerTag.Separator),
 
261
                    new TestingToken("hello", 1, LexerTag.Text),
 
262
                    new TestingToken(" ", 6, LexerTag.Separator)
 
263
                });
 
264
 
 
265
            /// test with '\r'
 
266
 
 
267
            _checkOutput("\rhello\r",
 
268
                new LexToken[] {
 
269
                    new TestingToken("\r", 0, LexerTag.Separator),
 
270
                    new TestingToken("hello", 1, LexerTag.Text),
 
271
                    new TestingToken("\r", 6, LexerTag.Separator)
 
272
            });
 
273
 
 
274
            // test with ';'
 
275
 
 
276
            _checkOutput(";hello;",
 
277
                new LexToken[] {
 
278
                    new TestingToken(";", 0, LexerTag.Separator),
 
279
                    new TestingToken("hello", 1, LexerTag.Text),
 
280
                    new TestingToken(";", 6, LexerTag.Separator)
 
281
                });
 
282
 
 
283
            // test with '['
 
284
 
 
285
            _checkOutput("[hello[",
 
286
                new LexToken[] {
 
287
                    new TestingToken("[", 0, LexerTag.Separator),
 
288
                    new TestingToken("hello", 1, LexerTag.Text),
 
289
                    new TestingToken("[", 6, LexerTag.Separator)
 
290
                });
 
291
 
 
292
            // test with ']'
 
293
 
 
294
            _checkOutput("]hello]",
 
295
                new LexToken[] {
 
296
                    new TestingToken("]", 0, LexerTag.Separator),
 
297
                    new TestingToken("hello", 1, LexerTag.Text),
 
298
                    new TestingToken("]", 6, LexerTag.Separator)
 
299
                });
 
300
 
 
301
            // test with '('
 
302
 
 
303
            _checkOutput("(hello(",
 
304
                new LexToken[] {
 
305
                    new TestingToken("(", 0, LexerTag.Separator),
 
306
                    new TestingToken("hello", 1, LexerTag.Text),
 
307
                    new TestingToken("(", 6, LexerTag.Separator)
 
308
                });
 
309
 
 
310
            // test with ')'
 
311
 
 
312
            _checkOutput(")hello)",
 
313
                new LexToken[] {
 
314
                    new TestingToken(")", 0, LexerTag.Separator),
 
315
                    new TestingToken("hello", 1, LexerTag.Text),
 
316
                    new TestingToken(")", 6, LexerTag.Separator)
 
317
                });
 
318
 
 
319
            return;
 
320
        }
 
321
 
 
322
        [Test]
 
323
        public void Test_Split_CommentC()
 
324
        {
 
325
            _checkOutput("/*plop/*",
 
326
                new LexToken[] {
 
327
                    new TestingToken("/*", 0, LexerTag.CommentC_Open),
 
328
                    new TestingToken("plop", 2, LexerTag.Text),
 
329
                    new TestingToken("/*", 6, LexerTag.CommentC_Open)
 
330
                });
 
331
 
 
332
            // test with */
 
333
            _checkOutput("*/plop*/",
 
334
                new LexToken[] {
 
335
                new TestingToken("*/", 0, LexerTag.CommentC_Close),
 
336
                new TestingToken("plop", 2, LexerTag.Text),
 
337
                new TestingToken("*/", 6, LexerTag.CommentC_Close)
 
338
                });
 
339
 
 
340
            return;
 
341
        }
 
342
 
 
343
        [Test]
 
344
        public void Test_Split_CommentCpp()
 
345
        {
 
346
            _checkOutput("//plop//",
 
347
                new LexToken[] {
 
348
                    new TestingToken("//", 0, LexerTag.CommentCpp),
 
349
                    new TestingToken("plop", 2, LexerTag.Text),
 
350
                    new TestingToken("//", 6, LexerTag.CommentCpp)
 
351
                });
 
352
 
 
353
            return;
 
354
        }
 
355
 
 
356
        #region TestingLexer
 
357
 
 
358
        /// <summary>
 
359
        /// Subclasses Lexer to access and test internal methods.
 
360
        /// </summary>
 
361
        class TestingLexer :
 
362
            Lexer
 
363
        {
 
364
            public TestingLexer()
 
365
            {
 
366
            }
 
367
 
 
368
            public new void Clear()
 
369
            {
 
370
                base.Clear();
 
371
            }
 
372
        }
 
373
 
 
374
        #endregion
 
375
 
 
376
        #region TestingToken
 
377
 
 
378
        class TestingToken :
 
379
            LexToken
 
380
        {
 
381
            public TestingToken(string text, int index, LexerTag tag)
 
382
            {
 
383
                _text = text;
 
384
                _start = index;
 
385
                _tag = tag;
 
386
 
 
387
                return;
 
388
            }
 
389
        }
 
390
 
 
391
        #endregion
 
392
    }
 
393
}