1 // RUNNABLE_PHOBOS_TEST
4 import core.stdc.stdio : printf;
5 import std.string : splitLines;
6 import std.utf : toUTF16, toUTF32;
8 /***********************************************/
13 str ~= "test"; // segfault
16 /***********************************************/
22 this(int i) { _i = i; }
23 int i() { return _i; };
30 this(int i) { super(i); }
35 printf("Testing array of Chars\n");
37 printf("Testing array of WChars\n");
39 printf("Testing array of DChars\n");
42 printf("Testing array of Bytes\n");
44 printf("Testing array of UBytes\n");
46 printf("Testing array of Shorts\n");
48 printf("Testing array of UShorts\n");
50 printf("Testing array of Ints\n");
52 printf("Testing array of UInts\n");
54 printf("Testing array of Longs\n");
56 printf("Testing array of ULongs\n");
58 printf("Testing array of Floats\n");
60 printf("Testing array of Doubles\n");
62 printf("Testing array of Reals\n");
65 printf("Testing multi-dim array of Chars\n");
68 printf("Testing array of Objects\n");
77 const int ITERS = 100;
82 for(int idx = 0; idx < ITERS; idx++) {
83 str[idx] = str[idx] ~ "TEST LINE\n";
86 if(str.length != ITERS) printf("Length Error: %d\n",str.length);
87 if(str[0].length != 10) printf("Length Error: %d\n",str[0].length);
88 if(str[ITERS-1].sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str[ITERS-1].sizeof);
89 if(str[ITERS-1][0].sizeof != (typ).sizeof) printf("Size Error: %d\n",str[ITERS-1][0].sizeof);
93 foreach(int idx, char c; s) {
95 typ[] t = s[lstart..idx];
96 if(t != "TEST LINE") {
97 printf("Error testing character array\n");
106 foreach(char[] s; str) {
110 foreach(s; splitLines(cast(string)tmp)) {
112 foreach(int idx, char c; s) {
114 if(s[lstart..idx] != "TEST LINE") {
115 printf("Error testing character array\n");
126 const int ITERS = 1000;
130 for(int idx = 0; idx < ITERS; idx++) {
131 str = str ~ "TEST LINE\n";
134 if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length);
135 if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof);
138 foreach(int idx, char c; str) {
140 if(str[lstart..idx] != "TEST LINE") {
141 printf("Error testing character array\n");
151 const int ITERS = 1000;
155 for(int idx = 0; idx < ITERS; idx++) {
156 str = str ~ toUTF16(cast(char[])"TEST LINE\n");
159 if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length);
160 if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof);
163 foreach(int idx, char c; str) {
165 if(str[lstart..idx] != toUTF16(cast(char[])"TEST LINE")) {
166 printf("Error testing character array\n");
176 const int ITERS = 1000;
180 for(int idx = 0; idx < ITERS; idx++) {
181 str = str ~ toUTF32(cast(char[])"TEST LINE\n");
184 if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length);
185 if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof);
188 foreach(int idx, char c; str) {
190 if(str[lstart..idx] != toUTF32(cast(char[])"TEST LINE")) {
191 printf("Error testing character array\n");
201 const int ITERS = 100;
205 for(typ idx = 0; idx < ITERS; idx++) {
209 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
210 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
211 for(int idx = 0; idx < ITERS; idx++) {
213 printf("a Data Error: %d\n",a[idx]);
221 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
222 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
223 for(int idx = 0; idx < ITERS; idx++) {
225 printf("b Data Error: %d\n",b[idx]);
230 c = a[0..ITERS/2] ~ b[ITERS/2..$];
233 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
234 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
235 for(int idx = 0; idx < ITERS; idx++) {
237 printf("c Data Error: %d\n",c[idx]);
245 const int ITERS = 100;
249 for(typ idx = 0; idx < ITERS; idx++) {
253 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
254 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
255 for(int idx = 0; idx < ITERS; idx++) {
257 printf("a Data Error: %d\n",a[idx]);
265 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
266 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
267 for(int idx = 0; idx < ITERS; idx++) {
269 printf("b Data Error: %d\n",b[idx]);
275 c = a[0..ITERS/2] ~ b[ITERS/2..$];
278 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
279 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
280 for(int idx = 0; idx < ITERS; idx++) {
282 printf("c Data Error: %d\n",c[idx]);
290 const int ITERS = 10000;
294 for(typ idx = 0; idx < ITERS; idx++) {
298 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
299 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
300 for(int idx = 0; idx < ITERS; idx++) {
302 printf("a Data Error: %d\n",a[idx]);
309 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
310 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
311 for(int idx = 0; idx < ITERS; idx++) {
313 printf("b Data Error: %d\n",b[idx]);
319 c = a[0..ITERS/2] ~ b[ITERS/2..$];
322 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
323 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
324 for(int idx = 0; idx < ITERS; idx++) {
326 printf("c Data Error: %d\n",c[idx]);
334 const int ITERS = 10000;
338 for(typ idx = 0; idx < ITERS; idx++) {
342 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
343 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
344 for(int idx = 0; idx < ITERS; idx++) {
346 printf("a Data Error: %d\n",a[idx]);
353 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
354 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
355 for(int idx = 0; idx < ITERS; idx++) {
357 printf("b Data Error: %d\n",b[idx]);
363 c = a[0..ITERS/2] ~ b[ITERS/2..$];
366 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
367 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
368 for(int idx = 0; idx < ITERS; idx++) {
370 printf("c Data Error: %d\n",c[idx]);
378 const int ITERS = 1000000;
382 for(int idx = 0; idx < ITERS; idx++) {
386 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
387 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
388 for(int idx = 0; idx < ITERS; idx++) {
390 printf("a Data Error: %d\n",a[idx]);
398 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
399 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
400 for(int idx = 0; idx < ITERS; idx++) {
402 printf("b Data Error: %d\n",b[idx]);
408 c = a[0..ITERS/2] ~ b[ITERS/2..$];
411 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
412 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
413 for(int idx = 0; idx < ITERS; idx++) {
415 printf("c Data Error: %d\n",c[idx]);
423 const int ITERS = 1000000;
427 for(int idx = 0; idx < ITERS; idx++) {
431 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
432 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
433 for(int idx = 0; idx < ITERS; idx++) {
435 printf("a Data Error: %d\n",a[idx]);
443 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
444 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
445 for(int idx = 0; idx < ITERS; idx++) {
447 printf("b Data Error: %d\n",b[idx]);
453 c = a[0..ITERS/2] ~ b[ITERS/2..$];
456 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
457 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
458 for(int idx = 0; idx < ITERS; idx++) {
460 printf("c Data Error: %d\n",c[idx]);
468 const int ITERS = 1000000;
472 for(int idx = 0; idx < ITERS; idx++) {
476 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
477 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
478 for(int idx = 0; idx < ITERS; idx++) {
480 printf("a Data Error: %d\n",a[idx]);
487 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
488 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
489 for(int idx = 0; idx < ITERS; idx++) {
491 printf("b Data Error: %d\n",b[idx]);
497 c = a[0..ITERS/2] ~ b[ITERS/2..$];
500 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
501 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
502 for(int idx = 0; idx < ITERS; idx++) {
504 printf("c Data Error: %d\n",c[idx]);
512 const int ITERS = 1000000;
516 for(int idx = 0; idx < ITERS; idx++) {
520 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
521 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
522 for(int idx = 0; idx < ITERS; idx++) {
524 printf("a Data Error: %d\n",a[idx]);
531 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
532 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
533 for(int idx = 0; idx < ITERS; idx++) {
535 printf("b Data Error: %d\n",b[idx]);
541 c = a[0..ITERS/2] ~ b[ITERS/2..$];
544 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
545 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
546 for(int idx = 0; idx < ITERS; idx++) {
548 printf("c Data Error: %d\n",c[idx]);
556 const int ITERS = 1000000;
560 for(int idx = 0; idx < ITERS; idx++) {
564 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
565 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
566 for(int idx = 0; idx < ITERS; idx++) {
568 printf("a Data Error: %d\n",a[idx]);
575 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
576 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
577 for(int idx = 0; idx < ITERS; idx++) {
579 printf("b Data Error: %d\n",b[idx]);
585 c = a[0..ITERS/2] ~ b[ITERS/2..$];
588 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
589 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
590 for(int idx = 0; idx < ITERS; idx++) {
592 printf("c Data Error: %d\n",c[idx]);
600 const int ITERS = 1000000;
604 for(int idx = 0; idx < ITERS; idx++) {
608 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
609 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
610 for(int idx = 0; idx < ITERS; idx++) {
612 printf("a Data Error: %d\n",a[idx]);
619 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
620 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
621 for(int idx = 0; idx < ITERS; idx++) {
623 printf("b Data Error: %d\n",b[idx]);
629 c = a[0..ITERS/2] ~ b[ITERS/2..$];
632 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
633 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
634 for(int idx = 0; idx < ITERS; idx++) {
636 printf("c Data Error: %d\n",c[idx]);
644 const int ITERS = 1000000;
648 for(int idx = 0; idx < ITERS; idx++) {
652 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
653 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
654 for(int idx = 0; idx < ITERS; idx++) {
656 printf("a Data Error: %d\n",a[idx]);
663 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
664 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
665 for(int idx = 0; idx < ITERS; idx++) {
667 printf("b Data Error: %d\n",b[idx]);
673 c = a[0..ITERS/2] ~ b[ITERS/2..$];
676 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
677 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
678 for(int idx = 0; idx < ITERS; idx++) {
680 printf("c Data Error: %d\n",c[idx]);
688 const int ITERS = 1000000;
692 for(int idx = 0; idx < ITERS; idx++) {
693 typ tc = new typ(idx);
697 if(a.length != ITERS) printf("Length Error: %d\n",a.length);
698 if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
699 for(int idx = 0; idx < ITERS; idx++) {
700 if(a[idx].i != idx) {
701 printf("a Data Error: %d\n",a[idx].i);
708 if(b.length != ITERS) printf("Length Error: %d\n",b.length);
709 if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
710 for(int idx = 0; idx < ITERS; idx++) {
711 if(b[idx].i != idx) {
712 printf("b Data Error: %d\n",b[idx].i);
718 c = a[0..ITERS/2] ~ b[ITERS/2..$];
720 if(c.length != ITERS) printf("Length Error: %d\n",c.length);
721 if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
722 for(int idx = 0; idx < ITERS; idx++) {
723 if(c[idx].i != idx) {
724 printf("c Data Error: %d\n",c[idx].i);