1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
18 #include <scanner.hxx>
33 * Perform tests on Scanner.
35 class ScannerTest
: public CppUnit::TestFixture
38 void testBlankLines();
43 void testGotoCompatible();
44 void testExclamation();
51 // Adds code needed to register the test suite
52 CPPUNIT_TEST_SUITE(ScannerTest
);
54 // Declares the method as a test to call
55 CPPUNIT_TEST(testBlankLines
);
56 CPPUNIT_TEST(testOperators
);
57 CPPUNIT_TEST(testAlphanum
);
58 CPPUNIT_TEST(testComments
);
59 CPPUNIT_TEST(testGoto
);
60 CPPUNIT_TEST(testGotoCompatible
);
61 CPPUNIT_TEST(testExclamation
);
62 CPPUNIT_TEST(testNumbers
);
63 CPPUNIT_TEST(testDataType
);
64 CPPUNIT_TEST(testHexOctal
);
65 CPPUNIT_TEST(testTdf103104
);
66 CPPUNIT_TEST(testTdf136032
);
68 // End of test suite definition
69 CPPUNIT_TEST_SUITE_END();
72 const OUString cr
= "\n";
73 const OUString rem
= "REM";
74 const OUString asdf
= "asdf";
75 const OUString dot
= ".";
76 const OUString goto_
= "goto";
77 const OUString excl
= "!";
79 std::vector
<Symbol
> getSymbols(const OUString
& source
, sal_Int32
& errors
, bool bCompatible
= false)
81 std::vector
<Symbol
> symbols
;
82 SbiScanner
scanner(source
);
83 scanner
.EnableErrors();
84 scanner
.SetCompatible(bCompatible
);
85 while (scanner
.NextSym())
88 symbol
.line
= scanner
.GetLine();
89 symbol
.col1
= scanner
.GetCol1();
90 symbol
.text
= scanner
.GetSym();
91 symbol
.number
= scanner
.GetDbl();
92 symbol
.type
= scanner
.GetType();
93 symbol
.ws
= scanner
.WhiteSpace();
94 symbols
.push_back(symbol
);
96 errors
= scanner
.GetErrors();
100 std::vector
<Symbol
> getSymbols(const OUString
& source
, bool bCompatible
= false)
103 return getSymbols(source
, i
, bCompatible
);
106 void ScannerTest::testBlankLines()
108 std::vector
<Symbol
> symbols
;
109 symbols
= getSymbols("");
110 CPPUNIT_ASSERT(symbols
.empty());
112 symbols
= getSymbols("\r\n");
113 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols
.size());
114 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
115 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
117 symbols
= getSymbols("\n");
118 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols
.size());
119 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
120 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
122 symbols
= getSymbols("\r");
123 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols
.size());
124 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
125 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
127 symbols
= getSymbols("\r\n\r\n");
128 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
129 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
130 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
131 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
132 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
134 symbols
= getSymbols("\n\r");
135 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
136 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
137 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
138 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
139 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
141 symbols
= getSymbols("\n\r\n");
142 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
143 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
144 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
145 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
146 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
148 symbols
= getSymbols("\r\n\r");
149 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
150 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
151 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
152 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
153 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
155 symbols
= getSymbols(" ");
156 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols
.size());
157 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
158 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
161 void ScannerTest::testOperators()
163 const OUString
sourceE("=");
164 const OUString
sourceLT("<");
165 const OUString
sourceGT(">");
166 const OUString
sourceLTE("<=");
167 const OUString
sourceGTE(">=");
168 const OUString
sourceNE("<>");
169 const OUString
sourceA(":=");
170 const OUString
sourceNot("Not");
172 std::vector
<Symbol
> symbols
;
174 symbols
= getSymbols(sourceE
);
175 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
176 CPPUNIT_ASSERT_EQUAL(sourceE
, symbols
[0].text
);
177 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
178 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
179 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
181 symbols
= getSymbols(sourceLT
);
182 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
183 CPPUNIT_ASSERT_EQUAL(sourceLT
, symbols
[0].text
);
184 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
185 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
186 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
188 symbols
= getSymbols(sourceGT
);
189 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
190 CPPUNIT_ASSERT_EQUAL(sourceGT
, symbols
[0].text
);
191 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
192 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
193 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
195 symbols
= getSymbols(sourceLTE
);
196 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
197 CPPUNIT_ASSERT_EQUAL(sourceLTE
, symbols
[0].text
);
198 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
199 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
200 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
202 symbols
= getSymbols(sourceGTE
);
203 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
204 CPPUNIT_ASSERT_EQUAL(sourceGTE
, symbols
[0].text
);
205 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
206 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
207 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
209 symbols
= getSymbols("==");
210 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
211 CPPUNIT_ASSERT_EQUAL(sourceE
, symbols
[0].text
);
212 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
213 CPPUNIT_ASSERT_EQUAL(sourceE
, symbols
[1].text
);
214 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
215 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
216 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
218 symbols
= getSymbols(sourceNE
);
219 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
220 CPPUNIT_ASSERT_EQUAL(sourceNE
, symbols
[0].text
);
221 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
222 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
223 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
225 symbols
= getSymbols(sourceA
);
226 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
227 CPPUNIT_ASSERT_EQUAL(sourceA
, symbols
[0].text
);
228 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
229 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
230 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
232 symbols
= getSymbols(sourceNot
);
233 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
234 CPPUNIT_ASSERT_EQUAL(sourceNot
, symbols
[0].text
);
235 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
236 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
237 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
240 void ScannerTest::testAlphanum()
242 const OUString
source1("asdfghefg");
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_");
249 std::vector
<Symbol
> symbols
;
251 symbols
= getSymbols(source1
);
252 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
253 CPPUNIT_ASSERT_EQUAL(source1
, symbols
[0].text
);
254 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
255 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
256 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
258 symbols
= getSymbols("1asfdasfd");
259 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
260 CPPUNIT_ASSERT(symbols
[0].text
.isEmpty()); // Can't start symbol with a digit
261 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[0].number
, 1E-12);
262 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
263 CPPUNIT_ASSERT_EQUAL(OUString("asfdasfd"), symbols
[1].text
);
264 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
265 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
266 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
268 symbols
= getSymbols(source3
);
269 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
270 CPPUNIT_ASSERT_EQUAL(source3
, symbols
[0].text
);
271 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
272 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
273 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
275 symbols
= getSymbols(source4
);
276 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
277 CPPUNIT_ASSERT_EQUAL(source4
, symbols
[0].text
);
278 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
279 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
280 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
282 symbols
= getSymbols(source5
);
283 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
284 CPPUNIT_ASSERT_EQUAL(source5
, symbols
[0].text
);
285 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
286 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
287 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
289 symbols
= getSymbols(source6
);
290 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
291 CPPUNIT_ASSERT_EQUAL(source6
, symbols
[0].text
);
292 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
293 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
294 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
296 symbols
= getSymbols(source7
);
297 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
298 CPPUNIT_ASSERT_EQUAL(OUString("joxclk_"), symbols
[0].text
);
299 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
300 // tdf#125637 - don't change underscore to space
301 CPPUNIT_ASSERT_EQUAL(OUString("joxclk_"), source7
);
302 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
303 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
305 symbols
= getSymbols(" asdf ");
306 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
307 CPPUNIT_ASSERT_EQUAL(OUString("asdf"), symbols
[0].text
);
308 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
309 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
310 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
312 symbols
= getSymbols(" 19395 asdfa ");
313 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
314 CPPUNIT_ASSERT(symbols
[0].text
.isEmpty());
315 CPPUNIT_ASSERT_DOUBLES_EQUAL(19395.0, symbols
[0].number
, 1E-12);
316 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
317 CPPUNIT_ASSERT_EQUAL(OUString("asdfa"), symbols
[1].text
);
318 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
319 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
320 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
322 symbols
= getSymbols("\n1\n2\na sdf");
323 CPPUNIT_ASSERT_EQUAL(size_t(8), symbols
.size());
324 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[0].text
);
325 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
326 CPPUNIT_ASSERT(symbols
[1].text
.isEmpty());
327 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[1].number
, 1E-12);
328 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[1].type
);
329 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
330 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
331 CPPUNIT_ASSERT(symbols
[3].text
.isEmpty());
332 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, symbols
[3].number
, 1E-12);
333 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[3].type
);
334 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[4].text
);
335 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[4].type
);
336 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(symbols
[5].text
.getLength()));
337 CPPUNIT_ASSERT_EQUAL('a', static_cast<char>(symbols
[5].text
[0]));
338 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[5].type
);
339 CPPUNIT_ASSERT_EQUAL(OUString("sdf"), symbols
[6].text
);
340 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[6].type
);
341 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[7].text
);
342 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[7].type
);
344 symbols
= getSymbols("asdf.asdf");
345 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
346 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[0].text
);
347 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
348 CPPUNIT_ASSERT_EQUAL(dot
, symbols
[1].text
);
349 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
350 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[2].text
);
351 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
352 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[3].text
);
353 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[3].type
);
355 symbols
= getSymbols("..");
356 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
357 CPPUNIT_ASSERT_EQUAL(dot
, symbols
[0].text
);
358 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
359 CPPUNIT_ASSERT_EQUAL(dot
, symbols
[1].text
);
360 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
361 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
362 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
365 void ScannerTest::testComments()
367 std::vector
<Symbol
> symbols
;
369 symbols
= getSymbols("REM asdf");
370 CPPUNIT_ASSERT_EQUAL(size_t(1), symbols
.size());
371 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[0].text
);
372 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
374 symbols
= getSymbols("REMasdf");
375 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
376 CPPUNIT_ASSERT_EQUAL(OUString("REMasdf"), symbols
[0].text
);
377 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
378 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
379 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
381 symbols
= getSymbols("'asdf");
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("asdf _\n'100");
387 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
388 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[0].text
);
389 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
390 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[1].text
);
391 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
393 symbols
= getSymbols("'asdf _\n100");
394 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
395 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[0].text
);
396 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
397 CPPUNIT_ASSERT(symbols
[1].text
.isEmpty());
398 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, symbols
[1].number
, 1E-12);
399 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[1].type
);
400 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
401 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
403 symbols
= getSymbols("'asdf _\n'100");
404 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
405 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[0].text
);
406 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
407 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[1].text
);
408 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
410 symbols
= getSymbols("'asdf _\n 1234 _\n asdf'");
411 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
412 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[0].text
);
413 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
414 CPPUNIT_ASSERT(symbols
[1].text
.isEmpty());
415 CPPUNIT_ASSERT_DOUBLES_EQUAL(1234.0, symbols
[1].number
, 1E-12);
416 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[1].type
);
417 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[2].text
);
418 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
419 CPPUNIT_ASSERT_EQUAL(rem
, symbols
[3].text
);
420 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[3].type
);
423 void ScannerTest::testGoto()
425 std::vector
<Symbol
> symbols
;
427 symbols
= getSymbols("goto");
428 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
429 CPPUNIT_ASSERT_EQUAL(goto_
, symbols
[0].text
);
430 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
431 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
432 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
434 symbols
= getSymbols("go to");
435 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
436 CPPUNIT_ASSERT_EQUAL(OUString("go"), symbols
[0].text
);
437 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
438 CPPUNIT_ASSERT_EQUAL(OUString("to"), symbols
[1].text
);
439 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
440 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
441 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
443 symbols
= getSymbols("go\nto");
444 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
445 CPPUNIT_ASSERT_EQUAL(OUString("go"), 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
);
449 CPPUNIT_ASSERT_EQUAL(OUString("to"), symbols
[2].text
);
450 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[2].type
);
451 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[3].text
);
452 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[3].type
);
455 void ScannerTest::testGotoCompatible()
457 std::vector
<Symbol
> symbols
;
459 symbols
= getSymbols("goto", true);
460 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
461 CPPUNIT_ASSERT_EQUAL(goto_
, symbols
[0].text
);
462 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
464 symbols
= getSymbols("go to", true);
465 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
466 CPPUNIT_ASSERT_EQUAL(goto_
, symbols
[0].text
);
467 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
469 symbols
= getSymbols("go\nto", true);
470 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
471 CPPUNIT_ASSERT_EQUAL(OUString("go"), symbols
[0].text
);
472 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
473 CPPUNIT_ASSERT_EQUAL(OUString("to"), symbols
[2].text
);
474 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[3].text
);
477 void ScannerTest::testExclamation()
479 std::vector
<Symbol
> symbols
;
481 symbols
= getSymbols("asdf!asdf");
482 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
483 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[0].text
);
484 CPPUNIT_ASSERT_EQUAL(excl
, symbols
[1].text
);
485 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[2].text
);
486 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[3].text
);
488 symbols
= getSymbols("!1234");
489 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
490 CPPUNIT_ASSERT_EQUAL(excl
, symbols
[0].text
);
491 CPPUNIT_ASSERT(symbols
[1].text
.isEmpty());
492 CPPUNIT_ASSERT_DOUBLES_EQUAL(1234.0, symbols
[1].number
, 1E-12);
493 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
495 symbols
= getSymbols("!_3");
496 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
497 CPPUNIT_ASSERT_EQUAL(excl
, symbols
[0].text
);
498 CPPUNIT_ASSERT_EQUAL(OUString("_3"), symbols
[1].text
);
499 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
501 symbols
= getSymbols("!$");
502 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
503 CPPUNIT_ASSERT_EQUAL(excl
, symbols
[0].text
);
504 CPPUNIT_ASSERT_EQUAL(OUString("$"), symbols
[1].text
);
505 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
507 symbols
= getSymbols("!%");
508 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
509 CPPUNIT_ASSERT_EQUAL(excl
, symbols
[0].text
);
510 CPPUNIT_ASSERT_EQUAL(OUString("%"), symbols
[1].text
);
511 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
513 symbols
= getSymbols("!\n");
514 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
515 CPPUNIT_ASSERT_EQUAL(excl
, symbols
[0].text
);
516 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
519 void ScannerTest::testNumbers()
521 std::vector
<Symbol
> symbols
;
524 symbols
= getSymbols("12345", errors
);
525 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
526 CPPUNIT_ASSERT_DOUBLES_EQUAL(12345.0, symbols
[0].number
, 1E-12);
527 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
528 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
529 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
531 symbols
= getSymbols("1.2.3", errors
);
532 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
533 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.2, symbols
[0].number
, 1E-12);
534 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
535 CPPUNIT_ASSERT_DOUBLES_EQUAL(.3, symbols
[1].number
, 1E-12);
536 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[1].type
);
537 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
538 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
540 symbols
= getSymbols("123.4", errors
);
541 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
542 CPPUNIT_ASSERT_DOUBLES_EQUAL(123.4, symbols
[0].number
, 1E-12);
543 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
544 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
545 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
547 symbols
= getSymbols("0.5", errors
);
548 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
549 CPPUNIT_ASSERT_DOUBLES_EQUAL(.5, symbols
[0].number
, 1E-12);
550 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
551 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
552 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
554 symbols
= getSymbols("5.0", errors
);
555 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
556 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, symbols
[0].number
, 1E-12);
557 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
558 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
559 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
561 symbols
= getSymbols("0.0", errors
);
562 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
563 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
564 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
565 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
566 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
568 symbols
= getSymbols("-3", errors
);
569 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
570 CPPUNIT_ASSERT_EQUAL(OUString("-"), symbols
[0].text
);
571 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, symbols
[1].number
, 1E-12);
572 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[1].type
);
573 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
574 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
576 symbols
= getSymbols("-0.0", errors
);
577 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
578 CPPUNIT_ASSERT_EQUAL(OUString("-"), symbols
[0].text
);
579 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[1].number
, 1E-12);
580 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[1].type
);
581 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
582 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
584 symbols
= getSymbols("12dE3", errors
);
585 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
586 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, symbols
[0].number
, 1E-12);
587 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
588 CPPUNIT_ASSERT_EQUAL(OUString("dE3"), symbols
[1].text
);
589 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
590 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
592 symbols
= getSymbols("12e3", errors
);
593 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
594 CPPUNIT_ASSERT_DOUBLES_EQUAL(12000.0, 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, static_cast<unsigned int>(errors
));
599 symbols
= getSymbols("12D+3", errors
);
600 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
601 CPPUNIT_ASSERT_DOUBLES_EQUAL(12000.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, static_cast<unsigned int>(errors
));
606 symbols
= getSymbols("12e++3", errors
);
607 CPPUNIT_ASSERT_EQUAL(size_t(6), symbols
.size());
608 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, symbols
[0].number
, 1E-12);
609 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
610 CPPUNIT_ASSERT_EQUAL(OUString("e"), symbols
[1].text
);
611 CPPUNIT_ASSERT_EQUAL(OUString("+"), symbols
[2].text
);
612 CPPUNIT_ASSERT_EQUAL(OUString("+"), symbols
[3].text
);
613 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, symbols
[4].number
, 1E-12);
614 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[4].type
);
615 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[5].text
);
616 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
618 symbols
= getSymbols("12e-3", errors
);
619 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
620 CPPUNIT_ASSERT_DOUBLES_EQUAL(.012, symbols
[0].number
, 1E-12);
621 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
622 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
623 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
625 symbols
= getSymbols("12e-3+", errors
);
626 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
627 CPPUNIT_ASSERT_DOUBLES_EQUAL(.012, symbols
[0].number
, 1E-12);
628 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
629 CPPUNIT_ASSERT_EQUAL(OUString("+"), symbols
[1].text
);
630 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
631 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
633 symbols
= getSymbols("1,2,3", errors
);
634 CPPUNIT_ASSERT_EQUAL(size_t(6), symbols
.size());
635 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[0].number
, 1E-12);
636 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
637 CPPUNIT_ASSERT_EQUAL(OUString(","), symbols
[1].text
);
638 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, symbols
[2].number
, 1E-12);
639 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[2].type
);
640 CPPUNIT_ASSERT_EQUAL(OUString(","), symbols
[3].text
);
641 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, symbols
[4].number
, 1E-12);
642 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[4].type
);
643 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[5].text
);
644 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
646 symbols
= getSymbols("1."
647 "0000000000000000000000000000000000000000000000000000000000000000000000000"
648 "000000000000000000000000000000000000000000000000000",
650 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
651 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[0].number
, 1E-12);
652 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
653 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
654 // This error is from a "buffer overflow" which is stupid because
655 // the buffer is artificially constrained by the scanner.
656 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
)); // HACK
658 symbols
= getSymbols("10e308", errors
);
659 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
660 CPPUNIT_ASSERT_EQUAL(std::numeric_limits
<double>::infinity(), symbols
[0].number
);
661 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
662 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
663 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
)); // math error, overflow
665 // trailing data type character % = SbxINTEGER
666 symbols
= getSymbols("1.23%");
667 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
668 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23, symbols
[0].number
, 1E-12);
669 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
670 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
671 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
673 // trailing data type character & = SbxLONG
674 symbols
= getSymbols("1.23&");
675 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
676 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23, symbols
[0].number
, 1E-12);
677 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
678 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
679 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
681 // trailing data type character ! = SbxSINGLE
682 symbols
= getSymbols("1.23!");
683 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
684 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23, symbols
[0].number
, 1E-12);
685 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
686 CPPUNIT_ASSERT_EQUAL(SbxSINGLE
, symbols
[0].type
);
687 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
689 // trailing data type character # = SbxDOUBLE
690 symbols
= getSymbols("1.23#");
691 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
692 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23, symbols
[0].number
, 1E-12);
693 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
694 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
695 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
697 // trailing data type character @ = SbxCURRENCY
698 symbols
= getSymbols("1.23@");
699 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
700 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23, symbols
[0].number
, 1E-12);
701 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
702 CPPUNIT_ASSERT_EQUAL(SbxCURRENCY
, symbols
[0].type
);
703 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
705 // trailing data type character $ = SbxSTRING
706 symbols
= getSymbols("1.23$", errors
);
707 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
708 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23, symbols
[0].number
, 1E-12);
709 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
710 CPPUNIT_ASSERT_EQUAL(SbxSTRING
, symbols
[0].type
);
711 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
712 // ERRCODE_BASIC_SYNTAX
713 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
716 void ScannerTest::testDataType()
718 std::vector
<Symbol
> symbols
;
720 symbols
= getSymbols("asdf%");
721 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
722 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
723 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
725 symbols
= getSymbols("asdf&");
726 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
727 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
728 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
730 symbols
= getSymbols("asdf!");
731 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
732 CPPUNIT_ASSERT_EQUAL(SbxSINGLE
, symbols
[0].type
);
733 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
735 symbols
= getSymbols("asdf#");
736 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
737 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
738 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
740 symbols
= getSymbols("asdf@");
741 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
742 CPPUNIT_ASSERT_EQUAL(SbxCURRENCY
, symbols
[0].type
);
743 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
745 symbols
= getSymbols("asdf$");
746 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
747 CPPUNIT_ASSERT_EQUAL(SbxSTRING
, symbols
[0].type
);
748 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
750 symbols
= getSymbols("asdf ");
751 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
752 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
753 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
756 void ScannerTest::testHexOctal()
759 std::vector
<Symbol
> symbols
;
761 symbols
= getSymbols("&HA");
762 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
763 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, symbols
[0].number
, 1E-12);
764 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
765 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
766 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
768 symbols
= getSymbols("&HASDF");
769 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
770 CPPUNIT_ASSERT_DOUBLES_EQUAL(2783.0, symbols
[0].number
, 1E-12);
771 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
772 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
773 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
775 symbols
= getSymbols("&H10");
776 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
777 CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, symbols
[0].number
, 1E-12);
778 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
779 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
780 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
782 symbols
= getSymbols("&&H&1H1&H1");
783 CPPUNIT_ASSERT_EQUAL(size_t(6), symbols
.size());
784 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
785 CPPUNIT_ASSERT_EQUAL(OUString("&"), symbols
[0].text
);
786 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[0].type
);
787 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[1].number
, 1E-12);
788 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[1].text
);
789 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[1].type
);
790 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[2].number
, 1E-12);
791 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[2].text
);
792 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[2].type
);
793 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[3].number
, 1E-12);
794 CPPUNIT_ASSERT_EQUAL(OUString("H1"), symbols
[3].text
);
795 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[3].type
);
796 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[4].number
, 1E-12);
797 CPPUNIT_ASSERT_EQUAL(OUString("H1"), symbols
[4].text
);
798 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[4].type
);
799 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[5].text
);
801 symbols
= getSymbols("&O&O12");
802 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
803 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
804 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
805 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
806 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[1].number
, 1E-12);
807 CPPUNIT_ASSERT_EQUAL(OUString("O12"), symbols
[1].text
);
808 CPPUNIT_ASSERT_EQUAL(SbxVARIANT
, symbols
[1].type
);
809 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
811 symbols
= getSymbols("&O10");
812 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
813 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, symbols
[0].number
, 1E-12);
814 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
815 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
816 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
818 symbols
= getSymbols("&HO");
819 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
820 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
821 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
822 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
824 symbols
= getSymbols("&O123000000000000000000000");
825 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
826 // TODO: this line fails on 64 bit systems!!!
827 // CPPUNIT_ASSERT_EQUAL(symbols[0].number, -1744830464);
828 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
829 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
831 symbols
= getSymbols("&H1.23");
832 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
833 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
834 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, symbols
[0].number
, 1E-12);
835 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
836 CPPUNIT_ASSERT_DOUBLES_EQUAL(.23, symbols
[1].number
, 1E-12);
837 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[1].text
);
838 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[1].type
);
839 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
841 /* tdf#62323, tdf#62326 - conversion of Hex literals to basic signed Integers */
844 symbols
= getSymbols("&H0");
845 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
846 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
847 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
848 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
849 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
852 symbols
= getSymbols("&H8000");
853 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
854 CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMININT
, symbols
[0].number
, 1E-12);
855 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
856 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
857 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
859 // &H80000000 = -2147483648
860 symbols
= getSymbols("&H80000000");
861 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
862 CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMINLNG
, symbols
[0].number
, 1E-12);
863 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
864 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
865 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
868 symbols
= getSymbols("&HFFFF");
869 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
870 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols
[0].number
, 1E-12);
871 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
872 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
873 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
876 symbols
= getSymbols("&HFFFFFFFF");
877 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
878 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols
[0].number
, 1E-12);
879 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
880 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
881 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
884 symbols
= getSymbols("&H7FFF");
885 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
886 CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMAXINT
, symbols
[0].number
, 1E-12);
887 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
888 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
889 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
891 // &H7FFFFFFF = 2147483647
892 symbols
= getSymbols("&H7FFFFFFF");
893 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
894 CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMAXLNG
, symbols
[0].number
, 1E-12);
895 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
896 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
897 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
899 /* tdf#130476 - trailing data type characters */
902 symbols
= getSymbols("&H0%");
903 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
904 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
905 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
906 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
907 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
910 symbols
= getSymbols("&H0&");
911 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
912 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
913 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
914 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
915 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
918 symbols
= getSymbols("&H0!");
919 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
920 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
921 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
922 CPPUNIT_ASSERT_EQUAL(SbxSINGLE
, symbols
[0].type
);
923 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
926 symbols
= getSymbols("&H0#");
927 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
928 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
929 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
930 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
931 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
934 symbols
= getSymbols("&H0@");
935 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
936 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
937 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
938 CPPUNIT_ASSERT_EQUAL(SbxCURRENCY
, symbols
[0].type
);
939 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
942 symbols
= getSymbols("&H0$", errors
);
943 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
944 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
945 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
946 CPPUNIT_ASSERT_EQUAL(SbxSTRING
, symbols
[0].type
);
947 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
948 // ERRCODE_BASIC_SYNTAX
949 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
952 symbols
= getSymbols("&O0%");
953 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
954 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
955 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
956 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
957 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
960 symbols
= getSymbols("&O0&");
961 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
962 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
963 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
964 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
965 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
968 symbols
= getSymbols("&O0!");
969 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
970 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
971 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
972 CPPUNIT_ASSERT_EQUAL(SbxSINGLE
, symbols
[0].type
);
973 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
976 symbols
= getSymbols("&O0#");
977 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
978 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
979 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
980 CPPUNIT_ASSERT_EQUAL(SbxDOUBLE
, symbols
[0].type
);
981 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
984 symbols
= getSymbols("&O0@");
985 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
986 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
987 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
988 CPPUNIT_ASSERT_EQUAL(SbxCURRENCY
, symbols
[0].type
);
989 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
992 symbols
= getSymbols("&O0$", errors
);
993 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
994 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols
[0].number
, 1E-12);
995 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
996 CPPUNIT_ASSERT_EQUAL(SbxSTRING
, symbols
[0].type
);
997 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
998 // ERRCODE_BASIC_SYNTAX
999 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
1001 // maximum for Hex % = SbxINTEGER
1002 symbols
= getSymbols("&HFFFF%");
1003 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1004 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols
[0].number
, 1E-12);
1005 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1006 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
1007 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1009 // overflow for Hex % = SbxINTEGER
1010 symbols
= getSymbols("&H10000%", errors
);
1011 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1012 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, symbols
[0].number
, 1E-12);
1013 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1014 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
1015 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1016 // ERRCODE_BASIC_MATH_OVERFLOW
1017 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
1019 // maximum for Octal % = SbxINTEGER
1020 symbols
= getSymbols("&O177777%");
1021 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1022 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols
[0].number
, 1E-12);
1023 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1024 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
1025 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1027 // overflow for Octal % = SbxINTEGER
1028 symbols
= getSymbols("&O200000%", errors
);
1029 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1030 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, symbols
[0].number
, 1E-12);
1031 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1032 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
1033 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1034 // ERRCODE_BASIC_MATH_OVERFLOW
1035 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
1037 // maximum for Hex & = SbxLONG
1038 symbols
= getSymbols("&H7FFFFFFF&");
1039 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1040 CPPUNIT_ASSERT_DOUBLES_EQUAL(2147483647.0, symbols
[0].number
, 1E-12);
1041 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1042 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1043 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1045 // minimum for Hex & = SbxLONG
1046 symbols
= getSymbols("&H80000000&");
1047 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1048 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2147483648.0, symbols
[0].number
, 1E-12);
1049 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1050 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1051 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1053 // overflow for Hex & = SbxLONG
1054 symbols
= getSymbols("&H100000000&", errors
);
1055 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1056 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, symbols
[0].number
, 1E-12);
1057 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1058 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1059 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1060 // ERRCODE_BASIC_MATH_OVERFLOW
1061 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
1063 // maximum for Octal & = SbxLONG
1064 symbols
= getSymbols("&O17777777777&");
1065 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1066 CPPUNIT_ASSERT_DOUBLES_EQUAL(2147483647.0, symbols
[0].number
, 1E-12);
1067 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1068 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1069 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1071 // minimum for Octal & = SbxLONG
1072 symbols
= getSymbols("&O20000000000&", errors
);
1073 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1074 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2147483648.0, symbols
[0].number
, 1E-12);
1075 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1076 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1077 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1079 // overflow for Octal & = SbxLONG
1080 symbols
= getSymbols("&O40000000000&", errors
);
1081 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1082 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, symbols
[0].number
, 1E-12);
1083 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1084 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1085 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1086 // ERRCODE_BASIC_MATH_OVERFLOW
1087 CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors
));
1089 /* test for leading zeros */
1091 // &H0000000FFFF = 65535
1092 symbols
= getSymbols("&H0000000FFFF");
1093 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1094 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols
[0].number
, 1E-12);
1095 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1096 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
1097 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1100 symbols
= getSymbols("&O00000123");
1101 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1102 CPPUNIT_ASSERT_DOUBLES_EQUAL(83.0, symbols
[0].number
, 1E-12);
1103 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1104 CPPUNIT_ASSERT_EQUAL(SbxINTEGER
, symbols
[0].type
);
1105 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1107 symbols
= getSymbols("&O7777777");
1108 CPPUNIT_ASSERT_EQUAL(size_t(2), symbols
.size());
1109 CPPUNIT_ASSERT_DOUBLES_EQUAL(2097151.0, symbols
[0].number
, 1E-12);
1110 CPPUNIT_ASSERT_EQUAL(OUString(), symbols
[0].text
);
1111 CPPUNIT_ASSERT_EQUAL(SbxLONG
, symbols
[0].type
);
1112 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[1].text
);
1115 void ScannerTest::testTdf103104()
1117 std::vector
<Symbol
> symbols
;
1119 symbols
= getSymbols("asdf _\n asdf");
1120 CPPUNIT_ASSERT_EQUAL(size_t(3), symbols
.size());
1121 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[0].text
);
1122 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[1].text
);
1123 CPPUNIT_ASSERT(symbols
[1].ws
);
1124 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[2].text
);
1126 symbols
= getSymbols("asdf. _\n asdf");
1127 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
1128 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[0].text
);
1129 CPPUNIT_ASSERT_EQUAL(dot
, symbols
[1].text
);
1130 CPPUNIT_ASSERT(!symbols
[1].ws
);
1131 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[2].text
);
1132 CPPUNIT_ASSERT(symbols
[2].ws
);
1133 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[3].text
);
1135 symbols
= getSymbols("asdf _\n .asdf");
1136 CPPUNIT_ASSERT_EQUAL(size_t(4), symbols
.size());
1137 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[0].text
);
1138 CPPUNIT_ASSERT_EQUAL(dot
, symbols
[1].text
);
1139 CPPUNIT_ASSERT(!symbols
[1].ws
);
1140 CPPUNIT_ASSERT_EQUAL(asdf
, symbols
[2].text
);
1141 CPPUNIT_ASSERT(!symbols
[2].ws
);
1142 CPPUNIT_ASSERT_EQUAL(cr
, symbols
[3].text
);
1145 void ScannerTest::testTdf136032()
1147 std::vector
<Symbol
> symbols
;
1150 // tdf#136032 - abort scan of a string beginning with a hashtag,
1151 // if a comma/whitespace is found. Otherwise, the compiler raises a syntax error.
1152 symbols
= getSymbols("Print #i,\"A#B\"", errors
);
1153 CPPUNIT_ASSERT_EQUAL(size_t(5), symbols
.size());
1154 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
1155 symbols
= getSymbols("Print #i, \"A#B\"", errors
);
1156 CPPUNIT_ASSERT_EQUAL(size_t(5), symbols
.size());
1157 CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned int>(errors
));
1160 // Put the test suite in the registry
1161 CPPUNIT_TEST_SUITE_REGISTRATION(ScannerTest
);
1163 CPPUNIT_PLUGIN_IMPLEMENT();
1165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */