10 /************************************************/
17 TypeInfo ti_foo
= typeid(Foo
);
18 TypeInfo ti_bar
= typeid(Bar
);
20 auto hfoo
= ti_foo
.toHash();
21 auto hbar
= ti_bar
.toHash();
22 writefln("typeid(Foo).toHash: ", hfoo
);
23 writefln("typeid(Bar).toHash: ", hbar
);
26 auto e
= (ti_foo
== ti_bar
);
27 writefln("opEquals: ", e ?
"equal" : "not equal");
30 auto c
= (ti_foo
.opCmp(ti_bar
) == 0);
31 writefln("opCmp: ", c ?
"equal" : "not equal");
36 /************************************************/
40 assert( [2,3]!=[2,4] );
41 assert( [3,2]!=[4,2] );
42 assert( !([2,3]==[2,4]) );
43 assert( ([2,3]==[2,3]) );
46 /************************************************/
60 assert(v
.langID
== 1);
68 foreach(ref v
; table
) {
70 assert(v
.langID
== 1);
82 assert(v
.langID
== 1);
86 assert(v
.langID
== 1);
89 /************************************************/
98 static assert(is(typeof(X
) == ExOuter
));
107 /************************************************/
115 void rec5(int i
, MyStruct5 s
)
129 assert(status5
==1030);
132 /************************************************/
153 /************************************************/
155 template parseUinteger(string s
)
157 static if (s
.length
== 0)
158 { const char[] value
= "";
159 const char[] rest
= "";
161 else static if (s
[0] >= '0' && s
[0] <= '9')
162 { const char[] value
= s
[0] ~ parseUinteger
!(s
[1..$]).value
;
163 const char[] rest
= parseUinteger
!(s
[1..$]).rest
;
166 { const char[] value
= "";
167 const char[] rest
= s
;
171 template parseInteger(string s
)
173 static if (s
.length
== 0)
174 { const char[] value
= "";
175 const char[] rest
= "";
177 else static if (s
[0] >= '0' && s
[0] <= '9')
178 { const char[] value
= s
[0] ~ parseUinteger
!(s
[1..$]).value
;
179 const char[] rest
= parseUinteger
!(s
[1..$]).rest
;
181 else static if (s
.length
>= 2 &&
182 s
[0] == '-' && s
[1] >= '0' && s
[1] <= '9')
183 { const char[] value
= s
[0..2] ~ parseUinteger
!(s
[2..$]).value
;
184 const char[] rest
= parseUinteger
!(s
[2..$]).rest
;
187 { const char[] value
= "";
188 const char[] rest
= s
;
194 writeln(parseUinteger
!("1234abc").value
);
195 writeln(parseUinteger
!("1234abc").rest
);
196 writeln(parseInteger
!("-1234abc").value
);
197 writeln(parseInteger
!("-1234abc").rest
);
199 assert(parseUinteger
!("1234abc").value
== "1234");
200 assert(parseUinteger
!("1234abc").rest
== "abc");
201 assert(parseInteger
!("-1234abc").value
== "-1234");
202 assert(parseInteger
!("-1234abc").rest
== "abc");
205 /************************************************/
218 assert((1+2).stringof == "1 + 2");
219 assert(Foo8.stringof == "Foo8");
220 assert(test.Foo8.stringof == "test.Foo8");
221 assert(int.stringof == "int");
222 assert((int*[5][]).stringof == "int*[5][]");
223 assert(Enum.RED.stringof == "Enum.RED");
224 assert(test.myint.stringof == "test.myint");
225 assert(myalias.stringof == "myalias");
226 assert((5).stringof == "5");
227 assert(typeof(5).stringof == "typeof(5)");
231 /************************************************/
244 alias void function() T;
254 /************************************************/
256 bool isalnum(dchar c
) { return c
>='0' && c
>= '9'; }
258 char[] toHtmlFilename(char[] fname
)
260 foreach (ref c
; fname
)
262 if (!isalnum(c
) && c
!= '.' && c
!= '-')
272 /************************************************/
280 writefln("Test is ", test.toString
);
281 assert(test.toString
== "test34.B34");
282 A34 test_2
=cast(A34
)(new B34
);
283 writefln("Test 2 is ", test_2
.toString
);
284 assert(test_2
.toString
== "test34.B34");
287 /************************************************/
289 template Foo12(T
: T
[U
], U
)
297 assert(is(typeof(x
) == int));
300 /************************************************/
307 printf("C13.this()\n");
315 C13 c
= cast(C13
)Object
.factory("test34.C13");
317 Object o
= Object
.factory("test35.C13");
321 /************************************************/
324 int func(int a
) { return 1; }
328 class Foo15
: Base15
{
329 alias Base15
.func func
;
333 class Bar15
: Foo15
{
334 alias Foo15
.func func
;
335 int func(string a
) { return 2; }
340 Bar15 b
= new Bar15();
341 assert(b
.func("hello") == 2);
342 assert(b
.func(5) == 1);
345 /************************************************/
347 struct Basic16(T
, U
) {}
349 struct Iterator16(T
: Basic16
!(T
, U
), U
)
353 writeln(typeid(T
), typeid(U
));
354 assert(is(T
== int));
355 assert(is(U
== float));
361 Iterator16
!(Basic16
!(int, float)).Foo();
364 /************************************************/
371 int insert17(T
) (S17
!(T
) lst
, S17
!(T
).iterator i
)
379 S17
!(int).iterator i
;
380 auto x
= insert17(a
, i
);
384 /************************************************/
389 for(int i
=0; i
<10; i
++)
393 printf("%Lg %Lg %Lg\n", t
, r
, 2*t
);
394 assert(2*t
== (i
+1)*2);
398 /************************************************/
403 void[] ca
= cast(void[])[c
];
404 char[] x
= cast(char[])ca
;
408 /************************************************/
418 template XX(uint a
, uint c
)
420 static uint XX(){ return (a
*256+c
);}
424 switch (cast(uint)type20
.a
)
426 case XX
!(cast(uint)type20
.a
,cast(uint)type20
.b
)():
437 /************************************************/
449 assert(is(typeof(j
) == int));
452 /************************************************/
457 assert(is(typeof(i
) == int));
458 assert(is(typeof(j
) == int));
461 /************************************************/
463 static m23
= 5, n23
= 6;
468 assert(is(typeof(i
) == int));
469 assert(is(typeof(j
) == int));
470 assert(is(typeof(m23
) == int));
471 assert(is(typeof(n23
) == int));
474 /************************************************/
478 const int[1] bar24
= [foo24
* 2];
479 const int zap24
= (1 << bar24
[a24
]);
483 assert(zap24
== 256);
486 /************************************************/
489 struct CircularQueue25(T
) { }
491 void front25(T
)(ref List25
!(T
) list
) { }
492 void front25(T
)(ref CircularQueue25
!(T
) queue
) { }
500 /************************************************/
507 static Foo26 foo26
= {"something"};
511 assert(foo26
.x
== "something");
514 /************************************************/
516 template Mang(alias F
)
519 alias void function (G
) H
;
520 const string mangledname
= H
.mangleof
;
523 template moo(alias A
)
526 const string a
= Mang
!(A
).mangledname
;
528 static assert(Mang
!(A
).mangledname
== a
); // FAILS !!!
535 string b
= moo
!(q
).a
;
538 /************************************************/
542 static void fromRgb(uint rgb
)
546 static void fromRgb(ubyte alpha
, uint rgb
)
554 Color
.fromRgb(cast(uint)0);
557 /************************************************/
561 const char[] t
="abcd";
562 const ubyte[] t2
=cast(ubyte[])t
;
563 const char[] t3
=['a','b','c','d'];
564 const ubyte[] t4
=cast(ubyte[])t3
;
565 assert(t4
[1] == 'b');
568 /************************************************/
572 const char[] test = "" ~ 'a' ~ 'b' ~ 'c';
573 char[] test2
= (cast(char[])null)~'a'~'b'~'c';
574 const char[] test3
= (cast(char[])null)~'a'~'b'~'c';
575 char[] test4
= (cast(char[])[])~'a'~'b'~'c';
576 const char[] test5
= (cast(char[])[])~'a'~'b'~'c';
577 const char[] test6
= null;
578 const char[] test7
= test6
~'a'~'b'~'c';
581 /************************************************/
585 synchronized invariant() { int x
; }
592 /************************************************/
596 return cast(ulong) (cast(ulong) 1176576512 + cast(float) -2);
601 assert(foo32()==1176576510);
604 /************************************************/
608 uint[258] cumCount
; // 256 + end + total
614 for (int i
=0; i
<cumCount
.length
; i
++)
621 void encode(uint symbol
) {
622 uint total
= cumCount
[$ - 1];
623 // "Error: Access Violation" in following line
624 upper
= lower
+ cast(uint)((cumCount
[symbol
+1] * range
) / total
) - 1;
625 lower
= lower
+ cast(uint)((cumCount
[symbol
] * range
) / total
);
631 RangeCoder rc
= new RangeCoder();
635 /************************************************/
641 public static Vector34
opCall(float x
= 0, float y
= 0, float z
= 0)
652 public string
toString()
654 return std
.string
.format("<%f, %f, %f>", x
, y
, z
);
664 v
= Vector34(1, 0, 0);
675 writef("Returned: %s\n", s
);
676 assert(std
.string
.format("%s", s
) == "<1.000000, 0.000000, 0.000000>");
679 public Vector34
foobar()
681 writef("Returning %s\n", v
);
684 Vector34 b
= Vector34();
691 Foo34 f
= new Foo34();
696 /************************************************/
703 extern (Windows
) int function(int i
, int j
, int k
) xxx
;
709 xxx
= cast(typeof(xxx
))(a
+ b
);
716 else version(X86_64
) asm
735 /************************************************/
739 int* p
= void, c
= void;
742 /************************************************/
750 writefln("Hello world!");
755 /************************************************/
758 int left
, top
, right
, bottom
;
763 print38(sizeTest(false));
764 print38(sizeTest(true));
765 print38(defaultRect
);
768 static Rect
sizeTest(bool empty
) {
775 /+Rect result = defaultRect;
780 void print38(Rect r
) {
781 writefln("(%d, %d)-(%d, %d)", r
.left
, r
.top
, r
.right
, r
.bottom
);
783 assert(r
.right
== 0);
785 assert(r
.bottom
== 0);
792 /************************************************/
796 double[][] foo
= [[1.0],[2.0]];
798 writeln(foo
[0]); // --> [1] , ok
799 writeln(foo
[1]); // --> [2] , ok
801 writeln(foo
); // --> [[1],4.63919e-306] ack!
802 writefln("%s", foo
); // --> ditto
803 auto f
= std
.string
.format("%s", foo
);
804 assert(f
== "[[1], [2]]");
810 writeln(bar
); // Error: Access violation
811 auto r
= std
.string
.format("%s", bar
);
812 assert(r
== "[[1], [2]]");
815 /************************************************/
822 auto r
= std
.string
.format("%s", x
);
823 assert(r
== "['b':123]");
827 /************************************************/
833 /************************************************/
840 Enum42
[] enums
= new Enum42
[1];
841 assert(enums
[0] == Enum42
.A
);
845 /************************************************/
856 auto b
= B43
!(A43
)(a
);
859 /************************************************/
863 int[ const char[] ] a
= ["abc":3, "def":4];
866 /************************************************/
870 //char[3][] a = ["abc", "def"];
872 //char[][2] b = ["abc", "def"];
876 /************************************************/
882 if (true) return false;
898 /************************************************/
900 static size_t
myfind(string haystack
, char needle
) {
901 foreach (i
, c
; haystack
) {
902 if (c
== needle
) return i
;
907 static size_t
skip_digits(string s
) {
909 if (c
< '0' || c
> '9') return i
;
914 static uint matoi(string s
) {
917 if (c
< '0' || c
> '9') break;
918 result
= result
* 10 + (c
- '0');
923 enum { leading
, skip
, width
, modifier
, format
, fmt_length
, extra
};
925 static string
GetFormat(string s
) {
928 // find the percent sign
929 while (pos
< s
.length
&& s
[pos
] != '%') {
932 const leading_chars
= pos
;
933 result
~= cast(char) pos
;
934 if (pos
< s
.length
) ++pos
; // go right after the '%'
936 if (pos
< s
.length
&& s
[pos
] == '*') {
943 result
~= cast(char) matoi(s
);
944 pos
+= skip_digits(s
[pos
.. $]);
946 if (pos
< s
.length
&& myfind("hjlLqtz", s
[pos
]) != size_t
.max
) {
947 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@
954 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@
963 static string
test = GetFormat(" %*Lf");
964 assert(test[modifier
] == 'L', "`" ~ test[modifier
] ~ "'");
967 /************************************************/
972 int foo48()(B48
!()) { return 1; }
973 int foo48()(C48 c
) { return 2; }
977 auto i
= foo48(new B48
!());
984 /************************************************/
994 writefln("Before test 1: ", a
.v
);
995 if (a
== a
.init
) { writeln(a
.v
,"(a==a.init)"); assert(0); }
996 else { writeln(a
.v
,"(a!=a.init)"); assert(a
.v
== 10); }
1000 writefln("Before test 1: ", a
.v
);
1001 if (a
== a
.init
) { writeln(a
.v
,"(a==a.init)"); assert(a
.v
== 10); }
1002 else { writeln(a
.v
,"(a!=a.init)"); assert(0); }
1006 writefln("Before test 2: ", a
.v
);
1007 if (a
== a
.init
) { writeln(a
.v
,"(a==a.init)"); assert(0); }
1008 else { writeln(a
.v
,"(a!=a.init)"); assert(a
.v
== 100); }
1011 writefln("Before test 3: ", a
.v
);
1012 if (a
== a
.init
) { writeln(a
.v
,"(a==a.init)"); assert(0); }
1013 else { writeln(a
.v
,"(a!=a.init)"); assert(a
.v
== 1000); }
1016 assert(a
.init
.v
== 0);
1018 assert(a
.init
.v
== 10);
1021 /************************************************/
1026 void div() { assert(i
== 3); }
1034 /************************************************/
1046 /************************************************/
1055 void func53(TestStruct
[2] testarg
)
1057 writeln(testarg
[0].dummy0
);
1058 writeln(testarg
[0].dummy1
);
1059 writeln(testarg
[0].dummy2
);
1061 writeln(testarg
[1].dummy0
);
1062 writeln(testarg
[1].dummy1
);
1063 writeln(testarg
[1].dummy2
);
1065 assert(testarg
[0].dummy0
== 0);
1066 assert(testarg
[0].dummy1
== 1);
1067 assert(testarg
[0].dummy2
== 2);
1069 assert(testarg
[1].dummy0
== 0);
1070 assert(testarg
[1].dummy1
== 1);
1071 assert(testarg
[1].dummy2
== 2);
1082 /************************************************/
1088 // Internal error: ..\ztc\cg87.c 3233
1089 // a += (1? b: 1+1i)*1i;
1092 // Internal error: ..\ztc\cod2.c 1680
1093 // a += (b?1:b-1i)*1i;
1098 /************************************************/
1103 template foo55(S
, T
: S
) { } // doesn't work
1105 alias foo55
!(B55
, D55
) bar55
;
1111 /************************************************/
1113 template t56() { alias Object t56
; }
1114 pragma(msg
, t56
!().stringof
);
1120 /************************************************/
1124 alias long[char[]] AA
;
1126 static if (is(AA T
: T
[U
], U
: const char[]))
1131 assert(is(T
== long));
1132 assert(is(U
== const(char)[]));
1135 static if (is(AA A
: A
[B
], B
: int))
1140 static if (is(int[10] W
: W
[V
], int V
))
1143 assert(is(W
== int));
1148 static if (is(int[10] X
: X
[Y
], int Y
: 5))
1154 /************************************************/
1181 /************************************************/
1185 extern (C
++) int bar60(int i
, int j
, int k
)
1187 printf("this = %p\n", this);
1188 printf("i = %d\n", i
);
1189 printf("j = %d\n", j
);
1190 printf("k = %d\n", k
);
1200 int foo60(int i
, int j
, int k
)
1202 printf("i = %d\n", i
);
1203 printf("j = %d\n", j
);
1204 printf("k = %d\n", k
);
1219 /***************************************************/
1221 template Foo61(alias a
) {}
1224 const Bar61 bar61
= {};
1226 alias Foo61
!(bar61
) baz61
;
1232 /************************************************/
1234 T
foo62(T
)(lazy T value
)
1241 foo62(new float[1]);
1244 /************************************************/
1308 writefln("Success");