comparison mde/file/serialize.d @ 88:01f4f5f1acc9

Changes to init and to allow compiling with gdc. Tweaked init code to allow using circular iterators (disabled until my patch makes it into tango). Changes to allow compiling with gdc. Building is successful and unittests complete, but in my experience a SIGSEGV occurs within SDL.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 29 Sep 2008 12:09:44 +0100
parents 79d816b3e2d2
children 97e6dce08037
comparison
equal deleted inserted replaced
87:2212285f714c 88:01f4f5f1acc9
344 344
345 345
346 // Structs 346 // Structs
347 struct Foo { int a = 9; char b = '\v'; float c; } 347 struct Foo { int a = 9; char b = '\v'; float c; }
348 struct Bar { Foo a,b; } 348 struct Bar { Foo a,b; }
349 static Foo foo1 = { a:150, b:'8', c:17.2f}, foo2; 349 static Foo foo1 = { a:150, b:'8'}, foo2;
350 Bar bar; 350 Bar bar;
351 bar.a = foo1; 351 bar.a = foo1;
352 bar.b = foo2; 352 bar.b = foo2;
353 assert (serialize(bar) == "{0:{0:150,1:'8',2:1.72000007e+01},1:{0:9,1:'\\v',2:nan}}"); 353 assert (serialize(bar) == "{0:{0:150,1:'8',2:nan},1:{0:9,1:'\\v',2:nan}}");
354 354
355 355
356 // Basic Types 356 // Basic Types
357 // Character types 357 // Character types
358 assert (serialize!(char) ('\'') == "\'\\\'\'"); 358 assert (serialize!(char) ('\'') == "\'\\\'\'");
384 // NOTE: this is something that should really work. 384 // NOTE: this is something that should really work.
385 char[] r = serialize!(ulong) (0x8FFF_FFFF_FFFF_FFFFLu); 385 char[] r = serialize!(ulong) (0x8FFF_FFFF_FFFF_FFFFLu);
386 })); 386 }));
387 387
388 // Floats 388 // Floats
389 // These numbers are not particularly meaningful: 389 // We can't do a proper float-test because we can't rely on numbers being printed to the same
390 assert (serialize!(float) (0.0f) == "0.00000000"); 390 // number of figures on all platforms. Do nan tests to check type is supported.
391 assert (serialize!(double) (-1e25) == "-1.00000000000000000e+25"); 391 assert (serialize!(float) (float.init) == "nan");
392 assert (serialize!(real) (cast(real) 4.918e300) == "4.91800000000000000000e+300"); 392 assert (serialize!(double) (double.init) == "nan");
393 assert (serialize!(real) (real.init) == "nan");
393 394
394 // Escape sequences (test conversion functions) 395 // Escape sequences (test conversion functions)
395 assert (serialize ("\a\b\t\n\v\f\r\"\'\\") == `"\a\b\t\n\v\f\r\"\'\\"`); 396 assert (serialize ("\a\b\t\n\v\f\r\"\'\\") == `"\a\b\t\n\v\f\r\"\'\\"`);
396 397
397 logger.info ("Unittest complete."); 398 logger.info ("Unittest complete.");