[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.

This commit is contained in:
Tomas Lindquist Olsen
2008-07-13 02:51:19 +02:00
parent d1e41f611e
commit cecb64b2e4
339 changed files with 388 additions and 172 deletions

23
tests/mini/a.d Normal file
View File

@@ -0,0 +1,23 @@
module a;
extern(C) int printf(char*, ...);
int i = 42;
void main()
{
int j;
j = i;
int* p;
p = &j;
int k = *p;
assert(k == 42);
byte b = -1;
int i = b;
assert(i == -1);
int* p2 = p;
printf("Done\n");
}

34
tests/mini/a_1.d Normal file
View File

@@ -0,0 +1,34 @@
class Foo
{
this(int j)
{
i = pi = j;
}
int i;
private:
int pi;
}
class Bar : Foo
{
this(int j)
{
super(j);
baz = 42;
}
int baz;
}
void func()
{
auto bar = new Bar(12);
}
void main()
{
func();
}

15
tests/mini/aa1.d Normal file
View File

@@ -0,0 +1,15 @@
module aa1;
void main()
{
int[int] aai;
assert(aai is null);
aai[0] = 52;
assert(aai !is null);
int i = aai[0];
assert(i == 52);
aai[32] = 123;
int j = aai[32];
assert(i == 52);
assert(j == 123);
}

21
tests/mini/aa1_1.d Normal file
View File

@@ -0,0 +1,21 @@
module tangotests.aa1_1;
extern(C) int printf(char*,...);
void main()
{
int[int] map;
map[1] = 1;
map[10] = 1;
map[11] = 11;
map[14] = 41;
map[21] = 12;
map[23] = 32;
map[32] = 23;
map[201] = 102;
foreach(k,v; map)
{
printf("%d:%d ", k,v);
}
printf("\n");
}

12
tests/mini/aa2.d Normal file
View File

@@ -0,0 +1,12 @@
module aa2;
void main()
{
long[float] aa;
long* p = 2.0f in aa;
assert(!p);
aa[4f] = 23;
p = 4f in aa;
assert(p);
assert(*p == 23);
}

12
tests/mini/aa2_1.d Normal file
View File

@@ -0,0 +1,12 @@
module tangotests.aa2_1;
int main()
{
int[cdouble] x;
cdouble d=22.0+0.0i;
x[d] = 44;
if(44 != x[d]){
assert(0);
}
return 0;
}

27
tests/mini/aa3.d Normal file
View File

@@ -0,0 +1,27 @@
module aa3;
extern(C) int printf(char*, ...);
alias char[] string;
void main()
{
int[string] aa;
{aa["hello"] = 1;}
{int* p = "" in aa;}
aa[" worl"] = 2;
aa["d"] = 3;
aa["thisisgreat"] = 10;
int sum;
string cat;
{
foreach(k,v;aa)
{
printf("int[%.*s] = %d\n", k.length, k.ptr, v);
sum += v;
cat ~= k;
}
}
assert(sum == 16);
printf("cat = %.*s\n", cat.length, cat.ptr);
assert(cat.length == 22);
}

20
tests/mini/aa4.d Normal file
View File

@@ -0,0 +1,20 @@
module aa4;
void main()
{
int[int] aa;
aa = addkey(aa,42,12);
int* p = haskey(aa,42);
assert(p && *p == 12);
}
int[int] addkey(int[int] aa, int key, int val)
{
aa[key] = val;
return aa;
}
int* haskey(int[int] aa, int key)
{
return key in aa;
}

9
tests/mini/aa5.d Normal file
View File

@@ -0,0 +1,9 @@
module aa5;
void main()
{
int[int] aa;
aa[42] = 1;
int i = aa[42];
assert(i == 1);
}

27
tests/mini/aa6.d Normal file
View File

@@ -0,0 +1,27 @@
module aa6;
extern(C) int printf(char*, ...);
void main()
{
int[int] aa;
aa = [1:1, 2:4, 3:9, 4:16];
printf("---\n");
foreach(int k, int v; aa)
printf("aa[%d] = %d\n", k, v);
aa.rehash;
printf("---\n");
foreach(int k, int v; aa)
printf("aa[%d] = %d\n", k, v);
size_t n = aa.length;
assert(n == 4);
int[] keys = aa.keys;
assert(keys[] == [1,2,3,4][]);
int[] vals = aa.values;
assert(vals[] == [1,4,9,16][]);
aa.remove(3);
printf("---\n");
foreach(int k, int v; aa)
printf("aa[%d] = %d\n", k, v);
assert(aa.length == 3);
}

19
tests/mini/align1.d Normal file
View File

@@ -0,0 +1,19 @@
module tangotests.align1;
extern(C) int printf(char*, ...);
struct TLA
{
char[3] tla;
char[] toString() { return tla; }
void dump()
{
printf("%.*s\n", 3, tla.ptr);
}
}
void main()
{
TLA fbi = TLA("FBI");
fbi.dump();
}

21
tests/mini/alignment.d Normal file
View File

@@ -0,0 +1,21 @@
module alignment;
align(1) struct S
{
ubyte b;
int i;
ubyte[2] b2;
long l;
real r;
}
void main()
{
byte b;
short s;
int i;
long l;
float f;
double d;
real r;
}

17
tests/mini/alloca1.d Normal file
View File

@@ -0,0 +1,17 @@
module alloca1;
pragma(LLVM_internal, "alloca")
void* alloca(uint);
extern(C) int printf(char*, ...);
void main()
{
int n = 16;
int* p = cast(int*)alloca(n*int.sizeof);
int[] a = p[0..n];
a[] = 0;
foreach(i,v; a) {
printf("a[%2d] = %d\n", i, v);
}
}

10
tests/mini/arrayinit.d Normal file
View File

@@ -0,0 +1,10 @@
module arrayinit;
float[4] ftable = [1,2,3,4];
int[8] itable = [3:42,6:123];
private uint[7] crc32_table = [0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535];
void main()
{
assert(crc32_table[3] == 0x990951ba);
}

43
tests/mini/arrays1.d Normal file
View File

@@ -0,0 +1,43 @@
module arrays1;
extern(C) int printf(char*, ...);
void integer()
{
auto arr = new int[16];
arr[1] = 42;
arr[6] = 555;
print_int(arr);
delete arr;
}
void floating()
{
auto arr = new float[6];
arr[1] = 3.14159265;
arr[3] = 1.61803399;
print_float(arr);
delete arr;
}
void print_int(int[] arr)
{
printf("arr[%lu] = [", arr.length);
for (auto i=0; i<arr.length; i++)
printf("%d,", arr[i]);
printf("\b]\n");
}
void print_float(float[] arr)
{
printf("arr[%lu] = [", arr.length);
for (auto i=0; i<arr.length; i++)
printf("%f,", arr[i]);
printf("\b]\n");
}
void main()
{
integer();
floating();
}

7
tests/mini/arrays10.d Normal file
View File

@@ -0,0 +1,7 @@
module arrays10;
void main()
{
int[] a = new int[10];
a[] = 3;
}

51
tests/mini/arrays11.d Normal file
View File

@@ -0,0 +1,51 @@
module arrays11;
void ints()
{
int[] a = [1,2,3,4,5,6];
{assert(a == a);}
int[] b = [4,5,6,7,8,9];
{assert(a != b);}
{assert(a[3..$] == b[0..3]);}
}
void floats()
{
float[] a = [1.0f, 2.0f, 3.0f, 4.0f];
{assert(a == a);}
float[] b = [2.0f, 3.0f, 5.0f];
{assert(a != b);}
{assert(a[1..3] == b[0..2]);}
}
struct S
{
int i;
int j;
int opEquals(S s)
{
return (i == s.i) && (j == s.j);
}
}
void structs()
{
S[] a = [S(0,0), S(1,0), S(2,0), S(3,0)];
{assert(a == a);}
S[] b = [S(0,1), S(1,0), S(2,0), S(3,1)];
{assert(a != b);}
{assert(a[1..3] == b[1..3]);}
S[2] c = [S(2,0), S(3,1)];
{assert(c == b[2..$]);}
}
void main()
{
ints();
floats();
structs();
}

19
tests/mini/arrays12.d Normal file
View File

@@ -0,0 +1,19 @@
module arrays12;
void ints()
{
int[3] a = [1,2,3];
int[3] b = [2,3,4];
int[3] c = [2,5,0];
{assert(a < b);}
{assert(b > a);}
{assert(a < c);}
{assert(c > a);}
{assert(b < c);}
{assert(c > b);}
}
void main()
{
ints();
}

18
tests/mini/arrays13.d Normal file
View File

@@ -0,0 +1,18 @@
module arrays13;
extern(C) int printf(char*, ...);
void main()
{
char[] a = "hello";
assert(a > "hel");
assert(a >= "hel");
assert(a < "helloo");
assert(a <= "helloo");
assert(a > "betty");
assert(a >= "betty");
assert(a == "hello");
assert(a <= "hello");
assert(a >= "hello");
}

7
tests/mini/arrays14.d Normal file
View File

@@ -0,0 +1,7 @@
module arrays14;
void main()
{
auto s = "hello world";
auto d = s.dup;
}

43
tests/mini/arrays15.d Normal file
View File

@@ -0,0 +1,43 @@
module arrays15;
extern(C) int printf(char*, ...);
void integer()
{
auto arr = new int[16];
arr[1] = 42;
arr[6] = 555;
print_int(arr);
delete arr;
}
void floating()
{
auto arr = new float[6];
arr[1] = 3.14159265;
arr[3] = 1.61803399;
print_float(arr);
delete arr;
}
void print_int(int[] arr)
{
printf("arr[%lu] = [", arr.length);
for (auto i=0; i<arr.length; i++)
printf("%d,", arr[i]);
printf("\b]\n");
}
void print_float(float[] arr)
{
printf("arr[%lu] = [", arr.length);
for (auto i=0; i<arr.length; i++)
printf("%f,", arr[i]);
printf("\b]\n");
}
void main()
{
integer();
floating();
}

30
tests/mini/arrays16.d Normal file
View File

@@ -0,0 +1,30 @@
module tangotests.arrays2;
void main()
{
intarrays!(byte)();
intarrays!(ubyte)();
intarrays!(short)();
intarrays!(ushort)();
intarrays!(int)();
intarrays!(uint)();
intarrays!(long)();
intarrays!(ulong)();
}
void intarrays(T)()
{
T[] ia = [cast(T)1,2,3,4];
T[] ib = [cast(T)1,2,3,4];
T[] ic = [cast(T)1,2,3];
T[] id = [cast(T)1,2,3,4,5];
assert(ia == ia);
assert(ia == ib);
assert(ia != ic);
assert(ia != id);
assert(ia > ic);
assert(ia !< ic);
assert(ia < id);
assert(ia !> id);
}

6
tests/mini/arrays17.d Normal file
View File

@@ -0,0 +1,6 @@
module tangotests.arrays3;
void main()
{
const char[2][2] id = [1: "ab"];
}

27
tests/mini/arrays18.d Normal file
View File

@@ -0,0 +1,27 @@
module tangotests.arrays4;
struct Str { int a,b; }
void main() {
Str[] arr = new Str[64];
auto tmp = Str(1,2);
arr[] = tmp;
assert(arr[0].a == 1);
assert(arr[0].b == 2);
assert(arr[13].a == 1);
assert(arr[13].b == 2);
assert(arr[42].a == 1);
assert(arr[42].b == 2);
assert(arr[63].a == 1);
assert(arr[63].b == 2);
arr[] = Str(3,4);
assert(arr[0].a == 3);
assert(arr[0].b == 4);
assert(arr[13].a == 3);
assert(arr[13].b == 4);
assert(arr[42].a == 3);
assert(arr[42].b == 4);
assert(arr[63].a == 3);
assert(arr[63].b == 4);
}

19
tests/mini/arrays2.d Normal file
View File

@@ -0,0 +1,19 @@
char[] get()
{
return "hello";
}
void param(char[] s)
{
}
void refparam(ref char[] s)
{
}
void main()
{
char[] dstr = get();
param(dstr);
refparam(dstr);
}

10
tests/mini/arrays3.d Normal file
View File

@@ -0,0 +1,10 @@
module arrays3;
void main()
{
int[] arr;
{arr = new int[25];}
{assert(arr.length == 25);}
{arr.length = arr.length + 5;}
{assert(arr.length == 30);}
}

13
tests/mini/arrays4.d Normal file
View File

@@ -0,0 +1,13 @@
module arrays4;
void main()
{
int[] arr;
arr ~= 3;
assert(arr.length == 1);
assert(arr[0] == 3);
arr ~= 5;
assert(arr.length == 2);
assert(arr[0] == 3);
assert(arr[1] == 5);
}

11
tests/mini/arrays5.d Normal file
View File

@@ -0,0 +1,11 @@
module arrays5;
void main()
{
auto arr = new float[5];
{arr[4] = 1f;}
{assert(arr[0] !<>= 0f);}
{assert(arr[1] !<>= 0f);}
{assert(arr[2] !<>= 0f);}
{assert(arr[3] !<>= 0f);}
{assert(arr[4] == 1f);}
}

6
tests/mini/arrays6.d Normal file
View File

@@ -0,0 +1,6 @@
module arrays6;
void main()
{
int[4] a = [1,2,3,4];
}

32
tests/mini/arrays7.d Normal file
View File

@@ -0,0 +1,32 @@
module arrays7;
extern(C) int printf(char*, ...);
pragma(LLVM_internal, "notypeinfo")
struct S
{
int i;
float f;
long l;
void print()
{
printf("%d %f %lx\n", i, f, l);
}
}
void main()
{
S[] arr;
S s;
assert(arr.length == 0);
arr ~= s;
assert(arr.length == 1);
arr ~= S(1,2.64,0xFFFF_FFFF_FFFF);
assert(arr.length == 2);
arr[0].print();
arr[1].print();
assert(arr[1].i == 1);
assert(arr[1].f > 2.63 && arr[1].f < 2.65);
assert(arr[1].l == 0xFFFF_FFFF_FFFF);
}

19
tests/mini/arrays8.d Normal file
View File

@@ -0,0 +1,19 @@
module arrays8;
extern(C) int printf(char*, ...);
void main()
{
char[] a = "hello ";
printf(" \"%s\".length = %u\n", a.ptr, a.length);
char[] b = "world";
printf(" \"%s\".length = %u\n", b.ptr, b.length);
char[] c = a ~ b;
printf("After 'a ~ b':\n");
printf(" \"%.*s\".length = %u\n", a.length, a.ptr, a.length);
printf(" \"%.*s\".length = %u\n", b.length, b.ptr, b.length);
printf(" \"%.*s\".length = %u\n", c.length, c.ptr, c.length);
assert(c.length == a.length + b.length);
assert(c !is a);
assert(c !is b);
}

8
tests/mini/arrays9.d Normal file
View File

@@ -0,0 +1,8 @@
module arrays9;
const int[] g = [1,2,3,4];
void main()
{
}

31
tests/mini/asm1.d Normal file
View File

@@ -0,0 +1,31 @@
module asm1;
extern(C) int printf(char*, ...);
void main()
{
version(D_InlineAsm_X86)
{
int x;
asm
{
mov EAX, 42;
mov x, EAX;
}
printf("x = %d\n", x);
}
else version(D_InlineAsm_X86_64)
{
long x;
asm
{
mov RAX, 42L;
mov x, RAX;
}
printf("x = %ld\n", x);
}
else
{
static assert(0, "no inline asm for this platform yet");
}
}

21
tests/mini/asm1_1.d Normal file
View File

@@ -0,0 +1,21 @@
module tangotests.asm1_1;
extern(C) int printf(char*, ...);
int main()
{
int i = 12;
int* ip = &i;
printf("%d\n", i);
asm
{
mov EBX, ip;
mov EAX, [EBX];
add EAX, 8;
mul EAX, EAX;
mov [EBX], EAX;
}
printf("%d\n", i);
assert(i == 400);
return 0;
}

19
tests/mini/asm2.d Normal file
View File

@@ -0,0 +1,19 @@
module tangotests.asm2;
extern(C) int printf(char*, ...);
int main()
{
int i = 40;
int j = 2;
asm
{
mov EAX, i;
mov EBX, j;
add EAX, EBX;
mov i, EAX;
}
printf("42 = %d\n", i);
assert(i == 42);
return 0;
}

15
tests/mini/asm3.d Normal file
View File

@@ -0,0 +1,15 @@
module tangotests.asm3;
extern(C) int printf(char*, ...);
void main()
{
char* fmt = "Hello D World\n";
printf(fmt);
asm
{
push fmt;
call printf;
pop EAX;
}
}

20
tests/mini/asm4.d Normal file
View File

@@ -0,0 +1,20 @@
module tangotests.asm4;
extern(C) int printf(char*,...);
void main()
{
char* fmt = "yay!\n";
asm
{
jmp L2;
L1:;
jmp L3;
L2:;
jmp L1;
L3:;
push fmt;
call printf;
pop EAX;
}
}

20
tests/mini/asm5.d Normal file
View File

@@ -0,0 +1,20 @@
module tangotests.asm5;
extern(C) int printf(char*, ...);
void main()
{
int i = func();
printf("%d\n", i);
assert(i == 42);
}
int func()
{
asm
{
naked;
mov EAX, 42;
ret;
}
}

23
tests/mini/asm6.d Normal file
View File

@@ -0,0 +1,23 @@
extern(C) int printf(char*, ...);
void main()
{
int a,b,c;
a = int.max-1;
b = 1;
asm
{
mov EAX, a;
mov ECX, b;
add EAX, ECX;
jo Loverflow;
mov c, EAX;
}
printf("c == %d\n", c);
assert(c == a+b);
return;
Loverflow:
assert(0, "overflow");
}

41
tests/mini/asm7.d Normal file
View File

@@ -0,0 +1,41 @@
module tangotests.asm7;
// test massive label collisions (runtime uses Loverflow too)
void main()
{
int a = add(1,2);
int s = sub(1,2);
assert(a == 3);
assert(s == -1);
}
int add(int a, int b)
{
int res;
asm
{
mov EAX, a;
add EAX, b;
jo Loverflow;
mov res, EAX;
}
return res;
Loverflow:
assert(0, "add overflow");
}
int sub(int a, int b)
{
int res;
asm
{
mov EAX, a;
sub EAX, b;
jo Loverflow;
mov res, EAX;
}
return res;
Loverflow:
assert(0, "sub overflow");
}

23
tests/mini/assign.d Normal file
View File

@@ -0,0 +1,23 @@
module assign;
// this is taken from std.intrinsic from gdc
int mybtc(uint *p, uint bitnum)
{
uint * q = p + (bitnum / (uint.sizeof*8));
uint mask = 1 << (bitnum & ((uint.sizeof*8) - 1));
int result = *q & mask;
*q ^= mask;
return result ? -1 : 0;
}
void main()
{
uint i = 0xFFFF_FFFF;
int r = mybtc(&i, 31);
assert(r);
assert(i == 0x7FFF_FFFF);
r = mybtc(&i, 31);
assert(!r);
assert(i == 0xFFFF_FFFF);
}

25
tests/mini/b.d Normal file
View File

@@ -0,0 +1,25 @@
module b;
extern(C) int printf(char*, ...);
struct S
{
int i;
float[4] f;
}
void main()
{
S s;
int i = s.i;
int* p = &s.i;
*p = 42;
printf("%d == %d\n", *p, s.i);
float* f = &s.f[0];
printf("%f == %f\n", *f, s.f[0]);
*f = 3.1415;
printf("%f == %f\n", *f, s.f[0]);
s.f[0] = 123.456;
printf("%f == %f\n", *f, s.f[0]);
}

78
tests/mini/bitops.d Normal file
View File

@@ -0,0 +1,78 @@
extern(C) int printf(char*, ...);
void main()
{
printf("Bitwise operations test\n");
{ ushort a = 0xFFF0;
ushort b = 0x0FFF;
assert((a&b) == 0x0FF0);
assert((a|b) == 0xFFFF);
assert((a^b) == 0xF00F);
}
{ ubyte a = 0xFF;
ulong b = 0xFFFF_FFFF_FFFF_FFF0;
assert((a&b) == 0xF0);
}
{ ushort s = 0xFF;
assert((s<<1) == s*2);
assert((s>>>1) == s/2);
}
{ int s = -10;
assert((s>>1) == -5);
assert((s>>>1) != -5);
}
{ ushort a = 0xFFF0;
ushort b = 0x0FFF;
auto t = a;
t &= b;
assert(t == 0x0FF0);
t = a;
t |= b;
assert(t == 0xFFFF);
t = a;
t ^= b;
assert(t == 0xF00F);
}
{ ubyte a = 0xFF;
ulong b = 0xFFFF_FFFF_FFFF_FFF0;
a &= b;
assert(a == 0xF0);
}
{ ushort s = 0xFF;
auto t = s;
t <<= 1;
assert(t == (s*2));
t = s;
t >>>= 1;
assert(t == s/2);
}
{ int s = -10;
auto t = s;
t >>= 1;
assert(t == -5);
t = s;
t >>>= 1;
assert(t != -5);
}
{ struct S
{
uint i;
ulong l;
};
S s = S(1,4);
auto a = s.i | s.l;
assert(a == 5);
s.i = 0xFFFF_00FF;
s.l = 0xFFFF_FFFF_0000_FF00;
s.l ^= s.i;
assert(s.l == ulong.max);
s.i = 0x__FFFF_FF00;
s.l = 0xFF00FF_FF00;
s.i &= s.l;
assert(s.i == 0x00FF_FF00);
}
printf(" SUCCESS\n");
}

5
tests/mini/bug1.d Normal file
View File

@@ -0,0 +1,5 @@
module bug1;
struct Foo { Foo opSub(ref Foo b) { return Foo(); } }
struct Bar { Foo whee; }
void test(ref Bar moo) { Foo nngh; auto plonk = nngh - moo.whee; }
void main() { Bar bar; test(bar); }

24
tests/mini/bug10.d Normal file
View File

@@ -0,0 +1,24 @@
module bug10;
extern(C) int printf(char*, ...);
class C
{
char[] msg;
this()
{
}
this(char[] msg)
{
this.msg = msg;
}
}
void main()
{
auto c = new C();
c.msg = "world";
auto b = new C("hello");
printf("%.*s\n", b.msg.length, b.msg.ptr);
printf("%.*s\n", c.msg.length, c.msg.ptr);
}

12
tests/mini/bug11.d Normal file
View File

@@ -0,0 +1,12 @@
module bug11;
struct S
{
int[4] arr;
}
S s=S([1,2,3,4]);
void main()
{
}

6
tests/mini/bug12.d Normal file
View File

@@ -0,0 +1,6 @@
module bug12;
void main()
{
const char[] name="y";
}

18
tests/mini/bug13.d Normal file
View File

@@ -0,0 +1,18 @@
module bug13;
void func1(ubyte[4]* arr)
{
ubyte* b = &(*arr)[0];
func2(&(*arr)[1]);
}
void func2(ubyte* ptr)
{
assert(*ptr == 2);
}
void main()
{
ubyte[4] arr = [cast(ubyte)1,2,3,4];
func1(&arr);
}

7
tests/mini/bug14.d Normal file
View File

@@ -0,0 +1,7 @@
module bug14;
void main()
{
int[] arr = new int[12];
int i = arr[0];
}

17
tests/mini/bug15.d Normal file
View File

@@ -0,0 +1,17 @@
module bug15;
bool bool1(bool b) {
if (b) return true;
else return false;
}
bool bool2(bool b) {
if (b) {return true;}
else {return false;}
}
void main()
{
assert(bool1(true));
assert(!bool2(false));
}

11
tests/mini/bug16.d Normal file
View File

@@ -0,0 +1,11 @@
module bug16;
void func(long val)
{
val >>= 32;
}
void main()
{
func(64L);
}

13
tests/mini/bug17.d Normal file
View File

@@ -0,0 +1,13 @@
module bug17;
struct Vec
{
Vec opAdd(ref Vec b) { return Vec(); }
Vec opMul(double a) { return Vec(); }
}
void main()
{
Vec foo;
Vec bar;
auto whee=foo+bar*1f;
}

11
tests/mini/bug18.d Normal file
View File

@@ -0,0 +1,11 @@
module bug18;
struct S {
int[9] i;
}
void main()
{
int[9] i;
auto s = S(i);
}

7
tests/mini/bug19.d Normal file
View File

@@ -0,0 +1,7 @@
module bug19;
void main()
{
auto dg = (int i) { return i*2; };
assert(dg(2) == 4);
}

4
tests/mini/bug2.d Normal file
View File

@@ -0,0 +1,4 @@
module bug2;
struct Vec { Vec barf() { return Vec(); } }
class test { this(Vec whee) { } }
void main() { Vec whee; new test(whee.barf()); }

19
tests/mini/bug20.d Normal file
View File

@@ -0,0 +1,19 @@
module bug20;
extern(C) int printf(char*, ...);
void func(void delegate() dg)
{
dg();
}
void main()
{
int i = 42;
void delegate() dg = {
i++;
};
printf("i = %d\n",i);
func(dg);
printf("i = %d\n",i);
assert(i == 43);
}

17
tests/mini/bug21.d Normal file
View File

@@ -0,0 +1,17 @@
module bug21;
extern(C) int printf(char*, ...);
void main()
{
int i = 42;
auto a = {
int j = i*2;
auto b = {
return j;
};
return b();
};
int i2 = a();
printf("%d\n", i2);
assert(i2 == i*2);
}

12
tests/mini/bug22.d Normal file
View File

@@ -0,0 +1,12 @@
module bug22;
extern(C) int printf(char*, ...);
void main()
{
int i;
delegate {
i = 42;
}();
printf("%d\n", i);
assert(i == 42);
}

15
tests/mini/bug23.d Normal file
View File

@@ -0,0 +1,15 @@
module bug23;
extern(C) int printf(char*, ...);
void main()
{
int i;
delegate {
i++;
delegate {
i++;
}();
}();
printf("%d\n", i);
assert(i == 2);
}

22
tests/mini/bug24.d Normal file
View File

@@ -0,0 +1,22 @@
module bug24;
extern(C) int printf(char*, ...);
struct S
{
long l;
float f;
}
void main()
{
S s = S(3L,2f);
delegate {
S t = S(4L, 1f);
delegate {
s.l += t.l;
s.f += t.f;
}();
}();
printf("%lu %f\n", s.l, s.f);
assert(s.l == 7 && s.f == 3);
}

13
tests/mini/bug25.d Normal file
View File

@@ -0,0 +1,13 @@
module bug25;
extern(C) int printf(char*, ...);
void main()
{
int i = 2;
delegate {
i = i*i;
i += i*i;
}();
printf("%d\n", i);
assert(i == 20);
}

8
tests/mini/bug26.d Normal file
View File

@@ -0,0 +1,8 @@
module bug26;
extern int i;
void main()
{
int j = i;
}

17
tests/mini/bug27.d Normal file
View File

@@ -0,0 +1,17 @@
module bug27;
int func(int a, int b)
{
if (a == b)
return 0;
else if (a < b)
return -1;
else
return 1;
}
void main()
{
int i = func(3,4);
assert(i == -1);
}

17
tests/mini/bug28.d Normal file
View File

@@ -0,0 +1,17 @@
module bug28;
void main()
{
char[] a = "hello";
char[] b = "hello";
char[] c = "world";
char[] d = "somethingelse";
assert(a == a);
assert(a == b);
assert(a != c);
assert(b != c);
assert(a != d);
assert(b != d);
assert(c != d);
assert(d == d);
}

16
tests/mini/bug29.d Normal file
View File

@@ -0,0 +1,16 @@
module bug29;
extern(C) int printf(char*, ...);
void main()
{
int[] arr16 = new int[4];
{
void[] arr = arr16;
{
printf("%lu\n", arr.length);
{
assert(arr.length == 16);
}
}
}
}

24
tests/mini/bug3.d Normal file
View File

@@ -0,0 +1,24 @@
module bug3;
struct S
{
int[] arr;
char[5] ch;
}
class C
{
int[] arr;
char[4] crs;
}
void main()
{
S s;
s.arr = new int[5];
s.arr[1] = 32;
int i;
i = s.arr[0];
//assert(s.arr[0] == 0);
//assert(s.arr[1] == 32);
}

22
tests/mini/bug30.d Normal file
View File

@@ -0,0 +1,22 @@
module bug30;
void main()
{
int[] a = new int[4];
{a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;}
int[] b = new int[4];
{b[0] = 1;
b[1] = 2;
b[2] = 3;
b[3] = 4;}
int[] c = new int[4];
{c[0] = 1;
c[1] = 2;
c[2] = 4;
c[3] = 3;}
{assert(a == b);}
{assert(a != c);}
}

15
tests/mini/bug32.d Normal file
View File

@@ -0,0 +1,15 @@
module bug32;
extern(C) int printf(char*, ...);
struct S
{
char[] getName() { return name; }
char[] name;
}
void main()
{
S s = S("Kyle");
char[] name = s.name;
printf("%.*s\n", name.length, name.ptr);
}

33
tests/mini/bug33.d Normal file
View File

@@ -0,0 +1,33 @@
module bug33;
extern(C) int memcmp(void*,void*,size_t);
private int string_cmp(char[] s1, char[] s2)
{
auto len = s1.length;
if (s2.length < len)
len = s2.length;
int result = memcmp(s1.ptr, s2.ptr, len);
if (result == 0)
result = cast(int)(cast(ptrdiff_t)s1.length - cast(ptrdiff_t)s2.length);
return result;
}
struct S
{
char[] toString()
{
return "S";
}
}
int func()
{
S a,b;
return string_cmp(a.toString(),b.toString());
}
void main()
{
assert(func() == 0);
}

55
tests/mini/bug34.d Normal file
View File

@@ -0,0 +1,55 @@
module bug34;
class MyTypeInfo_Pointer
{
char[] toString() { return m_next.toString() ~ "*"; }
int opEquals(Object o)
{ TypeInfo_Pointer c;
return this is o ||
((c = cast(TypeInfo_Pointer)o) !is null &&
this.m_next == c.m_next);
}
hash_t getHash(void *p)
{
return cast(uint)*cast(void* *)p;
}
int equals(void *p1, void *p2)
{
return cast(int)(*cast(void* *)p1 == *cast(void* *)p2);
}
int compare(void *p1, void *p2)
{
if (*cast(void* *)p1 < *cast(void* *)p2)
return -1;
else if (*cast(void* *)p1 > *cast(void* *)p2)
return 1;
else
return 0;
}
size_t tsize()
{
return (void*).sizeof;
}
void swap(void *p1, void *p2)
{ void* tmp;
tmp = *cast(void**)p1;
*cast(void**)p1 = *cast(void**)p2;
*cast(void**)p2 = tmp;
}
TypeInfo next() { return m_next; }
uint flags() { return 1; }
TypeInfo m_next;
}
void main()
{
}

7
tests/mini/bug35.d Normal file
View File

@@ -0,0 +1,7 @@
module bug35;
private const char[10] digits = "0123456789"; /// 0..9
void main()
{
}

8
tests/mini/bug36.d Normal file
View File

@@ -0,0 +1,8 @@
module bug36;
void main()
{
int[] a;
void* cp = cast(void*)a;
}

7
tests/mini/bug37.d Normal file
View File

@@ -0,0 +1,7 @@
module bug37;
void main()
{
char[] a = "hello";
assert(a !is null);
}

12
tests/mini/bug38.d Normal file
View File

@@ -0,0 +1,12 @@
module bug38;
void func(int* p)
{
p++;
}
void main()
{
int i;
func(&i);
}

13
tests/mini/bug39.d Normal file
View File

@@ -0,0 +1,13 @@
module bug39;
struct S
{
long l;
}
void main()
{
S s;
s.l = 23;
void* p = &s;
}

13
tests/mini/bug4.d Normal file
View File

@@ -0,0 +1,13 @@
module bug4;
int func(int i)
{
i += 2;
i -= 3;
return i;
}
void main()
{
assert(func(4) == 3);
}

12
tests/mini/bug40.d Normal file
View File

@@ -0,0 +1,12 @@
module bug40;
char[] func(void* p)
{
return null;
}
void main()
{
char[] function(void*) fp = &func;
assert(fp(null) is null);
}

10
tests/mini/bug41.d Normal file
View File

@@ -0,0 +1,10 @@
module bug41;
void main()
{
char[] a = "hello world";
char* ap = a.ptr;
size_t i = 5;
char[] b = ap[0..i];
assert(b == "hello");
}

10
tests/mini/bug42.d Normal file
View File

@@ -0,0 +1,10 @@
module bug42;
void main() {
int i = 2;
switch (i) {
case 0:
case 1:
default:
}
}

16
tests/mini/bug43.d Normal file
View File

@@ -0,0 +1,16 @@
module bug43;
struct S
{
ubyte[3] vals;
}
void func(ubyte[3] v)
{
}
void main()
{
S s;
func(s.vals);
}

21
tests/mini/bug44.d Normal file
View File

@@ -0,0 +1,21 @@
module bug44;
pragma(LLVM_internal, "notypeinfo")
struct rgb
{
long l;
}
void foo()
{
}
rgb test() {
scope(exit) foo();
return rgb();
}
void main()
{
rgb r = test();
}

11
tests/mini/bug45.d Normal file
View File

@@ -0,0 +1,11 @@
module bug45;
void foo() {
int bar;
scope(exit) { bar++; }
if (bar) return;
}
void main() {
foo();
}

15
tests/mini/bug47.d Normal file
View File

@@ -0,0 +1,15 @@
module bug47;
bool func(bool a, bool b)
{
if (a) b = false;
return b;
}
void main()
{
assert(func(0,0) == 0);
assert(func(0,1) == 1);
assert(func(1,0) == 0);
assert(func(1,1) == 0);
}

10
tests/mini/bug48.d Normal file
View File

@@ -0,0 +1,10 @@
module bug48;
size_t func(void *p)
{
return cast(size_t)*cast(void* *)p;
}
void main()
{
}

16
tests/mini/bug49.d Normal file
View File

@@ -0,0 +1,16 @@
module bug49;
pragma(LLVM_internal, "notypeinfo")
struct S
{
int i;
long l;
}
void main()
{
S s;
s.i = 0x__FFFF_FF00;
s.l = 0xFF00FF_FF00;
s.i &= s.l;
}

17
tests/mini/bug5.d Normal file
View File

@@ -0,0 +1,17 @@
module bug5;
struct hah {
static hah f()
{
hah res;
return res;
}
hah g()
{
return hah.init;
}
}
void main()
{
}

29
tests/mini/bug50.d Normal file
View File

@@ -0,0 +1,29 @@
module bug50;
extern(C) int printf(char*, ...);
pragma(LLVM_internal, "notypeinfo")
struct S
{
int i;
float f;
long l;
void print()
{
printf("%d %f %lx\n", i, f, l);
}
}
void main()
{
S s;
s.print();
s = S(1,2,3);
s.print();
S[] arr;
{arr ~= s;}
{arr[0].print();}
{arr ~= S(1,2,3);}
{arr[1].print();}
}

10
tests/mini/bug51.d Normal file
View File

@@ -0,0 +1,10 @@
module bug51;
const ubyte[3] arr1 = 1;
const ubyte[3] arr2 = [1];
const ubyte[3] arr3 = [1:1];
void main()
{
assert(arr1 == [cast(ubyte)1,1,1][]);
assert(arr2 == [cast(ubyte)1,0,0][]);
assert(arr3 == [cast(ubyte)0,1,0][]);
}

5
tests/mini/bug52.d Normal file
View File

@@ -0,0 +1,5 @@
module bug52;
struct Vec { double x,y,z; }
struct Pair(T, U) { T first; U second; }
typedef Pair!(double, Vec) Hit;
void main() {}

6
tests/mini/bug53.d Normal file
View File

@@ -0,0 +1,6 @@
module bug53;
class Foo {
final void bar() {}
void test() { bar(); }
}
void main() {}

17
tests/mini/bug54.d Normal file
View File

@@ -0,0 +1,17 @@
module bug54;
extern(C) size_t strlen(char*);
// creating args for main
void d_main_args(size_t n, char** args, ref char[][] res)
{
assert(res.length == n);
foreach(i,v; args[0..n])
{
res[i] = v[0 .. strlen(v)];
}
}
void main()
{
}

21
tests/mini/bug55.d Normal file
View File

@@ -0,0 +1,21 @@
module bug55;
extern(C) int printf(char*, ...);
int atoi(char[] s) {
int i, fac=1;
bool neg = (s.length) && (s[0] == '-');
char[] a = neg ? s[1..$] : s;
foreach_reverse(c; a) {
i += (c-'0') * fac;
fac *= 10;
}
return !neg ? i : -i;
}
void main()
{
printf("64213 = %d\n", atoi("64213"));
printf("-64213 = %d\n", atoi("-64213"));
assert(atoi("64213") == 64213);
assert(atoi("-64213") == -64213);
}

8
tests/mini/bug56.d Normal file
View File

@@ -0,0 +1,8 @@
module bug56;
void main()
{
int[] a;
a = [1,2,3];
{int[] b = [4,5,6];}
}

10
tests/mini/bug57.d Normal file
View File

@@ -0,0 +1,10 @@
import std.stdio;
class Foo {}
void func3()
{
Foo[1] test=[new Foo];
writefln(test);
}
void main() {
func3();
}

10
tests/mini/bug58.d Normal file
View File

@@ -0,0 +1,10 @@
module bug58;
import std.stdio;
void main()
{
int[16] arr = [1,16,2,15,3,14,4,13,5,12,6,11,7,10,8,9];
writefln("arr = ",arr);
arr.sort;
writefln("arr.sort = ",arr);
assert(arr == [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
}

20
tests/mini/bug59.d Normal file
View File

@@ -0,0 +1,20 @@
module bug59;
void main()
{
int[2] a = 0;
//func(a);
a[0] = 1;
int i = a[0];
int* p = &a[0];
}
void func(int[2] a)
{
int* p = cast(int*)a;
}
void func2(int[4] a)
{
int* p = 3+cast(int*)a;
}

15
tests/mini/bug6.d Normal file
View File

@@ -0,0 +1,15 @@
module bug6;
class wrong { }
void bark(ref wrong s) { s = new wrong; }
void foo(wrong tree) {
auto old = tree;
bark(tree);
assert(old !is tree);
}
void main()
{
auto w = new wrong;
auto old = w;
foo(w);
assert(w is old);
}

18
tests/mini/bug60.d Normal file
View File

@@ -0,0 +1,18 @@
module bug60;
extern(C) int printf(char*, ...);
void func(T...)(T t)
{
foreach(v;t) {
if (v.length) {
foreach(i;v) {
printf("%d\n", i);
}
}
}
}
void main()
{
auto a = [1,2,3];
func(a);
}

27
tests/mini/bug61.d Normal file
View File

@@ -0,0 +1,27 @@
module bug61;
extern(C) int printf(char*, ...);
void main()
{
int[3] a = [42,4,141414];
printf("empty:\n");
foreach(v; a[3..$]) {
printf("int = %d\n", v);
}
printf("one element:\n");
foreach(v; a[2..$]) {
printf("int = %d\n", v);
}
printf("all elements:\n");
foreach(v; a) {
printf("int = %d\n", v);
}
printf("empty reversed:\n");
foreach_reverse(v; a[3..$]) {
printf("int = %d\n", v);
}
printf("all elements reversed:\n");
foreach_reverse(v; a) {
printf("int = %d\n", v);
}
}

13
tests/mini/bug62.d Normal file
View File

@@ -0,0 +1,13 @@
module bug62;
extern(C) int printf(char*, ...);
void main()
{
int[] arr = [1,2,5,7,9];
int i = 0;
foreach(v; arr) {
i += v;
}
printf("sum = %d\n", i);
assert(i == 24);
}

Some files were not shown because too many files have changed in this diff Show More