build fix
[LibreOffice.git] / basic / qa / cppunit / test_scanner.cxx
blob509a793f175aa89ead49949cb4915bc0e95a786b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/types.h>
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/plugin/TestPlugIn.h>
16 #include <osl/file.hxx>
17 #include <osl/process.h>
18 #include <rtl/math.hxx>
20 #include "scanner.hxx"
22 namespace
24 struct Symbol
26 sal_uInt16 line;
27 sal_uInt16 col1;
28 OUString text;
29 double number;
30 SbxDataType type;
33 /**
34 * Perform tests on Scanner.
36 class ScannerTest : public CppUnit::TestFixture
38 private:
39 void testBlankLines();
40 void testOperators();
41 void testAlphanum();
42 void testComments();
43 void testGoto();
44 void testGotoCompatible();
45 void testExclamation();
46 void testNumbers();
47 void testDataType();
48 void testHexOctal();
50 // Adds code needed to register the test suite
51 CPPUNIT_TEST_SUITE(ScannerTest);
53 // Declares the method as a test to call
54 CPPUNIT_TEST(testBlankLines);
55 CPPUNIT_TEST(testOperators);
56 CPPUNIT_TEST(testAlphanum);
57 CPPUNIT_TEST(testComments);
58 CPPUNIT_TEST(testGoto);
59 CPPUNIT_TEST(testGotoCompatible);
60 CPPUNIT_TEST(testExclamation);
61 CPPUNIT_TEST(testNumbers);
62 CPPUNIT_TEST(testDataType);
63 CPPUNIT_TEST(testHexOctal);
65 // End of test suite definition
66 CPPUNIT_TEST_SUITE_END();
69 static const OUString cr = "\n";
70 static const OUString rem = "REM";
71 static const OUString asdf = "asdf";
72 static const OUString dot = ".";
73 static const OUString goto_ = "goto";
74 static const OUString excl = "!";
76 std::vector<Symbol> getSymbols(const OUString& source, sal_Int32& errors, bool bCompatible = false)
78 std::vector<Symbol> symbols;
79 SbiScanner scanner(source);
80 scanner.EnableErrors();
81 scanner.SetCompatible(bCompatible);
82 while(scanner.NextSym())
84 Symbol symbol;
85 symbol.line = scanner.GetLine();
86 symbol.col1 = scanner.GetCol1();
87 symbol.text = scanner.GetSym();
88 symbol.number = scanner.GetDbl();
89 symbol.type = scanner.GetType();
90 symbols.push_back(symbol);
92 errors = scanner.GetErrors();
93 return symbols;
96 std::vector<Symbol> getSymbols(const OUString& source, bool bCompatible = false)
98 sal_Int32 i;
99 return getSymbols(source, i, bCompatible);
102 void ScannerTest::testBlankLines()
104 const OUString source1("");
105 const OUString source2("\r\n");
106 const OUString source3("\n");
107 const OUString source4("\r");
108 const OUString source5("\r\n\r\n");
109 const OUString source6("\n\r");
110 const OUString source7("\n\r\n");
111 const OUString source8("\r\n\r");
112 const OUString source9(" ");
114 std::vector<Symbol> symbols;
115 symbols = getSymbols(source1);
116 CPPUNIT_ASSERT(symbols.empty());
118 symbols = getSymbols(source2);
119 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols.size());
120 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
121 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
123 symbols = getSymbols(source3);
124 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols.size());
125 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
126 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
128 symbols = getSymbols(source4);
129 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols.size());
130 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
131 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
133 symbols = getSymbols(source5);
134 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
135 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
136 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
137 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
138 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
140 symbols = getSymbols(source6);
141 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
142 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
143 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
144 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
145 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
147 symbols = getSymbols(source7);
148 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
149 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
150 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
151 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
152 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
154 symbols = getSymbols(source8);
155 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
156 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
157 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
158 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
159 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
161 symbols = getSymbols(source9);
162 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols.size());
163 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
164 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
167 void ScannerTest::testOperators()
169 const OUString sourceE("=");
170 const OUString sourceLT("<");
171 const OUString sourceGT(">");
172 const OUString sourceLTE("<=");
173 const OUString sourceGTE(">=");
174 const OUString sourceEE("==");
175 const OUString sourceNE("<>");
176 const OUString sourceA(":=");
178 std::vector<Symbol> symbols;
180 symbols = getSymbols(sourceE);
181 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
182 CPPUNIT_ASSERT_EQUAL(sourceE, symbols[0].text);
183 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
184 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
185 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
187 symbols = getSymbols(sourceLT);
188 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
189 CPPUNIT_ASSERT_EQUAL(sourceLT, symbols[0].text);
190 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
191 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
192 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
194 symbols = getSymbols(sourceGT);
195 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
196 CPPUNIT_ASSERT_EQUAL(sourceGT, symbols[0].text);
197 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
198 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
199 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
201 symbols = getSymbols(sourceLTE);
202 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
203 CPPUNIT_ASSERT_EQUAL(sourceLTE, symbols[0].text);
204 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
205 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
206 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
208 symbols = getSymbols(sourceGTE);
209 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
210 CPPUNIT_ASSERT_EQUAL(sourceGTE, symbols[0].text);
211 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
212 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
213 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
215 symbols = getSymbols(sourceEE);
216 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
217 CPPUNIT_ASSERT_EQUAL(sourceE, symbols[0].text);
218 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
219 CPPUNIT_ASSERT_EQUAL(sourceE, symbols[1].text);
220 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
221 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
222 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
224 symbols = getSymbols(sourceNE);
225 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
226 CPPUNIT_ASSERT_EQUAL(sourceNE, symbols[0].text);
227 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
228 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
229 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
231 symbols = getSymbols(sourceA);
232 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
233 CPPUNIT_ASSERT_EQUAL(sourceA, symbols[0].text);
234 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
235 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
236 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
239 void ScannerTest::testAlphanum()
241 const OUString source1("asdfghefg");
242 const OUString source2("1asfdasfd");
243 const OUString source3("AdfsaAUdsl10987");
244 const OUString source4("asdfa_mnvcnm");
245 const OUString source5("_asdf1");
246 const OUString source6("_6");
247 const OUString source7("joxclk_");
248 const OUString source8(" asdf ");
249 const OUString source9(" 19395 asdfa ");
250 const OUString source10("\n1\n2\na sdf");
251 const OUString source11("asdf.asdf");
252 const OUString source12("..");
254 std::vector<Symbol> symbols;
256 symbols = getSymbols(source1);
257 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
258 CPPUNIT_ASSERT_EQUAL(source1, symbols[0].text);
259 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
260 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
261 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
263 symbols = getSymbols(source2);
264 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
265 CPPUNIT_ASSERT(symbols[0].text.isEmpty()); // Can't start symbol with a digit
266 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[0].number, 1E-12);
267 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
268 CPPUNIT_ASSERT_EQUAL(OUString("asfdasfd"), symbols[1].text);
269 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
270 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
271 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
273 symbols = getSymbols(source3);
274 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
275 CPPUNIT_ASSERT_EQUAL(source3, symbols[0].text);
276 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
277 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
278 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
280 symbols = getSymbols(source4);
281 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
282 CPPUNIT_ASSERT_EQUAL(source4, symbols[0].text);
283 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
284 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
285 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
287 symbols = getSymbols(source5);
288 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
289 CPPUNIT_ASSERT_EQUAL(source5, symbols[0].text);
290 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
291 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
292 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
294 symbols = getSymbols(source6);
295 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
296 CPPUNIT_ASSERT_EQUAL(source6, symbols[0].text);
297 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
298 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
299 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
301 symbols = getSymbols(source7);
302 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
303 CPPUNIT_ASSERT_EQUAL(OUString("joxclk_"), symbols[0].text);
304 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
305 CPPUNIT_ASSERT_EQUAL(OUString("joxclk "), source7); // Change the trailing '_' to a ' '
306 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
307 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
309 symbols = getSymbols(source8);
310 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
311 CPPUNIT_ASSERT_EQUAL(OUString("asdf"), symbols[0].text);
312 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
313 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
314 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
316 symbols = getSymbols(source9);
317 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
318 CPPUNIT_ASSERT(symbols[0].text.isEmpty());
319 CPPUNIT_ASSERT_DOUBLES_EQUAL(19395.0, symbols[0].number, 1E-12);
320 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
321 CPPUNIT_ASSERT_EQUAL(OUString("asdfa"), symbols[1].text);
322 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
323 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
324 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
326 symbols = getSymbols(source10);
327 CPPUNIT_ASSERT_EQUAL(size_t(8), symbols.size());
328 CPPUNIT_ASSERT_EQUAL(cr, symbols[0].text);
329 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
330 CPPUNIT_ASSERT(symbols[1].text.isEmpty());
331 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[1].number, 1E-12);
332 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[1].type);
333 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
334 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
335 CPPUNIT_ASSERT(symbols[3].text.isEmpty());
336 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, symbols[3].number, 1E-12);
337 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[3].type);
338 CPPUNIT_ASSERT_EQUAL(cr, symbols[4].text);
339 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[4].type);
340 CPPUNIT_ASSERT_EQUAL(1u, (unsigned int)symbols[5].text.getLength());
341 CPPUNIT_ASSERT_EQUAL('a', (char)symbols[5].text[0]);
342 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[5].type);
343 CPPUNIT_ASSERT_EQUAL(OUString("sdf"), symbols[6].text);
344 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[6].type);
345 CPPUNIT_ASSERT_EQUAL(cr, symbols[7].text);
346 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[7].type);
348 symbols = getSymbols(source11);
349 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols.size());
350 CPPUNIT_ASSERT_EQUAL(asdf, symbols[0].text);
351 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
352 CPPUNIT_ASSERT_EQUAL(dot, symbols[1].text);
353 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
354 CPPUNIT_ASSERT_EQUAL(asdf, symbols[2].text);
355 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
356 CPPUNIT_ASSERT_EQUAL(cr, symbols[3].text);
357 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[3].type);
359 symbols = getSymbols(source12);
360 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
361 CPPUNIT_ASSERT_EQUAL(dot, symbols[0].text);
362 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
363 CPPUNIT_ASSERT_EQUAL(dot, symbols[1].text);
364 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
365 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
366 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
369 void ScannerTest::testComments()
371 const OUString source1("REM asdf");
372 const OUString source2("REMasdf");
373 const OUString source3("'asdf");
374 const OUString source4("asdf _\n'100");
375 const OUString source5("'asdf _\n100");
376 const OUString source6("'asdf _\n'100");
377 const OUString source7("'asdf _\n 1234 _\n asdf'");
379 std::vector<Symbol> symbols;
381 symbols = getSymbols(source1);
382 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols.size());
383 CPPUNIT_ASSERT_EQUAL(rem, symbols[0].text);
384 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
386 symbols = getSymbols(source2);
387 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
388 CPPUNIT_ASSERT_EQUAL(OUString("REMasdf"), symbols[0].text);
389 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
390 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
391 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
393 symbols = getSymbols(source3);
394 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols.size());
395 CPPUNIT_ASSERT_EQUAL(rem, symbols[0].text);
396 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
398 symbols = getSymbols(source4);
399 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
400 CPPUNIT_ASSERT_EQUAL(asdf, symbols[0].text);
401 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
402 CPPUNIT_ASSERT_EQUAL(rem, symbols[1].text);
403 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
405 symbols = getSymbols(source5);
406 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
407 CPPUNIT_ASSERT_EQUAL(rem, symbols[0].text);
408 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
409 CPPUNIT_ASSERT(symbols[1].text.isEmpty());
410 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, symbols[1].number, 1E-12);
411 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[1].type);
412 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
413 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
415 symbols = getSymbols(source6);
416 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
417 CPPUNIT_ASSERT_EQUAL(rem, symbols[0].text);
418 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
419 CPPUNIT_ASSERT_EQUAL(rem, symbols[1].text);
420 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
422 symbols = getSymbols(source7);
423 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols.size());
424 CPPUNIT_ASSERT_EQUAL(rem, symbols[0].text);
425 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
426 CPPUNIT_ASSERT(symbols[1].text.isEmpty());
427 CPPUNIT_ASSERT_DOUBLES_EQUAL(1234.0, symbols[1].number, 1E-12);
428 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[1].type);
429 CPPUNIT_ASSERT_EQUAL(asdf, symbols[2].text);
430 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
431 CPPUNIT_ASSERT_EQUAL(rem, symbols[3].text);
432 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[3].type);
435 void ScannerTest::testGoto()
437 const OUString source1("goto");
438 const OUString source2("go to");
439 const OUString source3("go\nto");
441 std::vector<Symbol> symbols;
443 symbols = getSymbols(source1);
444 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
445 CPPUNIT_ASSERT_EQUAL(goto_, symbols[0].text);
446 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
447 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
448 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
450 symbols = getSymbols(source2);
451 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
452 CPPUNIT_ASSERT_EQUAL(OUString("go"), symbols[0].text);
453 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
454 CPPUNIT_ASSERT_EQUAL(OUString("to"), symbols[1].text);
455 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
456 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
457 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
459 symbols = getSymbols(source3);
460 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols.size());
461 CPPUNIT_ASSERT_EQUAL(OUString("go"), symbols[0].text);
462 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
463 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
464 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
465 CPPUNIT_ASSERT_EQUAL(OUString("to"), symbols[2].text);
466 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[2].type);
467 CPPUNIT_ASSERT_EQUAL(cr, symbols[3].text);
468 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[3].type);
471 void ScannerTest::testGotoCompatible()
473 const OUString source1("goto");
474 const OUString source2("go to");
475 const OUString source3("go\nto");
477 std::vector<Symbol> symbols;
479 symbols = getSymbols(source1, true);
480 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
481 CPPUNIT_ASSERT_EQUAL(goto_, symbols[0].text);
482 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
484 symbols = getSymbols(source2, true);
485 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
486 CPPUNIT_ASSERT_EQUAL(goto_, symbols[0].text);
487 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
489 symbols = getSymbols(source3, true);
490 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols.size());
491 CPPUNIT_ASSERT_EQUAL(OUString("go"), symbols[0].text);
492 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
493 CPPUNIT_ASSERT_EQUAL(OUString("to"), symbols[2].text);
494 CPPUNIT_ASSERT_EQUAL(cr, symbols[3].text);
497 void ScannerTest::testExclamation()
499 const OUString source1("asdf!asdf");
500 const OUString source2("!1234");
501 const OUString source3("!_3");
502 const OUString source4("!$");
503 const OUString source5("!%");
504 const OUString source6("!\n");
506 std::vector<Symbol> symbols;
508 symbols = getSymbols(source1);
509 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols.size());
510 CPPUNIT_ASSERT_EQUAL(asdf, symbols[0].text);
511 CPPUNIT_ASSERT_EQUAL(excl, symbols[1].text);
512 CPPUNIT_ASSERT_EQUAL(asdf, symbols[2].text);
513 CPPUNIT_ASSERT_EQUAL(cr, symbols[3].text);
515 symbols = getSymbols(source2);
516 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
517 CPPUNIT_ASSERT_EQUAL(excl, symbols[0].text);
518 CPPUNIT_ASSERT(symbols[1].text.isEmpty());
519 CPPUNIT_ASSERT_DOUBLES_EQUAL(1234.0, symbols[1].number, 1E-12);
520 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
522 symbols = getSymbols(source3);
523 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
524 CPPUNIT_ASSERT_EQUAL(excl, symbols[0].text);
525 CPPUNIT_ASSERT_EQUAL(OUString("_3"), symbols[1].text);
526 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
528 symbols = getSymbols(source4);
529 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
530 CPPUNIT_ASSERT_EQUAL(excl, symbols[0].text);
531 CPPUNIT_ASSERT_EQUAL(OUString("$"), symbols[1].text);
532 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
534 symbols = getSymbols(source5);
535 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
536 CPPUNIT_ASSERT_EQUAL(excl, symbols[0].text);
537 CPPUNIT_ASSERT_EQUAL(OUString("%"), symbols[1].text);
538 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
540 symbols = getSymbols(source6);
541 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
542 CPPUNIT_ASSERT_EQUAL(excl, symbols[0].text);
543 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
546 void ScannerTest::testNumbers()
548 const OUString source1("12345");
549 const OUString source2("1.2.3");
550 const OUString source3("123.4");
551 const OUString source4("0.5");
552 const OUString source5("5.0");
553 const OUString source6("0.0");
554 const OUString source7("-3");
555 const OUString source8("-0.0");
556 const OUString source9("12dE3");
557 const OUString source10("12e3");
558 const OUString source11("12D+3");
559 const OUString source12("12e++3");
560 const OUString source13("12e-3");
561 const OUString source14("12e-3+");
562 const OUString source15("1,2,3");
563 const OUString source16("1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
564 const OUString source17("10e308");
566 std::vector<Symbol> symbols;
567 sal_Int32 errors;
569 symbols = getSymbols(source1, errors);
570 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
571 CPPUNIT_ASSERT_DOUBLES_EQUAL(12345.0, symbols[0].number, 1E-12);
572 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
573 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
574 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
576 symbols = getSymbols(source2, errors);
577 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
578 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.2, symbols[0].number, 1E-12);
579 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
580 CPPUNIT_ASSERT_DOUBLES_EQUAL(.3, symbols[1].number, 1E-12);
581 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[1].type);
582 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
583 CPPUNIT_ASSERT_EQUAL(1u, (unsigned int)errors);
585 symbols = getSymbols(source3, errors);
586 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
587 CPPUNIT_ASSERT_DOUBLES_EQUAL(123.4, symbols[0].number, 1E-12);
588 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
589 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
590 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
592 symbols = getSymbols(source4, errors);
593 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
594 CPPUNIT_ASSERT_DOUBLES_EQUAL(.5, symbols[0].number, 1E-12);
595 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
596 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
597 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
599 symbols = getSymbols(source5, errors);
600 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
601 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, symbols[0].number, 1E-12);
602 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
603 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
604 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
606 symbols = getSymbols(source6, errors);
607 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
608 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[0].number, 1E-12);
609 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
610 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
611 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
613 symbols = getSymbols(source7, errors);
614 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
615 CPPUNIT_ASSERT_EQUAL(OUString("-"), symbols[0].text);
616 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, symbols[1].number, 1E-12);
617 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[1].type);
618 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
619 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
621 symbols = getSymbols(source8, errors);
622 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
623 CPPUNIT_ASSERT_EQUAL(OUString("-"), symbols[0].text);
624 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[1].number, 1E-12);
625 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[1].type);
626 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
627 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
629 symbols = getSymbols(source9, errors);
630 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
631 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, symbols[0].number, 1E-12);
632 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
633 CPPUNIT_ASSERT_EQUAL(OUString("dE3"), symbols[1].text);
634 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
635 CPPUNIT_ASSERT_EQUAL(1u, (unsigned int)errors);
637 symbols = getSymbols(source10, errors);
638 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
639 CPPUNIT_ASSERT_DOUBLES_EQUAL(12000.0, symbols[0].number, 1E-12);
640 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
641 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
642 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
644 symbols = getSymbols(source11, errors);
645 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
646 CPPUNIT_ASSERT_DOUBLES_EQUAL(12000.0, symbols[0].number, 1E-12);
647 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
648 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
649 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
651 symbols = getSymbols(source12, errors);
652 CPPUNIT_ASSERT_EQUAL(size_t(6), symbols.size());
653 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, symbols[0].number, 1E-12);
654 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
655 CPPUNIT_ASSERT_EQUAL(OUString("e"), symbols[1].text);
656 CPPUNIT_ASSERT_EQUAL(OUString("+"), symbols[2].text);
657 CPPUNIT_ASSERT_EQUAL(OUString("+"), symbols[3].text);
658 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, symbols[4].number, 1E-12);
659 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[4].type);
660 CPPUNIT_ASSERT_EQUAL(cr, symbols[5].text);
661 CPPUNIT_ASSERT_EQUAL(1u, (unsigned int)errors);
663 symbols = getSymbols(source13, errors);
664 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
665 CPPUNIT_ASSERT_DOUBLES_EQUAL(.012, symbols[0].number, 1E-12);
666 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
667 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
668 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
670 symbols = getSymbols(source14, errors);
671 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
672 CPPUNIT_ASSERT_DOUBLES_EQUAL(.012, symbols[0].number, 1E-12);
673 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
674 CPPUNIT_ASSERT_EQUAL(OUString("+"), symbols[1].text);
675 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
676 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
678 symbols = getSymbols(source15, errors);
679 CPPUNIT_ASSERT_EQUAL(size_t(6), symbols.size());
680 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[0].number, 1E-12);
681 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
682 CPPUNIT_ASSERT_EQUAL(OUString(","), symbols[1].text);
683 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, symbols[2].number, 1E-12);
684 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[2].type);
685 CPPUNIT_ASSERT_EQUAL(OUString(","), symbols[3].text);
686 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, symbols[4].number, 1E-12);
687 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[4].type);
688 CPPUNIT_ASSERT_EQUAL(cr, symbols[5].text);
689 CPPUNIT_ASSERT_EQUAL(0u, (unsigned int)errors);
691 symbols = getSymbols(source16, errors);
692 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
693 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[0].number, 1E-12);
694 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
695 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
696 // This error is from a "buffer overflow" which is stupid because
697 // the buffer is artificially constrained by the scanner.
698 CPPUNIT_ASSERT_EQUAL(1u, (unsigned int)errors); // HACK
700 double fInf = 0.0;
701 rtl::math::setInf( &fInf, false);
702 symbols = getSymbols(source17, errors);
703 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
704 CPPUNIT_ASSERT_EQUAL(fInf, symbols[0].number);
705 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
706 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
707 CPPUNIT_ASSERT_EQUAL(1u, (unsigned int)errors); // math error, overflow
710 void ScannerTest::testDataType()
712 const OUString source1("asdf%");
713 const OUString source2("asdf&");
714 const OUString source3("asdf!");
715 const OUString source4("asdf#");
716 const OUString source5("asdf@");
717 const OUString source6("asdf$");
718 const OUString source7("asdf ");
720 std::vector<Symbol> symbols;
722 symbols = getSymbols(source1);
723 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
724 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
725 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
727 symbols = getSymbols(source2);
728 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
729 CPPUNIT_ASSERT_EQUAL(SbxLONG, symbols[0].type);
730 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
732 symbols = getSymbols(source3);
733 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
734 CPPUNIT_ASSERT_EQUAL(SbxSINGLE, symbols[0].type);
735 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
737 symbols = getSymbols(source4);
738 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
739 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[0].type);
740 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
742 symbols = getSymbols(source5);
743 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
744 CPPUNIT_ASSERT_EQUAL(SbxCURRENCY, symbols[0].type);
745 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
747 symbols = getSymbols(source6);
748 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
749 CPPUNIT_ASSERT_EQUAL(SbxSTRING, symbols[0].type);
750 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
752 symbols = getSymbols(source7);
753 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
754 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
755 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
758 void ScannerTest::testHexOctal()
760 const OUString source1("&HA");
761 const OUString source2("&HASDF");
762 const OUString source3("&H10");
763 const OUString source4("&&H&1H1&H1");
764 const OUString source5("&O&O12");
765 const OUString source6("&O10");
766 const OUString source7("&HO");
767 const OUString source8("&O123000000000000000000000");
768 const OUString source9("&H1.23");
770 std::vector<Symbol> symbols;
772 symbols = getSymbols(source1);
773 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
774 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, symbols[0].number, 1E-12);
775 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
776 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
777 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
779 symbols = getSymbols(source2);
780 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
781 CPPUNIT_ASSERT_DOUBLES_EQUAL(2783.0, symbols[0].number, 1E-12);
782 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
783 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
784 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
786 symbols = getSymbols(source3);
787 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
788 CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, symbols[0].number, 1E-12);
789 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
790 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
791 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
793 symbols = getSymbols(source4);
794 CPPUNIT_ASSERT_EQUAL(size_t(6), symbols.size());
795 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[0].number, 1E-12);
796 CPPUNIT_ASSERT_EQUAL(OUString("&"), symbols[0].text);
797 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[0].type);
798 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[1].number, 1E-12);
799 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[1].text);
800 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[1].type);
801 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[2].number, 1E-12);
802 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[2].text);
803 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[2].type);
804 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[3].number, 1E-12);
805 CPPUNIT_ASSERT_EQUAL(OUString("H1"), symbols[3].text);
806 CPPUNIT_ASSERT_EQUAL(SbxLONG, symbols[3].type);
807 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[4].number, 1E-12);
808 CPPUNIT_ASSERT_EQUAL(OUString("H1"), symbols[4].text);
809 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[4].type);
810 CPPUNIT_ASSERT_EQUAL(cr, symbols[5].text);
812 symbols = getSymbols(source5);
813 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
814 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[0].number, 1E-12);
815 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
816 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
817 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[1].number, 1E-12);
818 CPPUNIT_ASSERT_EQUAL(OUString("O12"), symbols[1].text);
819 CPPUNIT_ASSERT_EQUAL(SbxVARIANT, symbols[1].type);
820 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
822 symbols = getSymbols(source6);
823 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
824 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, symbols[0].number, 1E-12);
825 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
826 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
827 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
829 symbols = getSymbols(source7);
830 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
831 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[0].number, 1E-12);
832 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
833 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
835 symbols = getSymbols(source8);
836 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
837 // TODO: this line fails on 64 bit systems!!!
838 // CPPUNIT_ASSERT_EQUAL(symbols[0].number, -1744830464);
839 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
840 CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
842 symbols = getSymbols(source9);
843 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols.size());
844 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
845 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols[0].number, 1E-12);
846 CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
847 CPPUNIT_ASSERT_DOUBLES_EQUAL(.23, symbols[1].number, 1E-12);
848 CPPUNIT_ASSERT_EQUAL(OUString(), symbols[1].text);
849 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[1].type);
850 CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
853 // Put the test suite in the registry
854 CPPUNIT_TEST_SUITE_REGISTRATION(ScannerTest);
855 } // namespace
856 CPPUNIT_PLUGIN_IMPLEMENT();
858 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */