Changeset 55
- Timestamp:
- 03/10/08 12:46:31 (9 months ago)
- Files:
-
- trunk/tango/scrapple/text/convert/parseFrom.d (modified) (1 diff)
- trunk/tango/scrapple/text/convert/parseTo.d (modified) (2 diffs)
- trunk/tests/dsss.conf (modified) (1 diff)
- trunk/tests/unittests.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tango/scrapple/text/convert/parseFrom.d
r47 r55 313 313 return ((c <= '\r' && c >= '\a') || c == '\"' || c == '\'' || c == '\\'); 314 314 } 315 // Warning: this DOES NOT check c is escapable315 // Throws on unsupported escape sequences; however this should never actually happen within parseFrom. 316 316 private char replaceEscapableChar (char c) { 317 static char[char] escCharsRev; // reversed escChars 318 static bool escCharsRevFilled; // will be initialised false 319 320 if (!escCharsRevFilled) { // only do this once 321 // map of all supported escape sequences 322 escCharsRev = ['"' : '"', '\'' : '\'', 323 '\\' : '\\', '\a' : 'a', 324 '\b' : 'b', '\f' : 'f', 325 '\n' : 'n', '\r' : 'r', 326 '\t' : 't', '\v' : 'v']; 327 escCharsRevFilled = true; 328 } 329 330 return escCharsRev[c]; 331 } 332 333 debug (UnitTest) unittest { 334 // all utility functions should be well-enough used not to need testing 317 // This code was generated: 318 if (c <= '\v') { 319 if (c <= '\b') { 320 if (c == '\a') { 321 return 'a'; 322 } else if (c == '\b') { 323 return 'b'; 324 } 325 } else { 326 if (c == '\t') { 327 return 't'; 328 } else if (c == '\n') { 329 return 'n'; 330 } else if (c == '\v') { 331 return 'v'; 332 } 333 } 334 } else { 335 if (c <= '\r') { 336 if (c == '\f') { 337 return 'f'; 338 } else if (c == '\r') { 339 return 'r'; 340 } 341 } else { 342 if (c == '\"') { 343 return '\"'; 344 } else if (c == '\'') { 345 return '\''; 346 } else if (c == '\\') { 347 return '\\'; 348 } 349 } 350 } 351 352 // if we haven't returned: 353 throw new IllegalArgumentException ("Character is not escapable (internal parseFrom error)"); 354 } 355 356 debug (UnitTest) { 357 import tango.io.Console; 358 359 unittest { 360 Cout ("Running unittest: parseFrom ...").flush; 361 362 assert (parseFrom!(char[]) ("\a\b\t\n\v\f\r\"\'\\") == "\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\""); 363 364 Cout (" complete").newline; 365 } 335 366 } 336 367 //END Utility funcs trunk/tango/scrapple/text/convert/parseTo.d
r49 r55 442 442 private char replaceEscapedChar (char c) 443 443 { 444 static char[char] escChars; 445 static bool escCharsFilled; // will be initialised false 446 447 if (!escCharsFilled) { 448 // map of all supported escape sequences (cannot be static?) 449 escChars = ['"' : '"', '\'' : '\'', 450 '\\' : '\\', 'a' : '\a', 451 'b' : '\b', 'f' : '\f', 452 'n' : '\n', 'r' : '\r', 453 't' : '\t', 'v' : '\v']; 454 escCharsFilled = true; 455 } 456 457 char* r = c in escChars; 458 if (r != null) return *r; 459 else throw new ParseException ("Invalid escape sequence: \\"~c); 444 // This code was generated: 445 if (c <= 'b') { 446 if (c <= '\'') { 447 if (c == '\"') { 448 return '\"'; 449 } else if (c == '\'') { 450 return '\''; 451 } 452 } else { 453 if (c == '\\') { 454 return '\\'; 455 } else if (c == 'a') { 456 return '\a'; 457 } else if (c == 'b') { 458 return '\b'; 459 } 460 } 461 } else { 462 if (c <= 'n') { 463 if (c == 'f') { 464 return '\f'; 465 } else if (c == 'n') { 466 return '\n'; 467 } 468 } else { 469 if (c == 'r') { 470 return '\r'; 471 } else if (c == 't') { 472 return '\t'; 473 } else if (c == 'v') { 474 return '\v'; 475 } 476 } 477 } 478 479 // if we haven't returned: 480 throw new ParseException ("Invalid escape sequence: \\"~c); 460 481 } 461 482 … … 484 505 } 485 506 486 debug (UnitTest) unittest { 487 // all utility functions should be well-enough used not to need testing 507 debug (UnitTest) { 508 import tango.io.Console; 509 510 unittest { 511 Cout ("Running unittest: parseTo ...").flush; 512 513 assert (parseTo!(char[]) ("\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\"") == "\a\b\t\n\v\f\r\"\'\\"); 514 515 Cout (" complete").newline; 516 } 488 517 } 489 518 //END Utility funcs trunk/tests/dsss.conf
r47 r55 7 7 [shakematrix.d] 8 8 [unittests.d] 9 buildflags=-I.. -debug =UnitTest-unittest9 buildflags=-I.. -debug -debug=UnitTest -C-unittest trunk/tests/unittests.d
r47 r55 10 10 * It indiscriminately imports all modules in tango.scrapple so that any with unittests have their 11 11 * tests compiled in. 12 * 13 * BIG FAT WARNING: If you have scrapple installed in a global import directory, the modules will 14 * probably get imported from there, and hence will likely not reflect your latest versions! 15 * 16 * To double-check your unittests actually run, make them print a message or test with an 17 * assert(false) expression. 12 18 *************************************************************************************************/ 13 19 module unittests; 20 21 // Should import all modules. Last updated using r54 code. 22 // Some lines are commented out due to link errors. 14 23 15 24 import tango.scrapple.io.filter.RawCoutFilter; … … 18 27 import tango.scrapple.net.http.HttpMultipart; 19 28 import tango.scrapple.protocol.PlainTextProtocol; 20 /+ No unittest and link errors: 21 import tango.scrapple.sys.win32.Registry; +/ 29 //import tango.scrapple.sys.win32.Registry; link errors 22 30 import tango.scrapple.text.convert.parseFrom; 23 31 import tango.scrapple.text.convert.parseTo; … … 25 33 import tango.scrapple.thread.Message; 26 34 import tango.scrapple.thread.ThreadPool; 27 import tango.scrapple.util.uuid.Generators; 28 import tango.scrapple.util.uuid.NameBased; 29 import tango.scrapple.util.uuid.Random; 30 import tango.scrapple.util.uuid.Uuid2; 31 import tango.scrapple.util.uuid.Uuid3; 35 import tango.scrapple.util.uuid.ipc.AutoSemaphore; 36 import tango.scrapple.util.uuid.ipc.Common; 37 import tango.scrapple.util.uuid.ipc.IpcObject; 38 import tango.scrapple.util.uuid.ipc.MappableFile; 39 import tango.scrapple.util.uuid.ipc.MappedRegion; 40 import tango.scrapple.util.uuid.ipc.MemoryMappable; 41 import tango.scrapple.util.uuid.ipc.NamedSemaphore; 42 //import tango.scrapple.util.uuid.ipc.SharedMemoryObject; link errors 43 //import tango.scrapple.util.uuid.sys.Mac; pragma(lib,...) 44 import tango.scrapple.util.uuid.sys.SysString; 45 import tango.scrapple.util.uuid.NameUuidGen; 46 //import tango.scrapple.util.uuid.NativeUuidGen; pragma(lib,...) 47 import tango.scrapple.util.uuid.RandomUuidGen; 48 import tango.scrapple.util.uuid.TimeUuidGen; 49 import tango.scrapple.util.uuid.UnitTestUtil; 32 50 import tango.scrapple.util.uuid.Uuid; 33 51 import tango.scrapple.util.Arguments; … … 35 53 import tango.scrapple.util.Test; 36 54 37 import tango.io.Console; // for success message 55 import tango.io.Console; // for success message 56 57 bool unittestsRun = false; // check the test here, at least, actually gets run 38 58 39 59 // This should be an executable: 40 60 void main() { 41 61 // If execution reaches here, unittests were succesful: 42 Cout ("All scrapple unittests passed!").newline;62 if (unittestsRun) Cout ("All scrapple unittests passed! (presuming they were run)").newline; 43 63 } 64 65 debug (UnitTest) unittest { 66 Cout ("Unittests are being run...").newline; 67 unittestsRun = true; 68 assert (parseTo!(char[]) ("\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\"") == "\a\b\t\n\v\f\r\"\'\\"); 69 assert (parseFrom!(char[]) ("\a\b\t\n\v\f\r\"\'\\") == "\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\""); 70 }
