mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-06-08 17:54:10 +02:00
[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:
78
tests/minicomplex/arrays1.d
Normal file
78
tests/minicomplex/arrays1.d
Normal file
@@ -0,0 +1,78 @@
|
||||
module tangotests.arrays1;
|
||||
|
||||
import tango.stdc.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
real[] arr;
|
||||
print(arr);
|
||||
main2();
|
||||
}
|
||||
|
||||
void main2()
|
||||
{
|
||||
real[] arr = void;
|
||||
fill(arr);
|
||||
print(arr);
|
||||
main3();
|
||||
}
|
||||
|
||||
void main3()
|
||||
{
|
||||
}
|
||||
|
||||
void print(real[] arr)
|
||||
{
|
||||
printf("len=%u ; ptr=%p\n", arr.length, arr.ptr);
|
||||
}
|
||||
|
||||
void fill(ref real[] arr)
|
||||
{
|
||||
auto ptr = cast(void**)&arr;
|
||||
*ptr++ = cast(void*)0xbeefc0de;
|
||||
*ptr = cast(void*)0xbeefc0de;
|
||||
}
|
||||
|
||||
void dg1(void delegate(int[]) dg)
|
||||
{
|
||||
dg2(dg);
|
||||
}
|
||||
|
||||
void dg2(void delegate(int[]) dg)
|
||||
{
|
||||
dg(null);
|
||||
}
|
||||
|
||||
void sarr1(int[16] sa)
|
||||
{
|
||||
sarr1(sa);
|
||||
}
|
||||
|
||||
struct Str
|
||||
{
|
||||
size_t length;
|
||||
char* ptr;
|
||||
}
|
||||
|
||||
void str1(Str str)
|
||||
{
|
||||
str1(str);
|
||||
}
|
||||
|
||||
void str2(ref Str str)
|
||||
{
|
||||
str2(str);
|
||||
}
|
||||
|
||||
void str3(out Str str)
|
||||
{
|
||||
str3(str);
|
||||
}
|
||||
|
||||
void str4(Str* str)
|
||||
{
|
||||
str4(str);
|
||||
}
|
||||
|
||||
void str5(Str);
|
||||
|
||||
29
tests/minicomplex/constructors.d
Normal file
29
tests/minicomplex/constructors.d
Normal file
@@ -0,0 +1,29 @@
|
||||
import tango.io.Console;
|
||||
|
||||
class C
|
||||
{
|
||||
this()
|
||||
{
|
||||
Cout("C()").newline;
|
||||
}
|
||||
this(char[] str)
|
||||
{
|
||||
Cout("C(")(str)(")").newline;
|
||||
}
|
||||
}
|
||||
|
||||
class D : C
|
||||
{
|
||||
this()
|
||||
{
|
||||
super("D");
|
||||
Cout("D()").newline;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
auto c1 = new C();
|
||||
auto c2 = new C("C");
|
||||
auto d = new D();
|
||||
}
|
||||
12
tests/minicomplex/files1.d
Normal file
12
tests/minicomplex/files1.d
Normal file
@@ -0,0 +1,12 @@
|
||||
module tangotests.files1;
|
||||
|
||||
//import tango.io.Stdout;
|
||||
import tango.io.File;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto file = new File("files1.output");
|
||||
char[] str = "hello world from files1 test\n";
|
||||
void[] data = cast(void[])str;
|
||||
file.write(str);
|
||||
}
|
||||
9
tests/minicomplex/gc2.d
Normal file
9
tests/minicomplex/gc2.d
Normal file
@@ -0,0 +1,9 @@
|
||||
module tangotests.gc2;
|
||||
|
||||
import tango.core.Memory;
|
||||
|
||||
void main()
|
||||
{
|
||||
char[] tmp = new char[2500];
|
||||
GC.collect();
|
||||
}
|
||||
11
tests/minicomplex/ina1.d
Normal file
11
tests/minicomplex/ina1.d
Normal file
@@ -0,0 +1,11 @@
|
||||
module tangotests.ina1;
|
||||
|
||||
import tango.stdc.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
int alder;
|
||||
printf("Hvor gammel er du?\n");
|
||||
scanf("%d", &alder);
|
||||
printf("om 10 år er du %d\n", alder + 10);
|
||||
}
|
||||
6
tests/minicomplex/l.d
Normal file
6
tests/minicomplex/l.d
Normal file
@@ -0,0 +1,6 @@
|
||||
import tango.io.Console;
|
||||
|
||||
void main()
|
||||
{
|
||||
Cout("Hi, says LLVMDC + Tango").newline;
|
||||
}
|
||||
63
tests/minicomplex/mem1.d
Normal file
63
tests/minicomplex/mem1.d
Normal file
@@ -0,0 +1,63 @@
|
||||
module tangotests.mem1;
|
||||
|
||||
import tango.stdc.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
printf("new int;\n");
|
||||
int* i = new int;
|
||||
assert(*i == 0);
|
||||
|
||||
printf("new int[3];\n");
|
||||
int[] ar = new int[3];
|
||||
ar[0] = 1;
|
||||
ar[1] = 56;
|
||||
assert(ar.length == 3);
|
||||
assert(ar[0] == 1);
|
||||
assert(ar[1] == 56);
|
||||
assert(ar[2] == 0);
|
||||
|
||||
printf("array ~= elem;\n");
|
||||
int[] ar2;
|
||||
ar2 ~= 22;
|
||||
assert(ar2.length == 1);
|
||||
assert(ar2[0] == 22);
|
||||
|
||||
printf("array ~= array;\n");
|
||||
ar2 ~= ar;
|
||||
assert(ar2.length == 4);
|
||||
assert(ar2[0] == 22);
|
||||
assert(ar2[1] == 1);
|
||||
printf("%d %d %d %d\n", ar2[0], ar2[1], ar2[2], ar2[3]);
|
||||
assert(ar2[2] == 56);
|
||||
assert(ar2[3] == 0);
|
||||
|
||||
printf("array ~ array;\n");
|
||||
int[] ar5 = ar ~ ar2;
|
||||
assert(ar5.length == 7);
|
||||
assert(ar5[0] == 1);
|
||||
assert(ar5[1] == 56);
|
||||
assert(ar5[2] == 0);
|
||||
assert(ar5[3] == 22);
|
||||
assert(ar5[4] == 1);
|
||||
assert(ar5[5] == 56);
|
||||
assert(ar5[6] == 0);
|
||||
|
||||
printf("array ~ elem;\n");
|
||||
int[] ar4 = ar2 ~ 123;
|
||||
assert(ar4.length == 5);
|
||||
assert(ar4[0] == 22);
|
||||
assert(ar4[1] == 1);
|
||||
assert(ar4[2] == 56);
|
||||
assert(ar4[3] == 0);
|
||||
assert(ar4[4] == 123);
|
||||
|
||||
printf("elem ~ array;\n");
|
||||
int[] ar3 = 123 ~ ar2;
|
||||
assert(ar3.length == 5);
|
||||
assert(ar3[0] == 123);
|
||||
assert(ar3[1] == 22);
|
||||
assert(ar3[2] == 1);
|
||||
assert(ar3[3] == 56);
|
||||
assert(ar3[4] == 0);
|
||||
}
|
||||
29
tests/minicomplex/mem4.d
Normal file
29
tests/minicomplex/mem4.d
Normal file
@@ -0,0 +1,29 @@
|
||||
module tangotests.mem4;
|
||||
|
||||
import tango.stdc.stdio;
|
||||
|
||||
class C {
|
||||
int* ptr;
|
||||
this() {
|
||||
printf("this()\n");
|
||||
ptr = new int;
|
||||
}
|
||||
~this() {
|
||||
printf("~this()\n");
|
||||
delete ptr;
|
||||
assert(ptr is null);
|
||||
}
|
||||
final void check()
|
||||
{
|
||||
printf("check()\n");
|
||||
assert(ptr !is null);
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
C c = new C();
|
||||
c.check();
|
||||
delete c;
|
||||
assert(c is null);
|
||||
}
|
||||
7
tests/minicomplex/stdout1.d
Normal file
7
tests/minicomplex/stdout1.d
Normal file
@@ -0,0 +1,7 @@
|
||||
import tango.io.Stdout;
|
||||
|
||||
void main()
|
||||
{
|
||||
Stdout("Hello World").newline;
|
||||
Stdout.formatln("{} {}", "Hello", "World");
|
||||
}
|
||||
8
tests/minicomplex/stdout2.d
Normal file
8
tests/minicomplex/stdout2.d
Normal file
@@ -0,0 +1,8 @@
|
||||
module tangotests.stdout2;
|
||||
|
||||
import tango.io.Stdout;
|
||||
|
||||
void main()
|
||||
{
|
||||
Stdout.formatln("{} {} {}", "a", "b", 1.0);
|
||||
}
|
||||
13
tests/minicomplex/templ1.d
Normal file
13
tests/minicomplex/templ1.d
Normal file
@@ -0,0 +1,13 @@
|
||||
module tangotests.templ1;
|
||||
|
||||
import Util = tango.text.Util;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
void main()
|
||||
{
|
||||
foreach (line; Util.lines("a\nb\nc"))
|
||||
{
|
||||
printf("%.*s\n", line.length, line.ptr);
|
||||
}
|
||||
}
|
||||
9
tests/minicomplex/u.d
Normal file
9
tests/minicomplex/u.d
Normal file
@@ -0,0 +1,9 @@
|
||||
import tango.io.Console;
|
||||
void main()
|
||||
{
|
||||
Cout("getting name std").newline;
|
||||
Cerr("getting name err").newline;
|
||||
auto s = Cin.get();
|
||||
Cout("putting name").newline;
|
||||
Cout (s).newline;
|
||||
}
|
||||
13
tests/minicomplex/vararg1.d
Normal file
13
tests/minicomplex/vararg1.d
Normal file
@@ -0,0 +1,13 @@
|
||||
module tangotests.vararg1;
|
||||
|
||||
import tango.stdc.stdio;
|
||||
|
||||
void func(int[] arr...)
|
||||
{
|
||||
printf("1,2,4,5,6 == %d,%d,%d,%d,%d\n", arr[0],arr[1],arr[2],arr[3],arr[4]);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
func(1,2,4,5,6);
|
||||
}
|
||||
42
tests/minicomplex/vararg2.d
Normal file
42
tests/minicomplex/vararg2.d
Normal file
@@ -0,0 +1,42 @@
|
||||
module tangotests.vararg2;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
import tango.core.Vararg;
|
||||
|
||||
void main()
|
||||
{
|
||||
func(0xf00, 1, " ", 2, " ", 3, "\n", 0.3, "\n");
|
||||
}
|
||||
|
||||
void func(int foo, ...)
|
||||
{
|
||||
foreach(t; _arguments)
|
||||
{
|
||||
if (t == typeid(char[]))
|
||||
{
|
||||
char[] str = va_arg!(char[])(_argptr);
|
||||
printf("%.*s", str.length, str.ptr);
|
||||
}
|
||||
else if (t == typeid(int))
|
||||
{
|
||||
printf("%d", va_arg!(int)(_argptr));
|
||||
}
|
||||
else if (t == typeid(float))
|
||||
{
|
||||
printf("%f", va_arg!(float)(_argptr));
|
||||
}
|
||||
else if (t == typeid(double))
|
||||
{
|
||||
printf("%f", va_arg!(double)(_argptr));
|
||||
}
|
||||
else if (t == typeid(real))
|
||||
{
|
||||
printf("%f", va_arg!(real)(_argptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0, "not int");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
tests/minicomplex/volatile1.d
Normal file
13
tests/minicomplex/volatile1.d
Normal file
@@ -0,0 +1,13 @@
|
||||
module tangotests.volatile1;
|
||||
|
||||
import tango.stdc.stdlib;
|
||||
|
||||
void main()
|
||||
{
|
||||
int var = rand();
|
||||
{
|
||||
int i = var;
|
||||
volatile;
|
||||
int j = i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user