Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test4.d

raw
1 // PERMUTE_ARGS:
2 // REQUIRED_ARGS:
3
4 import core.exception;
5 import core.stdc.math;
6 import core.vararg;
7
8 extern(C)
9 {
10 int atoi(const char*);
11 int memcmp(const void*, const void*, size_t);
12 int printf(const char*, ...);
13 }
14
15 int cmp(const(char)[] s1, const(char)[] s2)
16 {
17 assert(s1.length == s2.length);
18
19 return memcmp(s1.ptr, s2.ptr, s1.length);
20 }
21
22 /* ================================ */
23
24 void test1()
25 {
26 int i;
27
28 int[6] foo = 1;
29 for (i = 0; i < foo.length; i++)
30 assert(foo[i] == 1);
31
32 int[10] bar;
33 for (i = 0; i < bar.length; i++)
34 assert(bar[i] == 0);
35
36 foo[3] = 4;
37 int[6] abc = foo;
38 for (i = 0; i < abc.length; i++)
39 assert(abc[i] == foo[i]);
40
41 abc[2] = 27;
42 foo[] = abc;
43 for (i = 0; i < abc.length; i++)
44 assert(abc[i] == foo[i]);
45 }
46
47 /* ================================ */
48
49 void test2()
50 {
51 byte[5] foo1;
52 ubyte[6] foo2;
53 short[7] foo3;
54 ushort[8] foo4;
55 int[9] foo5;
56 uint[10] foo6;
57 long[11] foo7;
58 ulong[12] foo8;
59 float[13] foo9;
60 double[14] foo10;
61 real[15] foo11;
62
63 int i;
64
65 printf("test2()\n");
66 for (i = 0; i < foo1.length; i++)
67 assert(foo1[i] == 0);
68 for (i = 0; i < foo2.length; i++)
69 { printf("foo2[%d] = %d\n", i, foo2[i]);
70 assert(foo2[i] == 0);
71 }
72 for (i = 0; i < foo3.length; i++)
73 assert(foo3[i] == 0);
74 for (i = 0; i < foo4.length; i++)
75 assert(foo4[i] == 0);
76 for (i = 0; i < foo5.length; i++)
77 {
78 printf("foo5[%d] = %d\n", i, foo5[i]);
79 assert(foo5[i] == 0);
80 }
81 for (i = 0; i < foo6.length; i++)
82 assert(foo6[i] == 0);
83 for (i = 0; i < foo7.length; i++)
84 assert(foo7[i] == 0);
85 for (i = 0; i < foo8.length; i++)
86 assert(foo8[i] == 0);
87 for (i = 0; i < foo9.length; i++)
88 assert(isnan(foo9[i]));
89 for (i = 0; i < foo10.length; i++)
90 assert(isnan(foo10[i]));
91 for (i = 0; i < foo11.length; i++)
92 assert(isnan(foo11[i]));
93 }
94
95 /* ================================ */
96
97 void test3()
98 {
99 byte[5] foo1 = 20;
100 ubyte[6] foo2 = 21;
101 short[7] foo3 = 22;
102 ushort[8] foo4 = 23;
103 int[9] foo5 = 24;
104 uint[10] foo6 = 25;
105 long[11] foo7 = 26;
106 ulong[12] foo8 = 27;
107 float[13] foo9 = 28;
108 double[14] foo10 = 29;
109 real[15] foo11 = 30;
110
111 int i;
112
113 for (i = 0; i < foo1.length; i++)
114 assert(foo1[i] == 20);
115 for (i = 0; i < foo2.length; i++)
116 assert(foo2[i] == 21);
117 for (i = 0; i < foo3.length; i++)
118 assert(foo3[i] == 22);
119 for (i = 0; i < foo4.length; i++)
120 assert(foo4[i] == 23);
121 for (i = 0; i < foo5.length; i++)
122 assert(foo5[i] == 24);
123 for (i = 0; i < foo6.length; i++)
124 assert(foo6[i] == 25);
125 for (i = 0; i < foo7.length; i++)
126 assert(foo7[i] == 26);
127 for (i = 0; i < foo8.length; i++)
128 assert(foo8[i] == 27);
129 for (i = 0; i < foo9.length; i++)
130 assert(foo9[i] == 28);
131 for (i = 0; i < foo10.length; i++)
132 assert(foo10[i] == 29);
133 for (i = 0; i < foo11.length; i++)
134 assert(foo11[i] == 30);
135 }
136
137 /* ================================ */
138
139 struct a4
140 {
141 string b = "string";
142 int c;
143 }
144
145 void test4()
146 {
147 a4 a;
148 int i;
149
150 assert(a.b.length == 6);
151 i = cmp(a.b, "string");
152 assert(i == 0);
153
154 a4[3] c;
155 int j;
156 for (j = 0; j < 3; j++)
157 {
158 assert(c[j].b.length == 6);
159 i = cmp(c[j].b, "string");
160 assert(i == 0);
161 }
162 }
163
164
165 /* ================================ */
166
167 float f5;
168 const char[4] x5 = "abcd";
169
170 struct a5
171 {
172 string b = "string";
173 int c;
174 }
175
176 a5[5] foo5;
177
178 void test5()
179 {
180 printf("test5()\n");
181 assert(isnan(f5));
182
183 assert(cmp(x5, "abcd") == 0);
184
185 int i;
186 for (i = 0; i < 5; i++)
187 {
188 assert(foo5[i].c == 0);
189 assert(cmp(foo5[i].b, "string") == 0);
190 }
191 }
192
193 /* ================================ */
194
195 struct TRECT6
196 {
197 int foo1 = 2;
198
199 union {
200 struct
201 {
202 int Left = 3, Top = 4, Right = 5, Bottom = 6;
203 }
204 struct
205 {
206 long TopLeft, BottomRight;
207 }
208 }
209
210 int foo2 = 7;
211 }
212
213 void test6()
214 {
215 TRECT6 t;
216
217 assert(t.foo1 == 2);
218 assert(t.Left == 3);
219 assert(t.Top == 4);
220 assert(t.Right == 5);
221 assert(t.Bottom == 6);
222 assert(t.foo2 == 7);
223 assert(&t.foo1 < &t.Left);
224 assert(&t.Bottom < &t.foo2);
225
226 assert(TRECT6.foo1.offsetof == 0);
227 static if (long.alignof == 8)
228 {
229 assert(TRECT6.Left.offsetof == 8);
230 assert(TRECT6.Top.offsetof == 12);
231 assert(TRECT6.Right.offsetof == 16);
232 assert(TRECT6.Bottom.offsetof == 20);
233 assert(TRECT6.TopLeft.offsetof == 8);
234 assert(TRECT6.BottomRight.offsetof == 16);
235 assert(TRECT6.foo2.offsetof == 24);
236 }
237 else
238 {
239 assert(TRECT6.Left.offsetof == 4);
240 assert(TRECT6.Top.offsetof == 8);
241 assert(TRECT6.Right.offsetof == 12);
242 assert(TRECT6.Bottom.offsetof == 16);
243 assert(TRECT6.TopLeft.offsetof == 4);
244 assert(TRECT6.BottomRight.offsetof == 12);
245 assert(TRECT6.foo2.offsetof == 20);
246 }
247 }
248
249 /* ================================ */
250
251 struct TestVectors
252 {
253 string pattern;
254 string input;
255 string result;
256 string format;
257 string replace;
258 };
259
260 TestVectors[] tva =
261 [
262 { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" },
263 { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" },
264 ];
265
266 TestVectors[2] tvs =
267 [
268 { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" },
269 { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" },
270 ];
271
272 TestVectors* tvp =
273 [
274 { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" },
275 { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" },
276 ];
277
278 void test7()
279 {
280 int i;
281
282 //printf("start\n");
283 //printf("%d\n", tva[0].pattern.length);
284 //printf("%.*s\n", tva[0].pattern.length, tva[0].pattern.ptr);
285
286 i = cmp(tva[0].pattern, "(a)\\1");
287 assert(i == 0);
288 i = cmp(tva[1].replace, "abc");
289 assert(i == 0);
290
291 i = cmp(tvs[0].pattern, "(a)\\1");
292 assert(i == 0);
293 i = cmp(tvs[1].replace, "abc");
294 assert(i == 0);
295
296 i = cmp(tvp[0].pattern, "(a)\\1");
297 assert(i == 0);
298 i = cmp(tvp[1].replace, "abc");
299 assert(i == 0);
300
301 //printf("finish\n");
302 }
303
304 /* ================================ */
305
306 const uint WSABASEERR = 10000;
307 const uint WSAENOTCONN = (WSABASEERR+57);
308
309 void test8()
310 {
311 switch (10057)
312 {
313 case WSAENOTCONN:
314 break;
315 default:
316 assert(0);
317 }
318 }
319
320 /* ================================ */
321
322
323 alias T9* PPixel;
324 align(1) struct TAG
325 {
326 int foo;
327 }
328 alias TAG T9;
329 alias TAG Pixel;
330
331
332 void func9(PPixel x)
333 {
334 }
335
336 void test9()
337 {
338 Pixel p;
339 func9(&p);
340 }
341
342 /* ================================ */
343
344
345 string[] colors10 = [ "red", "green", "blue" ];
346
347 void test10()
348 {
349 printf("test10()\n");
350
351 int i;
352
353 i = cmp(colors10[0], "red");
354 assert(i == 0);
355 }
356
357 /* ================================ */
358
359 const uint MAX_PATH1 = 260;
360 enum { MAX_PATH2 = 261 }
361
362 struct WIN32_FIND_DATA {
363 char[MAX_PATH1] cFileName1;
364 char[MAX_PATH2] cFileName2;
365 }
366
367 void test11()
368 {
369 }
370
371 /* ================================ */
372
373
374 interface IPersistent
375 {
376 int store(Object);
377 int retrieve(Object);
378 }
379
380 class Persistent: IPersistent
381 {
382 int store(Object n) { return 1; }
383 int retrieve(Object n) { return 2; }
384 }
385
386 void func12(IPersistent p)
387 {
388 Object o = new Object();
389 assert(p.store(o) == 1);
390 assert(p.retrieve(o) == 2);
391 }
392
393 void test12()
394 {
395 Persistent p = new Persistent();
396 Object o = new Object();
397 assert(p.store(o) == 1);
398 assert(p.retrieve(o) == 2);
399
400 func12(p);
401 }
402
403 /* ================================ */
404
405 class X13 { }
406
407 class A13
408 {
409 X13 B(X13 x, out int i)
410 {
411 i = 666;
412 return new X13;
413 }
414
415 X13 B(X13 x)
416 {
417 int j;
418 return B(x, j);
419 }
420 }
421
422 void test13()
423 {
424 A13 a;
425 X13 x;
426 int i;
427
428 a = new A13();
429 x = a.B(x, i);
430 assert(i == 666);
431 }
432
433 /* ================================ */
434
435 void foo14() { }
436
437 int testx14(int x)
438 {
439 try
440 {
441 return 3;
442 }
443 finally
444 {
445 foo14();
446 }
447 }
448
449 class bar
450 {
451 int y;
452 synchronized int sync(int x)
453 {
454 printf("in sync(%d) = %d\n", x, y + 3);
455 return y + 3;
456 }
457 }
458
459 void test14()
460 {
461 auto b = new shared(bar)();
462 int i;
463 i = b.sync(4);
464 printf("i = %d\n", i);
465 assert(i == 3);
466
467 assert(testx14(7) == 3);
468 }
469
470 /* ================================ */
471
472 /+
473 int foo15(int i)
474 {
475 switch (i)
476 {
477 case 7:
478 case 8:
479 return i;
480 }
481 return 0;
482 }
483
484 void test15()
485 {
486 int i = 0;
487 try
488 {
489 foo15(3);
490 }
491 catch (SwitchError sw)
492 {
493 //printf("caught switch error\n");
494 i = 1;
495 }
496 assert(i == 1);
497 }
498 +/
499
500 /* ================================ */
501
502
503 struct GUID { // size is 16
504 align(1):
505 uint Data1;
506 ushort Data2;
507 ushort Data3;
508 ubyte[8] Data4;
509 }
510
511
512 GUID CLSID_Hello = { 0x30421140, 0, 0, [0xC0,0,0,0,0,0,0,0x46] };
513 GUID IID_IHello = { 0x00421140, 0, 0, [0xC0,0,0,0,0,0,0,0x46] };
514
515 int testa()
516 {
517 return CLSID_Hello == IID_IHello;
518 }
519
520 int testb()
521 {
522 return CLSID_Hello != IID_IHello;
523 }
524
525 int testc()
526 {
527 return CLSID_Hello == IID_IHello ? 5 : 3;
528 }
529
530 int testd()
531 {
532 return CLSID_Hello != IID_IHello ? 7 : 9;
533 }
534
535 void test16()
536 {
537 assert(testa() == 0);
538 assert(testb() == 1);
539 assert(testc() == 3);
540 assert(testd() == 7);
541 }
542
543
544 /* ================================ */
545
546 private const uint[256] crc_table = [
547 0x00000000u, 0x77073096u, 0xee0e612cu, 0x990951bau, 0x076dc419u,
548 0x2d02ef8du
549 ];
550
551 public const(uint)[] get_crc_table()
552 {
553 return crc_table;
554 }
555
556 void test18()
557 {
558 const(uint)[] c;
559
560 c = get_crc_table();
561 assert(c[3] == 0x990951bau);
562 }
563
564 /* ================================ */
565
566 int[0xffff] foo19;
567
568 void test19()
569 {
570 int i;
571
572 for (i = 0; i < 0xffff; i++)
573 assert(foo19[i] == 0);
574 }
575
576 /* ================================ */
577
578
579 extern (Windows) int cfw(int x, int y)
580 {
581 return x * 10 + y;
582 }
583
584 extern (C) int cfc(int x, int y)
585 {
586 return x * 10 + y;
587 }
588
589 int cfd(int x, int y)
590 {
591 return x * 10 + y;
592 }
593
594
595 extern (Windows) int function (int, int) fpw;
596 extern (C) int function (int, int) fpc;
597 int function (int, int) fpd;
598
599 void test20()
600 {
601 printf("test20()\n");
602 int i;
603
604 fpw = &cfw;
605 fpc = &cfc;
606 fpd = &cfd;
607
608 //printf("test w\n");
609 i = (*fpw)(1, 2);
610 assert(i == 12);
611
612 //printf("test c\n");
613 i = (*fpc)(3, 4);
614 assert(i == 34);
615
616 //printf("test d\n");
617 i = (*fpd)(7, 8);
618 assert(i == 78);
619 }
620
621
622 /* ================================ */
623
624 int def23(int x, int y)
625 {
626 return x * y;
627 }
628
629 struct Foo23
630 {
631 int a = 7;
632 int b = 8;
633 int c = 9;
634
635 int abc()
636 {
637 def23(3, 4);
638 a *= b;
639 bar();
640 return a;
641 }
642
643 int bar()
644 {
645 a *= 2;
646 return a;
647 }
648
649 invariant()
650 {
651 assert(c == 9);
652 }
653 }
654
655 void test23()
656 {
657 Foo23 f;
658 int i;
659
660 assert(f.a == 7 && f.b == 8);
661 i = f.abc();
662 assert(i == 112);
663 }
664
665 /* ================================ */
666
667 struct Foo24
668 {
669 int x, y;
670 int[] z;
671 }
672
673 void test24()
674 {
675 assert(Foo24.z.offsetof == 8);
676 }
677
678 /* ================================ */
679
680 void test27()
681 {
682 static real[1] n = [ -1 ];
683 //printf("%Le\n", n[0]);
684 assert(n[0] == -1.0);
685 }
686
687 /* ================================ */
688
689 int x29;
690
691 class Foo29
692 {
693 ~this()
694 {
695 x29 = bar();
696 }
697
698 int bar()
699 {
700 return 3;
701 }
702 }
703
704
705 void test29()
706 {
707 printf("test29()\n");
708
709 Foo29 f = new Foo29();
710
711 destroy(f);
712 assert(x29 == 3);
713 }
714
715 /* ================================ */
716
717
718 struct GC30
719 {
720 static ClassInfo gcLock;
721
722 invariant()
723 {
724 }
725
726 void *malloc()
727 { void *p;
728
729 synchronized (gcLock)
730 {
731 p = test();
732 if (!p)
733 return null;
734 }
735 return p;
736 }
737
738 void *test() { return null; }
739 }
740
741 void test30()
742 {
743 printf("test30()\n");
744 GC30 gc;
745
746 GC30.gcLock = Object.classinfo;
747 assert(gc.malloc() == null);
748 }
749
750
751 /* ================================ */
752
753 void test31()
754 {
755 char[14] foo;
756 char[] bar;
757 int i = 3;
758
759 while (i--)
760 bar = foo;
761 }
762
763 /* ================================ */
764
765
766
767 real foo32()
768 {
769 return 4 % 1.0;
770 }
771
772 void test32()
773 {
774 assert(foo32() == 0);
775 }
776
777 /* ================================ */
778
779 void test33()
780 {
781 char[8] foo;
782
783 foo[] = "12345678";
784 assert(foo[7] == '8');
785 }
786
787
788 /* ================================ */
789
790 void foo34(int[] a)
791 {
792 //printf("a.length = %d\n", a.length);
793 assert(a.length == 5);
794 assert(a[0] == 11);
795 assert(a[1] == 22);
796 assert(a[2] == 33);
797 assert(a[3] == 44);
798 assert(a[4] == 55);
799 }
800
801 void test34()
802 {
803 printf("test34()\n");
804
805 static int[5] x = [11,22,33,44,55];
806 int[] y;
807 int* z;
808
809 foo34(x);
810
811 y = x;
812 foo34(y);
813
814 z = x.ptr;
815 foo34(z[0..5]);
816 }
817
818 /* ================================ */
819
820 class X35
821 {
822 final synchronized void foo()
823 {
824 for(;;)
825 {
826 break;
827 }
828 }
829 }
830
831 void test35()
832 {
833 auto x = new shared(X35);
834
835 x.foo();
836 }
837
838
839 /* ================================ */
840
841 void test36()
842 {
843 synchronized
844 {
845 }
846 }
847
848 void test36b() @nogc nothrow
849 {
850 synchronized
851 {
852 }
853 }
854
855 /* ================================ */
856 int test37()
857 {
858 string one = "1";
859 debug printf("pre\n");
860 int N = atoi(one.ptr);
861 assert(N == 1);
862 return 0;
863 }
864
865
866 /* ================================ */
867
868 void test39()
869 {
870 char[] array;
871 array.length=4;
872 char letter = 'a';
873 array[0..4]=letter;
874 assert(array[0]=='a');
875 assert(array[1]=='a');
876 assert(array[2]=='a');
877 assert(array[3]=='a');
878 }
879
880 /* ================================ */
881
882 int dummyJob;
883
884 int dummy()
885 {
886 return ++dummyJob;
887 }
888
889 void bar40(){
890 return cast(void)dummy();
891 }
892
893 int foo40()
894 {
895 bar40();
896 return dummyJob-1;
897 }
898
899 void test40()
900 {
901 assert(foo40() == 0);
902 }
903
904 /* ================================ */
905
906 int status;
907
908 void check()
909 {
910 assert(status==1);
911 void main(int dummy){
912 assert(status==3);
913 status+=5;
914 }
915 status+=2;
916 assert(status==3);
917 main(2);
918 assert(status==8);
919 status+=7;
920 }
921
922 void test41()
923 {
924 status++;
925 assert(status==1);
926 check();
927 assert(status==15);
928 }
929
930 /* ================================ */
931
932 void test42()
933 {
934 real[10] array;
935 real[] copy = array.dup;
936 }
937
938 /* ================================ */
939
940 void test43()
941 {
942 string s;
943
944 s = __FILE__; printf("file = '%.*s'\n", cast(int)s.length, s.ptr);
945 printf("line = %d\n", __LINE__);
946 s = __DATE__; printf("date = '%.*s'\n", cast(int)s.length, s.ptr);
947 s = __TIME__; printf("time = '%.*s'\n", cast(int)s.length, s.ptr);
948 s = __TIMESTAMP__; printf("timestamp = '%.*s'\n", cast(int)s.length, s.ptr);
949 }
950
951 /* ================================ */
952
953 void test44()
954 {
955 int[] a;
956 int i;
957
958 a.length = 6;
959 a = a[0 .. $ - 1];
960 assert(a.length == 5);
961 }
962
963 /* ================================ */
964
965 alias int MyInt;
966
967 void test45()
968 {
969 MyInt test(string c="x"){
970 return 2;
971 }
972 assert(test("abc")==2);
973 }
974
975 /* ================================ */
976
977 int status46;
978
979 class Check46
980 {
981 void sum(byte[] b){
982 status46++;
983 }
984
985 void add(byte b){
986 assert(0);
987 }
988
989 alias sum write;
990 alias add write;
991
992 void test(){
993 byte[] buffer;
994 write(buffer);
995 }
996 }
997
998
999 void test46()
1000 {
1001 Check46 c = new Check46();
1002 status46=0;
1003 assert(status46==0);
1004 c.test();
1005 assert(status46==1);
1006 }
1007
1008 /* ================================ */
1009
1010 int status47;
1011
1012 int foo47(int arg)
1013 {
1014 loop:
1015 while(1)
1016 {
1017 try
1018 {
1019 try
1020 {
1021 if (arg == 1)
1022 {
1023 break loop;
1024 }
1025 }
1026 finally
1027 {
1028 assert(status47==0);
1029 status47+=2;
1030 }
1031
1032 try
1033 {
1034 assert(0);
1035 }
1036 finally
1037 {
1038 assert(0);
1039 }
1040 }
1041 finally
1042 {
1043 assert(status47==2);
1044 status47+=3;
1045 }
1046 assert(0);
1047 return 0;
1048 }
1049 return -1;
1050 }
1051
1052 void test47()
1053 {
1054 assert(status47 == 0);
1055 assert(foo47(1) == -1);
1056 assert(status47 == 5);
1057 }
1058
1059 /* ================================ */
1060
1061 int status48;
1062
1063 int foo48(int arg)
1064 {
1065
1066 loop:
1067 while(1){
1068 try{
1069 try{
1070 if(arg == 1)
1071 {
1072 break loop;
1073 }
1074 }finally{
1075 assert(status48==0);
1076 status48+=2;
1077 }
1078 }finally{
1079 assert(status48==2);
1080 status48+=3;
1081 }
1082 return 0;
1083 }
1084 return -1;
1085 }
1086
1087 void test48()
1088 {
1089 assert(status48 == 0);
1090 assert(foo48(1) == -1);
1091 assert(status48 == 5);
1092 }
1093
1094 /* ================================ */
1095
1096 int getch49()
1097 {
1098 return 0;
1099 }
1100
1101 void writefln49(...)
1102 {
1103 }
1104
1105 class Cout{
1106 Cout set(int x){
1107 return this;
1108 }
1109 Cout opBinary(string op)(int x) if (op == "<<")
1110 {
1111 return set(x);
1112 }
1113 }
1114
1115 void test49()
1116 {
1117 Cout cout = new Cout;
1118 cout << 5 << 4;
1119 writefln49,getch49;
1120 }
1121
1122 /* ================================ */
1123
1124 struct S50{
1125 int i;
1126 }
1127
1128 class C50{
1129 static S50 prop(){
1130 S50 s;
1131 return s;
1132 }
1133
1134 static void prop(S50 s){
1135 }
1136 }
1137
1138 void test50()
1139 {
1140 C50 c = new C50();
1141 c.prop = true ? C50.prop : C50.prop;
1142 assert(c.prop.i == 0);
1143 c.prop.i = 7;
1144 assert(c.prop.i != 7);
1145 }
1146
1147 /* ================================ */
1148
1149 void func1()
1150 {
1151 static class foo {
1152 public int a;
1153 }
1154 }
1155
1156 void test51()
1157 {
1158 static class foo {
1159 public int b;
1160 }
1161
1162 foo bar = new foo();
1163 bar.b = 255;
1164 }
1165
1166 /* ================================ */
1167
1168 struct S52
1169 {
1170 int i;
1171 }
1172
1173 const int a52 = 3;
1174 const S52 b52 = { a52 };
1175 const S52 c52 = b52;
1176
1177 void test52()
1178 {
1179 assert(c52.i == 3);
1180 }
1181
1182 /* ================================ */
1183
1184 const int c53 = b53 + 1;
1185 const int a53 = 1;
1186 const int b53 = a53 + 1;
1187
1188 void test53()
1189 {
1190 assert(a53==1);
1191 assert(b53==2);
1192 assert(c53==3);
1193 }
1194
1195 /* ================================ */
1196 void test54()
1197 {
1198 int status=0;
1199
1200 try
1201 {
1202 try
1203 {
1204 status++;
1205 assert(status==1);
1206 throw new Exception("first");
1207 }
1208 finally
1209 {
1210 printf("finally\n");
1211 status++;
1212 assert(status==2);
1213 status++;
1214 throw new Exception("second");
1215 }
1216 }
1217 catch(Exception e)
1218 {
1219 printf("catch %.*s\n", cast(int)e.msg.length, e.msg.ptr);
1220 assert(e.msg == "first");
1221 assert(e.next.msg == "second");
1222 }
1223 printf("success54\n");
1224 }
1225
1226 /* ================================ */
1227
1228 void foo55()
1229 {
1230 try
1231 {
1232 Exception x = new Exception("second");
1233 printf("inner throw %p\n", x);
1234 throw x;
1235 }
1236 catch (Exception e)
1237 {
1238 printf("inner catch %p\n", e);
1239 printf("e.msg == %.*s\n", cast(int)e.msg.length, e.msg.ptr);
1240 assert(e.msg == "second");
1241 //assert(e.msg == "first");
1242 //assert(e.next.msg == "second");
1243 }
1244 }
1245
1246 void test55()
1247 {
1248 int status=0;
1249 try{
1250 try{
1251 status++;
1252 assert(status==1);
1253 Exception x = new Exception("first");
1254 printf("outer throw %p\n", x);
1255 throw x;
1256 }finally{
1257 printf("finally\n");
1258 status++;
1259 assert(status==2);
1260 status++;
1261 foo55();
1262 printf("finally2\n");
1263 }
1264 }catch(Exception e){
1265 printf("outer catch %p\n", e);
1266 assert(e.msg == "first");
1267 assert(status==3);
1268 }
1269 printf("success55\n");
1270 }
1271
1272 /* ================================ */
1273
1274 void test56()
1275 {
1276 assert('\&sup2;'==178);
1277 assert('\&sup3;'==179);
1278 assert('\&sup1;'==185);
1279 assert('\&frac14;'==188);
1280 assert('\&frac12;'==189);
1281 assert('\&frac34;'==190);
1282 assert('\&there4;'==8756);
1283 }
1284
1285 /* ================================ */
1286
1287 void test57()
1288 {
1289 version (D_Bits)
1290 {
1291 void displayb(char[] name, bit[] x)
1292 {
1293 writef("%-5s: ", name);
1294 foreach(bit b; x)
1295 writef("%d",b);
1296 writefln("");
1297 }
1298
1299 bit[] a;
1300 bit[] b;
1301
1302 a.length = 7;
1303 a[0] = 0;
1304 a[1] = 1;
1305 a[2] = 1;
1306 a[3] = 0;
1307 a[4] = 0;
1308 a[5] = 1;
1309 a[6] = 0;
1310
1311 displayb("a", a);
1312
1313 b ~= a;
1314 displayb("b1", b);
1315
1316 b ~= a;
1317 displayb("b2", b);
1318
1319 for (int i = 0; i < a.length; i++)
1320 {
1321 assert(b[i] == a[i]);
1322 assert(b[i+7] == a[i]);
1323 }
1324
1325 b.length = 0;
1326 b ~= a;
1327 displayb("b3", b);
1328
1329 b.length = b.length + 7;
1330 for(int i = 0; i < a.length; i++)
1331 b[i+7] = a[i];
1332 displayb("b4", b);
1333
1334 for (int i = 0; i < a.length; i++)
1335 {
1336 assert(b[i] == a[i]);
1337 assert(b[i+7] == a[i]);
1338 }
1339 }
1340 }
1341
1342 /* ================================ */
1343
1344 interface Foo58
1345 {
1346 }
1347
1348 interface Bar58 : Foo58
1349 {
1350 }
1351
1352 class Baz58 : Bar58
1353 {
1354 }
1355
1356 Object test58()
1357 {
1358 Bar58 b = new Baz58;
1359 return cast(Object)b;
1360 }
1361
1362 /* ================================ */
1363
1364 float x59;
1365
1366 void test59()
1367 {
1368 return cast(void)(x59 = -x59);
1369 }
1370
1371
1372 /* ================================ */
1373 // https://issues.dlang.org/show_bug.cgi?id=10664
1374
1375 Exception collectExceptionE(int delegate () expression, ref int result)
1376 {
1377 try
1378 {
1379 result = expression();
1380 }
1381 catch (Exception e)
1382 {
1383 return e;
1384 }
1385 return null;
1386 }
1387
1388 RangeError collectExceptionR(int delegate () expression, ref int result)
1389 {
1390 try
1391 {
1392 result = expression();
1393 }
1394 catch (RangeError e)
1395 {
1396 return e;
1397 }
1398 return null;
1399 }
1400
1401 void test10664()
1402 {
1403 int b;
1404 int foo() { throw new Exception("blah"); }
1405 assert(collectExceptionE(&foo, b));
1406
1407 int[] a = new int[3];
1408 int goo() { return a[4]; }
1409 collectExceptionR(&goo, b);
1410 }
1411
1412 /* ================================ */
1413
1414
1415 int main()
1416 {
1417 test1();
1418 test2();
1419 test3();
1420 test4();
1421 test5();
1422 test6();
1423 test7();
1424 test8();
1425 test9();
1426 test10();
1427 test11();
1428 test12();
1429 test13();
1430 test14();
1431 //test15();
1432 test16();
1433 test18();
1434 test19();
1435 test20();
1436 test23();
1437 test24();
1438 // test26();
1439 test27();
1440 // test28();
1441 test29();
1442 test30();
1443 test31();
1444 test32();
1445 test33();
1446 test34();
1447 test35();
1448 test36();
1449 test37();
1450 test39();
1451 test40();
1452 test41();
1453 test42();
1454 test43();
1455 test44();
1456 test45();
1457 test46();
1458 test47();
1459 test48();
1460 test49();
1461 test50();
1462 test51();
1463 test52();
1464 test53();
1465 test54();
1466 test55();
1467 test56();
1468 test57();
1469 test58();
1470 test59();
1471 test10664();
1472
1473 printf("Success\n");
1474 return 0;
1475 }