Debian Codegraph @

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

raw
1 /*
2 REQUIRED_ARGS: -Jrunnable/extra-files
3 EXTRA_FILES: extra-files/test15.txt
4 */
5
6 import core.math;
7 import core.vararg;
8
9 extern (C)
10 {
11 int printf(const char*, ...);
12 }
13
14 struct A { int x; }
15 struct B { int x = 22; }
16
17 void test5()
18 {
19 A* a = new A;
20 assert(a.x == 0);
21 B* b = new B;
22 assert(b.x == 22);
23 }
24
25 /************************************/
26
27 void test6()
28 {
29 assert('\x12'.sizeof == 1);
30 assert('\u1234'.sizeof == 2);
31 assert('\U00105678'.sizeof == 4);
32
33 assert('\x12' == 0x12);
34 assert('\u1234' == 0x1234);
35 assert('\U00105678' == 0x105678);
36
37 assert("abc\\def" == r"abc\def");
38 }
39
40
41 /************************************/
42
43 void test7()
44 {
45 string s = `hello"there'you`;
46 printf("s = '%.*s'\n", cast(int)s.length, s.ptr);
47 assert(s == "hello\"there'you");
48 ubyte[] b = cast(ubyte[])"\x8B\x7D\xf4\x0d";
49 for (int i = 0; i < b.length; i++)
50 printf("b[%d] = x%02x\n", i, b[i]);
51 assert(b.length == 4);
52 assert(b[0] == 0x8B);
53 assert(b[1] == 0x7D);
54 assert(b[2] == 0xF4);
55 assert(b[3] == 0x0D);
56 }
57
58
59 /************************************/
60
61
62 void foo8(out bool b)
63 {
64 b = true;
65 }
66
67
68 void test8()
69 {
70 bool b;
71 bool *pb = &b;
72
73 assert(b == false);
74 *pb = true;
75 assert(b == true);
76 *pb = false;
77 assert(b == false);
78 foo8(b);
79 assert(b == true);
80 }
81
82
83 /************************************/
84
85 struct Pair
86 {
87 int a;
88 int b;
89
90 Pair abs ()
91 {
92 return this;
93 }
94
95 Pair opBinary(string op)(Pair other) if (op == "/")
96 {
97 Pair result;
98
99 result.a = a + other.a;
100 result.b = b + other.b;
101 return result;
102 }
103 }
104
105 void test9()
106 {
107 Pair t;
108
109 t.a = 5;
110 t.b = 23;
111 t = t.abs () / t;
112 printf("a = %d, b = %d\n", t.a, t.b);
113 assert(t.a == 10);
114 assert(t.b == 46);
115 }
116
117
118 /************************************/
119
120 void test10()
121 {
122 int b = 0b_1_1__1_0_0_0_1_0_1_0_1_0_;
123
124 printf("b = %d\n", b);
125 assert(b == 3626);
126
127 b = 1_2_3_4_;
128 printf("b = %d\n", b);
129 assert(b == 1234);
130
131 b = 0x_1_2_3_4_;
132 printf("b = %d\n", b);
133 assert(b == 4660);
134
135 b = 0_;
136 printf("b = %d\n", b);
137 assert(b == 0);
138
139 double d = 0_._2_3_4_;
140 printf("d = %g\n", d);
141 assert(d == 0.234);
142
143 d = 0_._2_3_4_e+3_5_;
144 printf("d = %g\n", d);
145 assert(d == 0.234e+35);
146
147 d = 0_._2_3_4_e3_5_;
148 printf("d = %g\n", d);
149 assert(d == 0.234e+35);
150 }
151
152 /************************************/
153
154 class CA14 { }
155 class CB14 : CA14 { }
156
157 class A14 {
158 int show( CA14 a ) { printf("A14::show( CA14 )\n"); return 1; }
159 int boat( CA14 a ) { printf("A14::boat( CA14 )\n"); return 1; }
160 }
161
162 class B14 : A14 {
163 int show( CA14 a, CB14 b ) { printf("B14::show(CA14, CB14)\n"); return 2; }
164 int boat( CA14 a, CB14 b ) { printf("B14::boat(CA14, CB14)\n"); return 2; }
165 }
166
167 class C14 : B14 {
168 override int show( CA14 a ) { printf("C::show( CA14 )\n"); return 3; }
169 alias B14.show show;
170
171 alias B14.boat boat;
172 override int boat( CA14 a ) { printf("C::boat( CA14 )\n"); return 3; }
173 }
174
175 class D14 : C14 {
176 }
177
178
179 void test14()
180 {
181 D14 b = new D14();
182 int i;
183
184 i = b.show( new CA14(), new CB14() );
185 assert(i == 2);
186 i = b.show( new CA14() );
187 assert(i == 3);
188
189 i = b.boat( new CA14(), new CB14() );
190 assert(i == 2);
191 i = b.boat( new CA14() );
192 assert(i == 3);
193 }
194
195
196 /************************************/
197
198 class A15
199 {
200 void foo()
201 {
202 List1.rehash;
203 List2.rehash;
204 }
205 private:
206 int delegate(in int arg1)[char[]] List1;
207 int[char []] List2;
208 }
209
210 void test15()
211 {
212 }
213
214
215 /************************************/
216
217 void test16()
218 {
219 char[] a=new char[0];
220 uint c = 200000;
221 while (c--)
222 a ~= 'x';
223 //printf("a = '%.*s'\n", cast(int)a.length, a.ptr);
224 }
225
226
227 /************************************/
228
229 class A17 { }
230 class B17 : A17 { }
231
232 void foo17(const(A17)[] a) { }
233
234 void test17()
235 {
236 B17[] b;
237 foo17(b);
238 }
239
240
241 /************************************/
242
243 void test18()
244 {
245 uint a;
246 real b=4;
247 a=cast(uint)b;
248 }
249
250 /************************************/
251
252 abstract class Foo19
253 {
254 int bar() { return 1; }
255 }
256
257 void test19()
258 {
259 Foo19 f;
260 }
261
262 /************************************/
263
264 int foo20(string s,char d) { return 1; }
265 int foo20(string s,double d) { return 2; }
266 int foo20(string s,long d) { return 3; }
267
268 void test20()
269 {
270 int i;
271 double x;
272 i = foo20("test=",x);
273 assert(i == 2);
274 }
275
276 /************************************/
277
278 void test21()
279 {
280 // Minimalistic byLine implementation
281 static struct Lines
282 {
283 private string text, line;
284 this(string text)
285 {
286 this.text = text;
287 popFront();
288 }
289
290 bool empty() const { return text == ""; }
291
292 string front() const
293 {
294 assert(!empty);
295 return line;
296 }
297
298 void popFront()
299 {
300 assert(!empty);
301 foreach (const idx; 0 .. text.length)
302 {
303 if (text[idx] == '\n')
304 {
305 line = text[0..idx];
306 text = text[idx + 1..$];
307 return;
308 }
309 }
310
311 line = text;
312 text = null;
313 }
314 }
315
316 static immutable string file = import(`test15.txt`);
317
318 int[string] esdom;
319
320 foreach(it; Lines(file))
321 esdom[it.idup] = 0;
322
323 esdom.rehash;
324 }
325
326 /************************************/
327
328 int foo22(char* p) { return 1; }
329 int foo22(char[] s) { return 2; }
330
331 void test22()
332 {
333 int i;
334
335 i = foo22(cast(char*)"abc");
336 assert(i == 1);
337 i = foo22(cast(char[])"abc");
338 assert(i == 2);
339 }
340
341
342 /************************************/
343
344 void test23()
345 {
346 uint v;
347 int b;
348 long l;
349 real e;
350
351 e = cos(e);
352 e = fabs(e);
353 e = rint(e);
354 l = rndtol(e);
355 e = sin(e);
356 e = sqrt(e);
357 }
358
359
360 /************************************/
361
362 abstract class dtortest24
363 {
364 this() {}
365 ~this() {}
366 }
367
368 void test24()
369 {
370 }
371
372
373 /************************************/
374
375 abstract class bar25 {
376
377 this() {}
378
379 void foo() {}
380
381 }
382
383 class subbar25 : bar25 {
384
385 this() {}
386
387 }
388
389 void test25()
390 {
391 new subbar25();
392 }
393
394
395 /************************************/
396
397 void test26()
398 {
399 string[] instructions =[ "a", "b", "c" ];
400
401 foreach(ref string instr; instructions)
402 {
403 instr = instr[];
404 }
405
406 foreach(string instr; instructions)
407 {
408 printf("%.*s\n", cast(int)instr.length, instr.ptr);
409 }
410 }
411
412
413 /************************************/
414
415 void foo27(ClassInfo ci) { }
416
417 class A27
418 {
419 }
420
421 class B27 : A27
422 {
423 static this()
424 {
425 foo27(B27.classinfo);
426 foo27(A27.classinfo);
427 }
428 }
429
430 void test27()
431 {
432 }
433
434
435 /************************************/
436
437 void foo28(ClassInfo ci)
438 {
439 printf("%.*s\n", cast(int)ci.name.length, ci.name.ptr);
440
441 static int i;
442 switch (i++)
443 {
444 case 0:
445 case 2: assert(ci.name == "test15.A28");
446 break;
447 case 1: assert(ci.name == "test15.B28");
448 break;
449 default: assert(0);
450 }
451 }
452
453 class A28
454 {
455 static this() {
456 foo28(A28.classinfo );
457 }
458 }
459
460 class B28 : A28
461 {
462 static this() {
463 foo28(B28.classinfo );
464 (new B28()).bodge_it();
465 }
466 void bodge_it() {
467 foo28(A28.classinfo );
468 }
469 }
470
471 void test28()
472 {
473 A28 a,b;
474 a = new A28();
475 b = new B28();
476 }
477
478
479 /************************************/
480
481 void test29()
482 {
483 static void delegate() dg;
484
485 dg = null;
486 }
487
488
489 /************************************/
490
491 string foo30(int i)
492 {
493 return i ? "three" : "two";
494 }
495
496 string bar30(int i)
497 {
498 return i ? "one" : "five";
499 }
500
501 void test30()
502 {
503 string s;
504
505 s = foo30(0);
506 assert(s == "two");
507 s = foo30(1);
508 assert(s == "three");
509
510 s = bar30(0);
511 assert(s == "five");
512 s = bar30(1);
513 assert(s == "one");
514 }
515
516
517 /************************************/
518 // https://www.digitalmars.com/d/archives/18204.html
519 // DMD0.050 also failed with alias.
520
521 alias int recls_bool_t;
522
523 class Entry31
524 {
525
526 recls_bool_t IsReadOnly()
527 {
528 return cast(recls_bool_t)0;
529 }
530 }
531
532
533 void test31()
534 {
535 Entry31 entry = new Entry31();
536
537 if (entry.IsReadOnly)
538 {
539 }
540 }
541
542
543 /************************************/
544
545 class A32
546 {
547 alias int delegate() mfunc;
548
549 this( mfunc initv )
550 {
551 }
552 }
553
554 class foo32
555 {
556 static void getMemberBar()
557 {
558 //foo32 f = new foo32(); new A32( &(f.bar) );
559 new A32( &((new foo32()).bar) );
560 }
561
562 int bar()
563 {
564 return 0;
565 }
566 }
567
568
569 void test32()
570 {
571 foo32.getMemberBar();
572 }
573
574
575 /************************************/
576
577 void[] foo33(int[] b)
578 {
579 return b;
580 }
581
582 void test33()
583 {
584 int[6] c;
585 void[] v;
586
587 v = foo33(c);
588 assert(v.length == 6 * int.sizeof);
589 }
590
591 /************************************/
592
593 void test34()
594 {
595 version (D_Bits)
596 {
597 bool[8] a8;
598 assert(a8.sizeof == 4);
599 bool[16] a16;
600 assert(a16.sizeof == 4);
601 bool[32] a32;
602 assert(a32.sizeof == 4);
603 bool[256] a256;
604 assert(a256.sizeof == 32);
605 }
606 }
607
608 /************************************/
609
610 void test35()
611 {
612 typeof(1 + 2) i;
613
614 assert(i.sizeof == int.sizeof);
615 assert(typeof('c').sizeof == char.sizeof);
616 assert(typeof(1).sizeof == int.sizeof);
617 assert(typeof(1.0F).sizeof == float.sizeof);
618 assert(typeof(1.0).sizeof == double.sizeof);
619 assert(typeof(1.0L).sizeof == real.sizeof);
620
621 //assert(((typeof(1.0L))i).sizeof == real.sizeof);
622 assert((cast(typeof(1.0L))i).sizeof == real.sizeof);
623 }
624
625 /************************************/
626
627 void test36x()
628 {
629 version (Win32)
630 {
631 // stdin.getch();
632 }
633 }
634
635 void test36()
636 {
637 }
638
639
640 /************************************/
641
642 struct T37
643 {
644 char x;
645
646 T37 create()
647 { T37 t;
648 t.x = 3;
649 return t;
650 }
651
652 bool test1()
653 {
654 return create() == this;
655 }
656
657 bool test2()
658 {
659 return this == create();
660 }
661 }
662
663
664 void test37()
665 {
666 T37 t;
667
668 assert(!t.test1());
669 t.x = 3;
670 assert(t.test1());
671
672 t.x = 0;
673 assert(!t.test2());
674 t.x = 3;
675 assert(t.test2());
676 }
677
678 /************************************/
679
680 void test38()
681 {
682 uint f(uint n) { return n % 10; }
683
684 printf("%u\n", uint.max);
685 printf("%u\n", f(uint.max));
686 assert(f(uint.max) == 5);
687 }
688
689 /************************************/
690
691 void test39()
692 {
693 short s=HIWORD (0x0FFFDDDD);
694 short t=LOWORD (0xFFFFCCCC);
695 short v=HIWORD_(0x0FFFEEEE);
696 short x=HIWORD_(0xFFFFAAAA);
697
698 printf("%x %x %x %x\n",s,t,v,x);
699 assert(s == 0xFFF);
700 assert(t == 0xFFFFCCCC);
701 assert(v == 0xFFF);
702 assert(x == 0xFFFFFFFF);
703 }
704
705 short HIWORD(uint i)
706 {
707 return cast(short)(( i >> 16) & 0xFFFF);
708 }
709
710 short LOWORD(uint i)
711 {
712
713 return cast(short)i;
714 }
715 extern (C) short HIWORD_(uint i)
716 {
717 return cast(short)(( i >> 16) & 0xFFFF);
718 }
719
720
721 /************************************/
722
723 class caller40 {
724 caller40 opCall (out int i) {
725 i = 10;
726 return this;
727 }
728 }
729
730 void test40()
731 {
732 caller40 c = new caller40;
733 int x,y;
734 c(x)(y);
735 assert(x == 10);
736 assert(y == 10);
737 }
738
739 /************************************/
740
741 class Foo41 { void print() {printf("Foo41\n");} }
742
743 class Bar41 : Foo41
744 {
745 void test()
746 {
747 void printFoo41()
748 {
749 super.print(); // DMD crashes here
750 }
751 printFoo41();
752 }
753 }
754
755 void test41()
756 {
757 Bar41 b = new Bar41();
758 b.test();
759 }
760
761 /************************************/
762
763 interface Interface
764 {
765 void foo42();
766 }
767
768 void bar42(Interface i)
769 {
770 i.foo42();
771 }
772
773 class Abstract : Interface
774 {
775 abstract void foo42();
776 }
777
778 class Concrete : Abstract
779 {
780 override void foo42() { printf("Concrete.foo42(this = %p)\n", this); }
781 }
782
783 class Sub : Concrete
784 {
785 }
786
787 void test42()
788 {
789 Sub s = new Sub();
790 s.foo42();
791 bar42(s);
792 }
793
794 /************************************/
795
796 class A43
797 {
798 int foo() { return 6; }
799 }
800
801 int bar43(A43 a)
802 {
803 return a.foo;
804 }
805
806 void test43()
807 {
808 A43 a = new A43();
809 assert(bar43(a) == 6);
810 }
811
812
813 /************************************/
814
815 class C44
816 {
817 const char[][] arrArr=["foo"];
818 }
819
820 void test44()
821 {
822 C44 c= new C44();
823 printf("%.*s\n", cast(int)c.arrArr[0].length, c.arrArr[0].ptr);
824 assert(c.arrArr[0] == "foo");
825 }
826
827
828 /************************************/
829
830 void test45()
831 {
832 void* p;
833 void[] data;
834
835 data = p[0 .. 5];
836 }
837
838 /************************************/
839
840 union A46
841 {
842 char c;
843 struct { short s; }
844 struct { long l; }
845 int a;
846 struct { float f; }
847 }
848
849 void test46()
850 {
851 A46 a;
852 printf("%td\n", cast(byte*)&a.c - cast(byte*)&a);
853 printf("%td\n", cast(byte*)&a.s - cast(byte*)&a);
854 printf("%td\n", cast(byte*)&a.l - cast(byte*)&a);
855 printf("%td\n", cast(byte*)&a.a - cast(byte*)&a);
856 printf("%td\n", cast(byte*)&a.f - cast(byte*)&a);
857
858 assert(cast(byte*)&a.c == cast(byte*)&a);
859 assert(cast(byte*)&a.s == cast(byte*)&a);
860 assert(cast(byte*)&a.l == cast(byte*)&a);
861 assert(cast(byte*)&a.a == cast(byte*)&a);
862 assert(cast(byte*)&a.f == cast(byte*)&a);
863 }
864
865
866 /************************************/
867
868 class Bug47
869 {
870
871 void foo()
872 {
873 }
874
875 static void foo(int i)
876 {
877 }
878
879 static void bar()
880 {
881 foo(1);
882 }
883 }
884
885 void test47()
886 {
887 }
888
889
890 /************************************/
891
892 int[2] x48 = 3;
893 float y48 = 0.0f;
894
895 void test48()
896 {
897 printf("%d, %d\n", x48[0], x48[1]);
898 assert(x48[0] == 3 && x48[1] == 3);
899
900 y48 = -100;
901
902 printf("%d, %d\n", x48[0], x48[1]);
903 assert(x48[0] == 3 && x48[1] == 3);
904 }
905
906 /************************************/
907
908 struct Baz49 { int x,y,z,t; }
909
910 void foo49(out Baz49 x, out int y)
911 {
912 }
913
914 void test49()
915 {
916 int y = 3;
917 Baz49 b;
918 assert(b.x == 0);
919 assert(b.y == 0);
920 assert(b.z == 0);
921 assert(b.t == 0);
922 b.x = 1;
923 b.y = 6;
924 b.z = 10;
925 b.t = 11;
926 foo49(b, y);
927 assert(b.x == 0);
928 assert(b.y == 0);
929 assert(b.z == 0);
930 assert(b.t == 0);
931 assert(y == 0);
932 }
933
934 /************************************/
935
936 void foo50(int[] f, ...)
937 {
938 foreach(size_t i, TypeInfo ti; _arguments) { }
939 }
940
941 void bar50(out int[] f, ...)
942 {
943 foreach(size_t i, TypeInfo ti; _arguments) { }
944 }
945
946 void test50()
947 {
948 int[] a;
949
950 foo50(a, 1, 2, 3);
951 bar50(a, 1, 2, 3);
952 }
953
954
955 /************************************/
956
957 deprecated int tri(int x)
958 {
959 return x*(x+1)/2;
960 }
961
962 deprecated int pent(int x)
963 {
964 return x*x + tri(x) - x;
965 }
966
967 deprecated class Qwert
968 {
969 int yuiop;
970
971 this(int y) { yuiop = y; }
972
973 int twiceYuiop()
974 {
975 return 2 * yuiop;
976 }
977
978 invariant()
979 {
980 assert (yuiop < 100);
981 }
982 }
983
984 void test51()
985 {
986 }
987
988 /************************************/
989
990 void foo52(double d) {}
991 deprecated void foo52(int i) {}
992
993 deprecated void bar52(int i) {}
994 void bar52(double d) {}
995
996 void test52()
997 {
998 // foo52(1);
999 foo52(1.0);
1000 bar52(1.0);
1001 }
1002
1003 /************************************/
1004
1005 class X53
1006 {
1007 void foo(double d) {}
1008 deprecated void foo(int i) {}
1009
1010 deprecated void bar(int i) {}
1011 void bar(double d) {}
1012 }
1013
1014 void test53()
1015 {
1016 X53 x = new X53();
1017 //x.foo(1);
1018 //x.bar(1);
1019 x.foo(1.0);
1020 x.bar(1.0);
1021 }
1022
1023 /************************************/
1024
1025 interface B54 : A54
1026 {
1027 A54 getParent();
1028 }
1029
1030 interface A54
1031 {
1032 void parse(char[] systemId);
1033 }
1034
1035 void test54()
1036 {
1037 }
1038
1039
1040 /************************************/
1041
1042 class Writer
1043 {
1044 int put (bool x){ return 1; }
1045 int put (int x){ return 2; }
1046 }
1047
1048 class MyWriter : Writer
1049 {
1050 alias Writer.put put;
1051
1052 override int put (bool x){ return 3; }
1053 }
1054
1055 void test55()
1056 {
1057 MyWriter m = new MyWriter();
1058
1059 assert(m.put(false) == 3);
1060 assert(m.put(1) == 2);
1061 }
1062
1063
1064 /************************************/
1065
1066 class Foo56
1067 {
1068 alias int baseType;
1069 }
1070
1071 void test56()
1072 {
1073 Foo56 f = new Foo56;
1074
1075 f.baseType s = 10;
1076 }
1077
1078
1079 /************************************/
1080
1081 void det(float[][] mat)
1082 {
1083 float[][] newmat;
1084
1085 size_t i = newmat[0 .. (mat.length - 1)].length;
1086 }
1087
1088 void test57()
1089 {
1090 }
1091
1092
1093 /************************************/
1094
1095 int foo58 (int a, int t) { return 2; }
1096
1097 class A58
1098 {
1099 int foo58 ( ) { return 3; }
1100 alias .foo58 foo58;
1101 }
1102
1103 void test58()
1104 { int y, x;
1105
1106 with ( new A58 )
1107 { y = foo58(0,1);
1108 x = foo58();
1109 }
1110 assert(y == 2);
1111 assert(x == 3);
1112 }
1113
1114
1115 /************************************/
1116
1117 void test59()
1118 {
1119 struct data
1120 {
1121 int b1=-1;
1122 int b2=2;
1123 }
1124
1125 data d;
1126 assert(d.b1 == -1);
1127 assert(d.b2 == 2);
1128 }
1129
1130
1131 /************************************/
1132
1133 class Foo60
1134 {
1135 int x;
1136 this() { x = 3; }
1137 ~this() { }
1138 }
1139
1140
1141 void test60()
1142 {
1143 Foo60 f = new Foo60();
1144
1145 assert(f.x == 3);
1146 }
1147
1148
1149 /************************************/
1150
1151 class StdString
1152 {
1153 alias nearest = core.math.rint;
1154 }
1155
1156 void test61()
1157 {
1158 StdString g = new StdString();
1159 assert(g.nearest(123.1) == 123);
1160 }
1161
1162
1163 /************************************/
1164
1165 void test62()
1166 { char[4] a;
1167
1168 assert(a[0] == 0xFF);
1169 assert(a[1] == 0xFF);
1170 assert(a[2] == 0xFF);
1171 assert(a[3] == 0xFF);
1172 }
1173
1174
1175 /************************************/
1176
1177 void test63()
1178 {
1179 bool b;
1180 real r;
1181 int i;
1182
1183 i=cast(double) b ? 1 : 4;
1184 r=cast(real) b ? 1.0 : 2.0;
1185 }
1186
1187
1188 /************************************/
1189
1190 struct MyStruct64
1191 {
1192 int test(short s){printf("dynamic short\n"); return 1; }
1193 int test(int i){printf("dynamic int\n"); return 2; }
1194 static int staticTest(short s){printf("static short\n"); return 3; }
1195 static int staticTest(int i){printf("static int\n"); return 4; }
1196 }
1197
1198 void test64()
1199 {
1200 MyStruct64 S;
1201 int j;
1202
1203 short s = 1;
1204 int i = 1;
1205
1206 j = S.test(s);
1207 assert(j == 1);
1208 j = S.test(i);
1209 assert(j == 2);
1210
1211 j = S.staticTest(s);
1212 assert(j == 3);
1213 j = S.staticTest(i);
1214 assert(j == 4);
1215
1216 }
1217
1218 /************************************/
1219
1220 void test65()
1221 {
1222 int[8] qwert;
1223 int[] yuiop = qwert[2..5] = 4;
1224
1225 assert(yuiop.length == 3);
1226 assert(yuiop[0] == 4);
1227 assert(yuiop[1] == 4);
1228 assert(yuiop[2] == 4);
1229 yuiop[1] = 2;
1230 assert(qwert[0] == 0);
1231 assert(qwert[1] == 0);
1232 assert(qwert[2] == 4);
1233 assert(qwert[3] == 2);
1234 assert(qwert[4] == 4);
1235 assert(qwert[5] == 0);
1236 assert(qwert[6] == 0);
1237 assert(qwert[7] == 0);
1238 }
1239
1240
1241 /************************************/
1242
1243 void foo66(ref bool b)
1244 {
1245 b = true;
1246 }
1247
1248 void test66()
1249 {
1250 bool[3] a;
1251
1252 foo66(a[0]);
1253 assert(a[0] == true);
1254 assert(a[1] == false);
1255 assert(a[2] == false);
1256 }
1257
1258
1259 /************************************/
1260
1261 class FuBar
1262 {
1263 void foo ()
1264 {
1265 printf ("should never get here\n");
1266 assert(0);
1267 }
1268
1269 const(void)[] get ()
1270 {
1271 return "weqweqweqweqwee";
1272 }
1273
1274 void test (void* dst)
1275 {
1276 uint count = 7;
1277 while (count)
1278 {
1279 // get as much as there is available in the buffer
1280 uint available = 10;
1281
1282 // cap bytes read
1283 if (available > count)
1284 available = count;
1285
1286 // copy them over
1287 dst[0..available] = get ()[0..available];
1288
1289 // bump counters
1290 dst += available;
1291 if ((count -= available) > 0)
1292 foo ();
1293 }
1294 }
1295 }
1296
1297
1298 void test67()
1299 {
1300 FuBar b = new FuBar();
1301 char[10] dst;
1302 b.test(&dst[0]);
1303 }
1304
1305
1306 /************************************/
1307
1308 struct Foo68 { int a,b,c,d; }
1309
1310 void bar68(out Foo68 f)
1311 {
1312 f.a = 28;
1313 }
1314
1315 void test68()
1316 {
1317 Foo68 f;
1318 bar68(f);
1319 assert(f.a == 28);
1320 }
1321
1322 /************************************/
1323
1324 class ConduitStyle
1325 {
1326
1327 // static ConduitStyle Read;
1328 // static ConduitStyle ReadWrite;
1329
1330 static ConduitStyle Read, ReadWrite;
1331 }
1332
1333 void test69()
1334 {
1335 }
1336
1337
1338 /************************************/
1339
1340 void test70()
1341 {
1342 printf("-5/3 prints: %d\n", -5/3);
1343 printf("-5/2 prints: %d\n", -5/2);
1344 printf("-7/3 prints: %d\n", -7/3);
1345 printf("-7/4 prints: %d\n", -7/4);
1346 printf("-7/7 prints: %d\n", -7/7);
1347 printf("-8/7 prints: %d\n", -8/7);
1348 printf("-12/6 prints: %d\n", -12/6);
1349 printf("12/6 prints: %d\n", 12/6);
1350 printf("-9/7 prints: %d\n", -9/7);
1351 printf("-11/8 prints: %d\n", -11/8);
1352 printf("-7/9 prints: %d\n", -7/9);
1353
1354 assert(-5/3 == -1);
1355 assert(-5/2 == -2);
1356 assert(-7/3 == -2);
1357 assert(-7/4 == -1);
1358 assert(-7/7 == -1);
1359 assert(-8/7 == -1);
1360 assert(-12/6 == -2);
1361 assert(12/6 == 2);
1362 assert(-9/7 == -1);
1363 assert(-11/8 == -1);
1364 assert(-7/9 == 0);
1365 }
1366
1367 /************************************/
1368
1369 void insertText(string str)
1370 {
1371 assert(str == "a ");
1372 }
1373
1374 char getCharAt()
1375 {
1376 return 'a';
1377 }
1378
1379 void test71()
1380 {
1381 insertText(getCharAt() ~ " ");
1382 }
1383
1384 /************************************/
1385
1386 public class Foo72
1387 {
1388 public this() { }
1389 }
1390
1391 void test72()
1392 {
1393 Foo72[] foos;
1394
1395 foos = new Foo72() ~ foos[];
1396 assert(foos.length == 1);
1397 }
1398
1399 /************************************/
1400 // https://issues.dlang.org/show_bug.cgi?id=19758
1401
1402 void test19758()
1403 {
1404 byte[1] a = [1];
1405 int b = 0;
1406
1407 // If delete this 4 lines, the result is correct.
1408 if (a[b] == 0)
1409 {
1410 a[b] = 0;
1411 if (1 << b) { }
1412 }
1413
1414 if ((a[b] & 0xFF) == 0)
1415 {
1416 assert((a[b] & 0xFF) == 0);
1417 }
1418 }
1419
1420 /************************************/
1421 // https://issues.dlang.org/show_bug.cgi?id=19968
1422
1423 void test19968()
1424 {
1425 int[2] array = [16, 678];
1426 union U { int i; bool b; }
1427 U u;
1428 u.i = 0xBFBFBFBF;
1429 assert(array[u.b] == 678);
1430 }
1431
1432 /************************************/
1433
1434 int main()
1435 {
1436 test5();
1437 test6();
1438 test7();
1439 test8();
1440 test9();
1441 test10();
1442 test14();
1443 test15();
1444 test16();
1445 test17();
1446 test18();
1447 test19();
1448 test20();
1449 test21();
1450 test22();
1451 test23();
1452 test24();
1453 test25();
1454 test26();
1455 test27();
1456 test28();
1457 test29();
1458 test30();
1459 test31();
1460 test32();
1461 test33();
1462 test34();
1463 test35();
1464 test36();
1465 test37();
1466 test38();
1467 test39();
1468 test40();
1469 test41();
1470 test42();
1471 test43();
1472 test44();
1473 test45();
1474 test46();
1475 test47();
1476 test48();
1477 test49();
1478 test50();
1479 test51();
1480 test52();
1481 test53();
1482 test54();
1483 test55();
1484 test56();
1485 test57();
1486 test58();
1487 test59();
1488 test60();
1489 test61();
1490 test62();
1491 test63();
1492 test64();
1493 test65();
1494 test66();
1495 test67();
1496 test68();
1497 test69();
1498 test70();
1499 test71();
1500 test72();
1501 test19758();
1502 test19968();
1503
1504 printf("Success\n");
1505 return 0;
1506 }