mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-13 02:13:14 +01:00
[svn r44] Lots of bug fixes.
New array literal support New array ~= operator support (for single element) New with statement support More...
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
module arrays4;
|
||||
|
||||
import std.stdio;
|
||||
void main()
|
||||
{
|
||||
auto arr = new int[4];
|
||||
auto arrcat = arr ~ arr;
|
||||
assert(arrcat.length == arr.length * 2);
|
||||
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);
|
||||
writefln(arr);
|
||||
}
|
||||
|
||||
|
||||
6
test/arrays6.d
Normal file
6
test/arrays6.d
Normal file
@@ -0,0 +1,6 @@
|
||||
module arrays6;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[4] a = [1,2,3,4];
|
||||
}
|
||||
19
test/arrays7.d
Normal file
19
test/arrays7.d
Normal file
@@ -0,0 +1,19 @@
|
||||
module arrays7;
|
||||
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
float f;
|
||||
long l;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
S[] arr;
|
||||
S s;
|
||||
arr ~= s;
|
||||
arr ~= S(1,2.64,0xFFFF_FFFF_FFFF);
|
||||
assert(arr[1].i == 1);
|
||||
assert(arr[1].f > 2.63 && arr[1].f < 2.65);
|
||||
assert(arr[1].l == 0xFFFF_FFFF_FFFF);
|
||||
}
|
||||
23
test/bug10.d
Normal file
23
test/bug10.d
Normal file
@@ -0,0 +1,23 @@
|
||||
module bug10;
|
||||
import std.stdio;
|
||||
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
test/bug11.d
Normal file
12
test/bug11.d
Normal file
@@ -0,0 +1,12 @@
|
||||
module bug11;
|
||||
|
||||
struct S
|
||||
{
|
||||
int[4] arr;
|
||||
}
|
||||
|
||||
S s=S([1,2,3,4]);
|
||||
|
||||
void main()
|
||||
{
|
||||
}
|
||||
6
test/bug12.d
Normal file
6
test/bug12.d
Normal file
@@ -0,0 +1,6 @@
|
||||
module bug12;
|
||||
|
||||
void main()
|
||||
{
|
||||
const string name="y";
|
||||
}
|
||||
18
test/bug13.d
Normal file
18
test/bug13.d
Normal 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
test/bug14.d
Normal file
7
test/bug14.d
Normal file
@@ -0,0 +1,7 @@
|
||||
module bug14;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[] arr = new int[12];
|
||||
int i = arr[0];
|
||||
}
|
||||
17
test/bug15.d
Normal file
17
test/bug15.d
Normal 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));
|
||||
}
|
||||
@@ -17,6 +17,8 @@ void main()
|
||||
S s;
|
||||
s.arr = new int[5];
|
||||
s.arr[1] = 32;
|
||||
assert(s.arr[0] == 0);
|
||||
assert(s.arr[1] == 32);
|
||||
int i;
|
||||
i = s.arr[0];
|
||||
//assert(s.arr[0] == 0);
|
||||
//assert(s.arr[1] == 32);
|
||||
}
|
||||
|
||||
21
test/bug8.d
Normal file
21
test/bug8.d
Normal file
@@ -0,0 +1,21 @@
|
||||
module bug8;
|
||||
|
||||
void main()
|
||||
{
|
||||
s = newS();
|
||||
}
|
||||
|
||||
S* s;
|
||||
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
}
|
||||
|
||||
S* newS()
|
||||
{
|
||||
auto tmp = new S;
|
||||
tmp.i = 4;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
32
test/bug9.d
Normal file
32
test/bug9.d
Normal file
@@ -0,0 +1,32 @@
|
||||
module bug9;
|
||||
struct rgb
|
||||
{
|
||||
ubyte[3] values;
|
||||
rgb average(rgb other)
|
||||
{
|
||||
rgb res;
|
||||
foreach (id, ref v; res.values) v=(values[id]+other.values[id])/2;
|
||||
return res;
|
||||
}
|
||||
void print()
|
||||
{
|
||||
printf("[%d,%d,%d]\n", values[0], values[1], values[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
rgb a,b;
|
||||
a.values[0] = 10;
|
||||
a.values[1] = 20;
|
||||
a.values[2] = 30;
|
||||
b.values[0] = 30;
|
||||
b.values[1] = 20;
|
||||
b.values[2] = 10;
|
||||
rgb avg = a.average(b);
|
||||
avg.print();
|
||||
assert(avg.values[0] == 20);
|
||||
assert(avg.values[1] == 20);
|
||||
assert(avg.values[2] == 20);
|
||||
}
|
||||
|
||||
8
test/cond1.d
Normal file
8
test/cond1.d
Normal file
@@ -0,0 +1,8 @@
|
||||
module cond1;
|
||||
|
||||
void main()
|
||||
{
|
||||
double a = 2;
|
||||
double b = 4;
|
||||
double c = (a > 0) ? a : b;
|
||||
}
|
||||
8
test/scope2.d
Normal file
8
test/scope2.d
Normal file
@@ -0,0 +1,8 @@
|
||||
module scope2;
|
||||
|
||||
void main()
|
||||
{
|
||||
scope(exit) printf("exit\n");
|
||||
scope(failure) printf("failure\n");
|
||||
scope(success) printf("success\n");
|
||||
}
|
||||
10
test/scope3.d
Normal file
10
test/scope3.d
Normal file
@@ -0,0 +1,10 @@
|
||||
module scope3;
|
||||
|
||||
void main()
|
||||
{
|
||||
int i;
|
||||
while (i < 10) {
|
||||
scope(success) i++;
|
||||
}
|
||||
printf("%d\n", i);
|
||||
}
|
||||
13
test/scope4.d
Normal file
13
test/scope4.d
Normal file
@@ -0,0 +1,13 @@
|
||||
module scope4;
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
try
|
||||
{
|
||||
return i;
|
||||
}
|
||||
finally
|
||||
{
|
||||
//i = 1;
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,5 @@ void main()
|
||||
{
|
||||
C c = new C;
|
||||
auto s = c.toString();
|
||||
printf("%.*s\n", s.length, s.ptr);
|
||||
}
|
||||
|
||||
15
test/with1.d
Normal file
15
test/with1.d
Normal file
@@ -0,0 +1,15 @@
|
||||
module with1;
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
float f;
|
||||
}
|
||||
void main()
|
||||
{
|
||||
S s;
|
||||
with(s)
|
||||
{
|
||||
i = 0;
|
||||
f = 3.4;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user