Changeset 649
- Timestamp:
- 08/29/10 08:36:42 (14 years ago)
- Files:
-
- trunk/test/compilable/extra-files/header.di (modified) (2 diffs)
- trunk/test/compilable/extra-files/xheader.di (modified) (1 diff)
- trunk/test/fail_compilation/fail255.d (deleted)
- trunk/test/runnable/auto1.d (modified) (1 diff)
- trunk/test/runnable/bug5.d (modified) (1 diff)
- trunk/test/runnable/interface.d (modified) (1 diff)
- trunk/test/runnable/test20.d (modified) (1 diff)
- trunk/test/runnable/test23.d (modified) (1 diff)
- trunk/test/runnable/test8.d (modified) (1 diff)
- trunk/test/runnable/testdstress.d (modified) (2 diffs)
- trunk/test/runnable/testmmfile.d (modified) (1 diff)
- trunk/test/runnable/testscope.d (modified) (1 diff)
- trunk/test/runnable/warning1.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/test/compilable/extra-files/header.di
r624 r649 1 1 // D import file generated from 'compilable/header.d' 2 2 module foo.bar; 3 private 4 { 5 import std.stdio; 6 } 3 private import std.stdio; 4 7 5 pragma (lib, "test"); 8 6 pragma (msg, "Hello World"); 9 7 typedef double mydbl = 10; 10 8 int main() 11 9 in 12 10 { 13 11 assert(1 + (2 + 3) == -(1 - 2 * 3)); 14 12 } 15 13 out(result) 16 14 { 17 15 assert(result == 0); 18 16 } 19 17 body 20 18 { 21 19 float f = (float).infinity; 22 20 int i = cast(int)f; 23 21 writeln((i , 1),2); 24 22 writeln(cast(int)(float).max); 25 23 assert(i == cast(int)(float).max); 26 24 assert(i == -2147483648u); … … 243 241 } 244 242 alias A!(uint) getHUint; 245 243 alias A!(int) getHInt; 246 244 alias A!(float) getHFloat; 247 245 alias A!(ulong) getHUlong; 248 246 alias A!(long) getHLong; 249 247 alias A!(double) getHDouble; 250 248 alias A!(byte) getHByte; 251 249 alias A!(ubyte) getHUbyte; 252 250 alias A!(short) getHShort; 253 251 alias A!(ushort) getHUShort; 254 252 alias A!(real) getHReal; 255 253 } 256 254 template templ(T) 257 255 { 258 256 void templ(T val) 259 257 { 260 258 pragma (msg, "Invalid destination type."); 261 259 } 262 260 } 263 static 264 { 265 char[] charArray = ['"','\'']; 266 } 261 static char[] charArray = ['"','\'']; 262 267 263 class Point 268 264 { 269 265 auto x = 10; 270 266 uint y = 20; 271 267 } 272 268 template Foo2(bool bar) 273 269 { 274 270 void test() 275 271 { 276 272 static if(bar) 277 273 { 278 274 int i; 279 275 } 280 276 else 281 277 { 282 278 } 283 279 284 280 static if(!bar) 285 281 { 286 282 } trunk/test/compilable/extra-files/xheader.di
r624 r649 8 8 void bar(in void* p) 9 9 { 10 10 } 11 11 void f(void function() f2); 12 12 class C2; 13 13 void foo2(const C2 c); 14 14 struct Foo3 15 15 { 16 16 int k; 17 17 ~this() 18 18 { 19 19 k = 1; 20 20 } 21 21 this(this) 22 22 { 23 23 k = 2; 24 24 } 25 25 } 26 26 class C3 27 27 { 28 @property 29 { 30 int get() 28 @property int get() 31 29 { 32 30 return 0; 33 31 } 34 32 } 35 }trunk/test/runnable/auto1.d
r574 r649 1 1 2 2 import std.c.stdio; 3 3 4 4 /******************************************/ 5 5 6 autoclass Foo6 scope class Foo 7 7 { 8 8 static int x; 9 9 10 10 ~this() 11 11 { 12 12 printf("Foo.~this()\n"); 13 13 x++; 14 14 } 15 15 } 16 16 17 17 int test1x() 18 18 { 19 autoFoo f = new Foo();19 scope Foo f = new Foo(); 20 20 return 6; 21 21 } 22 22 23 23 24 24 void test1() 25 25 { 26 26 { 27 autoFoo f = new Foo();27 scope Foo f = new Foo(); 28 28 } 29 29 int c; 30 30 31 31 assert(Foo.x == 1); 32 32 c = test1x(); 33 33 assert(c == 6); 34 34 assert(Foo.x == 2); 35 35 36 36 if (c != 6) 37 autoFoo h = new Foo();37 scope Foo h = new Foo(); 38 38 assert(Foo.x == 2); 39 39 40 40 if (c == 6) 41 autoFoo j = new Foo();41 scope Foo j = new Foo(); 42 42 assert(Foo.x == 3); 43 43 44 44 { 45 autoFoo g = null, k = new Foo();45 scope Foo g = null, k = new Foo(); 46 46 assert(Foo.x == 3); 47 47 } 48 48 assert(Foo.x == 4); 49 49 } 50 50 51 51 /******************************************/ 52 52 53 53 int ax; 54 54 55 autoclass A255 scope class A2 56 56 { 57 57 this() 58 58 { 59 59 printf("A2.this()\n"); 60 60 ax += 1; 61 61 } 62 62 63 63 ~this() 64 64 { 65 65 printf("A2.~this()\n"); 66 66 ax += 1000; 67 67 } 68 68 }; 69 69 70 70 71 71 void test2() 72 72 { 73 73 { 74 autoA2 a = new A2();74 scope A2 a = new A2(); 75 75 printf("Hello world.\n"); 76 76 } 77 77 assert(ax == 1001); 78 78 } 79 79 80 80 81 81 82 82 /******************************************/ 83 83 84 84 int status3; 85 85 86 autoclass Parent386 scope class Parent3 87 87 { 88 88 } 89 89 90 autoclass Child3 : Parent390 scope class Child3 : Parent3 91 91 { 92 92 this(){ 93 93 assert(status3==0); 94 94 status3=1; 95 95 } 96 96 97 97 ~this(){ 98 98 assert(status3==1); 99 99 status3=2; 100 100 } 101 101 } 102 102 103 103 void foo3() 104 104 { 105 autoParent3 o = new Child3();105 scope Parent3 o = new Child3(); 106 106 assert(status3==1); 107 107 } 108 108 109 109 void test3() 110 110 { 111 111 foo3(); 112 112 assert(status3==2); 113 113 } 114 114 115 115 /******************************************/ 116 116 117 117 int main() 118 118 { 119 119 test1(); 120 120 test2(); 121 121 test3(); 122 122 123 123 printf("Success\n"); 124 124 return 0; 125 125 } trunk/test/runnable/bug5.d
r539 r649 1 1 // REQUIRED_ARGS: -w 2 2 3 3 class F { } 4 4 5 5 int test1() { 6 autoF f = new F(); // comment out and warning goes away6 scope F f = new F(); // comment out and warning goes away 7 7 return 0; 8 8 } 9 9 10 10 int test2() { // no return at end of function 11 11 try { 12 12 return 0; 13 13 } finally { } 14 14 } 15 15 16 16 void main() 17 17 { 18 18 test1(); 19 19 test2(); 20 20 } trunk/test/runnable/interface.d
r551 r649 32 32 IO io = new IO(); 33 33 printf("io = %p\n", io); 34 34 foo(io, io); 35 35 delete io; 36 36 } 37 37 38 38 /*******************************************/ 39 39 40 40 interface I { } 41 41 class C : I 42 42 { 43 43 ~this() { printf("~C()\n"); } 44 44 } 45 45 46 46 void test2() 47 47 { 48 48 I i = new C(); 49 49 delete i; 50 50 51 51 { 52 autoI j = new C();52 scope I j = new C(); 53 53 } 54 54 } 55 55 56 56 /*******************************************/ 57 57 58 58 int main() 59 59 { 60 60 test1(); 61 61 test2(); 62 62 63 63 printf("Success\n"); 64 64 return 0; 65 65 } trunk/test/runnable/test20.d
r553 r649 195 195 196 196 /*****************************************/ 197 197 198 198 struct Foo10 { 199 199 const bool opEquals(const ref Foo10 x) { 200 200 return this.normalize is x.normalize; 201 201 } 202 202 const Foo10 normalize() { 203 203 Foo10 res; 204 204 return res; 205 205 } 206 206 } 207 207 208 208 void test10() 209 209 { 210 210 } 211 211 212 212 213 213 /*****************************************/ 214 214 215 autoclass T11215 scope class T11 216 216 { 217 217 this(){} 218 218 ~this(){} 219 219 } 220 220 221 221 void test11() 222 222 { 223 autoT11 t=new T11();223 scope T11 t=new T11(); 224 224 int i=1; 225 225 switch(i) 226 226 { 227 227 case 1: 228 228 break; 229 229 230 230 default: 231 231 break; 232 232 } 233 233 } 234 234 235 235 /*****************************************/ 236 236 237 237 void test12() 238 238 { 239 239 char[] s; 240 240 char[] t; 241 241 242 242 if (true) 243 243 s = null; trunk/test/runnable/test23.d
r553 r649 719 719 720 720 new (size_t sz, int i) 721 721 { 722 722 void* p = std.c.stdlib.malloc(sz); 723 723 printf("new(sz = %d) = %p\n", sz, p); 724 724 ps = p; 725 725 return p; 726 726 } 727 727 728 728 delete(void* p) 729 729 { 730 730 printf("delete(p = %p)\n", p); 731 731 assert(p == ps); 732 732 if (p) std.c.stdlib.free(p); 733 733 del += 1; 734 734 } 735 735 } 736 736 737 737 void foo33() 738 738 { 739 autoFoo33 f = new(3) Foo33;739 scope Foo33 f = new(3) Foo33; 740 740 } 741 741 742 742 void test33() 743 743 { 744 744 foo33(); 745 745 assert(Foo33.del == 1); 746 746 } 747 747 748 748 /*******************************************/ 749 749 750 750 struct o_O { int a; } 751 751 union O_O { int a; } 752 752 class O_o { int a; } 753 753 754 754 struct Foo34 755 755 { 756 756 int ok; 757 757 o_O foo; 758 758 O_O bar; 759 759 O_o baz; trunk/test/runnable/test8.d
r551 r649 875 875 real y1,x1; 876 876 877 877 C = x1 + y1*1i + Cj; 878 878 C = 1i*y1 + x1 + Cj; 879 879 C = Cj + 1i*y1 + x1; 880 880 C = y1*1i + Cj + x1; 881 881 C = 1i*y1 + Cj; 882 882 C = Cj + 1i*y1; 883 883 } 884 884 885 885 /***********************************/ 886 886 887 887 int x44; 888 888 889 889 class A44 { 890 890 this() { printf("A44 ctor\n"); x44 += 1; } 891 891 ~this() { printf("A44 dtor\n"); x44 += 0x100; } 892 892 } 893 893 class B44 : A44 { } 894 894 895 void foo44() { autoB44 b = new B44; }895 void foo44() { scope B44 b = new B44; } 896 896 897 897 void test44() 898 898 { 899 899 printf("foo44...\n"); 900 900 foo44(); 901 901 printf("...foo44\n"); 902 902 assert(x44 == 0x101); 903 903 } 904 904 905 905 /***********************************/ 906 906 907 907 /* 908 908 import std.stdarg; 909 909 import std.utf; 910 910 911 911 int unFormat( bool delegate( out dchar ) getc, 912 912 bool delegate( dchar ) ungetc, 913 913 TypeInfo[] arguments, 914 914 void* argptr ) 915 915 { trunk/test/runnable/testdstress.d
r575 r649 432 432 433 433 /* ================================ */ 434 434 435 435 class C21(T1){ 436 436 alias T1 type1; 437 437 } 438 438 439 439 class C21(T1, T2){ 440 440 alias T1 type1; 441 441 alias .C21!(T2) type2; 442 442 } 443 443 444 444 void test21() 445 445 { 446 446 alias C21!(int,long) CT; 447 447 CT c = new CT(); 448 448 } 449 449 450 450 /* ================================ */ 451 451 452 autoclass AutoClass{452 scope class AutoClass{ 453 453 } 454 454 455 455 void test22() 456 456 { 457 autoAutoClass ac = new AutoClass();457 scope AutoClass ac = new AutoClass(); 458 458 459 459 with(ac){ 460 460 } 461 461 } 462 462 463 463 /* ================================ */ 464 464 465 465 int status23; 466 466 467 autoclass C23{467 scope class C23{ 468 468 ~this(){ 469 469 assert(status23==0); 470 470 status23--; 471 471 throw new Exception("error msg"); 472 472 } 473 473 } 474 474 475 475 void foo23(){ 476 476 assert(status23==0); 477 autoC23 ac = new C23();477 scope C23 ac = new C23(); 478 478 } 479 479 480 480 void test23() 481 481 { 482 482 try{ 483 483 foo23(); 484 484 }catch{ 485 485 } 486 486 assert(status23==-1); 487 487 } 488 488 489 489 /* ================================ */ 490 490 491 491 int status24; 492 492 493 autoclass C24{493 scope class C24{ 494 494 this(){ 495 495 assert(status24==0); 496 496 status24+=2; 497 497 } 498 498 ~this(){ 499 499 assert(status24==2); 500 500 status24--; 501 501 throw new Exception("error msg"); 502 502 } 503 503 } 504 504 505 505 void check24(){ 506 autoC24 ac = new C24();506 scope C24 ac = new C24(); 507 507 throw new Exception("check error"); 508 508 } 509 509 510 510 void test24() 511 511 { 512 512 assert(status24==0); 513 513 try{ 514 514 check24(); 515 515 }catch{ 516 516 assert(status24==1); 517 517 status24-=5; 518 518 } 519 519 assert(status24==-4); 520 520 } 521 521 522 522 /* ================================ */ 523 523 524 524 struct S25{ 525 525 S25 opSub(int i) { S25 s; return s; } 526 526 } … … 621 621 622 622 /* ================================ */ 623 623 624 624 int status30; 625 625 626 626 class C30 627 627 { 628 628 this(){ 629 629 status30++; 630 630 } 631 631 632 632 ~this(){ 633 633 status30--; 634 634 throw new Exception("E2"); 635 635 } 636 636 } 637 637 638 638 void test30() 639 639 { 640 640 try{ 641 autoC30 m = new C30();641 scope C30 m = new C30(); 642 642 assert(status30 == 1); 643 643 delete m; 644 644 }catch(Error e){ 645 645 assert(status30 == 0); 646 646 status30--; 647 647 } 648 648 649 649 assert(status30 == -1); 650 650 } 651 651 652 652 /* ================================ */ 653 653 654 654 void test31() 655 655 { 656 656 string str = x"F0 9D 83 93"; // utf-8 for U+1D0D3 657 657 658 658 int count=0; 659 659 dchar tmp; 660 660 foreach(dchar value ; str){ 661 661 tmp=value; trunk/test/runnable/testmmfile.d
r575 r649 1 1 // PERMUTE_ARGS: 2 2 // REQUIRED_ARGS: -d 3 3 4 4 import std.file; 5 5 import std.mmfile; 6 6 7 7 int main() 8 8 { 9 9 static string name = "test.tmp"; 10 10 static string s = "abcd"; 11 11 12 12 write(name, s); 13 13 14 { autoMmFile mmf = new MmFile(name);14 { scope MmFile mmf = new MmFile(name); 15 15 string p; 16 16 17 17 assert(mmf[0] == 'a'); 18 18 p = cast(string)mmf[]; 19 19 //printf("p.length = %d\n", p.length); 20 20 assert(p[1] == 'b'); 21 21 p = cast(string)mmf[0 .. 4]; 22 22 assert(p[2] == 'c'); 23 23 } 24 24 25 { autoMmFile mmf = new MmFile(name, MmFile.Mode.Read, 0, null);25 { scope MmFile mmf = new MmFile(name, MmFile.Mode.Read, 0, null); 26 26 string p; 27 27 28 28 assert(mmf[0] == 'a'); 29 29 p = cast(string)mmf[]; 30 30 //printf("p.length = %d\n", p.length); 31 31 assert(mmf.length == 4); 32 32 assert(p[1] == 'b'); 33 33 p = cast(string)mmf[0 .. 4]; 34 34 assert(p[2] == 'c'); 35 35 } 36 36 37 37 remove(name); 38 38 39 { autoMmFile mmf = new MmFile(name, MmFile.Mode.ReadWriteNew, 4, null);39 { scope MmFile mmf = new MmFile(name, MmFile.Mode.ReadWriteNew, 4, null); 40 40 char[] p; 41 41 42 42 p = cast(char[])mmf[]; 43 43 p[] = "1234"; 44 44 mmf[3] = '5'; 45 45 assert(mmf[2] == '3'); 46 46 assert(mmf[3] == '5'); 47 47 } 48 48 49 49 { string p = cast(string)read(name); 50 50 51 51 assert(p[] == "1235"); 52 52 } 53 53 54 { autoMmFile mmf = new MmFile(name, MmFile.Mode.ReadWriteNew, 4, null);54 { scope MmFile mmf = new MmFile(name, MmFile.Mode.ReadWriteNew, 4, null); 55 55 char[] p; 56 56 57 57 p = cast(char[])mmf[]; 58 58 p[] = "5678"; 59 59 mmf[3] = '5'; 60 60 assert(mmf[2] == '7'); 61 61 assert(mmf[3] == '5'); 62 62 assert(cast(string)mmf[] == "5675"); 63 63 } 64 64 65 65 { string p = cast(string)read(name); 66 66 67 67 assert(p[] == "5675"); 68 68 } 69 69 70 { autoMmFile mmf = new MmFile(name, MmFile.Mode.ReadWrite, 4, null);70 { scope MmFile mmf = new MmFile(name, MmFile.Mode.ReadWrite, 4, null); 71 71 char[] p; 72 72 73 73 p = cast(char[])mmf[]; 74 74 assert(cast(char[])mmf[] == "5675"); 75 75 p[] = "9102"; 76 76 mmf[2] = '5'; 77 77 assert(cast(string)mmf[] == "9152"); 78 78 } 79 79 80 80 { string p = cast(string)read(name); 81 81 82 82 assert(p[] == "9152"); 83 83 } 84 84 85 85 remove(name); 86 86 87 { autoMmFile mmf = new MmFile(name, MmFile.Mode.ReadWrite, 4, null);87 { scope MmFile mmf = new MmFile(name, MmFile.Mode.ReadWrite, 4, null); 88 88 char[] p; 89 89 90 90 p = cast(char[])mmf[]; 91 91 p[] = "abcd"; 92 92 mmf[2] = '5'; 93 93 assert(cast(string)mmf[] == "ab5d"); 94 94 } 95 95 96 96 { string p = cast(string)read(name); 97 97 98 98 assert(p[] == "ab5d"); 99 99 } 100 100 101 { autoMmFile mmf = new MmFile(name, MmFile.Mode.ReadCopyOnWrite, 4, null);101 { scope MmFile mmf = new MmFile(name, MmFile.Mode.ReadCopyOnWrite, 4, null); 102 102 char[] p; 103 103 104 104 p = cast(char[])mmf[]; 105 105 assert(cast(string)mmf[] == "ab5d"); 106 106 p[] = "9102"; 107 107 mmf[2] = '5'; 108 108 assert(cast(string)mmf[] == "9152"); 109 109 } 110 110 111 111 { string p = cast(string)read(name); 112 112 113 113 assert(p[] == "ab5d"); 114 114 } 115 115 116 116 remove(name); 117 117 118 118 return 0; 119 119 } trunk/test/runnable/testscope.d
r549 r649 19 19 20 20 this() 21 21 { 22 22 assert(x == 0); 23 23 x++; 24 24 printf("Foo.this()\n"); 25 25 throw new Eh(); 26 26 assert(0); 27 27 } 28 28 29 29 ~this() 30 30 { 31 31 printf("Foo.~this()\n"); 32 32 } 33 33 } 34 34 35 35 void test1() 36 36 { 37 37 try 38 38 { 39 autoFoo f = new Foo();39 scope Foo f = new Foo(); 40 40 assert(0); 41 41 } 42 42 catch (Eh) 43 43 { 44 44 assert(Foo.x == 1); 45 45 Foo.x++; 46 46 } 47 47 finally 48 48 { 49 49 assert(Foo.x == 2); 50 50 Foo.x++; 51 51 } 52 52 assert(Foo.x == 3); 53 53 } 54 54 55 55 /********************************************/ 56 56 57 57 void test2() 58 58 { 59 59 int x; trunk/test/runnable/warning1.d
r549 r649 1 1 // REQUIRED_ARGS: -w 2 2 // PERMUTE_ARGS: 3 3 4 4 extern(C) int printf(const char*, ...); 5 5 6 6 class F { } 7 7 int foo() 8 8 { 9 autoF f = new F(); // comment out and warning goes away9 scope F f = new F(); // comment out and warning goes away 10 10 return 0; 11 11 } 12 12 13 13 int foo2() 14 14 { 15 15 try { 16 16 return 0; 17 17 } finally { } 18 18 } 19 19 20 20 private int getNthInt(A...)(uint index, A args) 21 21 { 22 22 foreach (i, arg; args) 23 23 { 24 24 static if (is(typeof(arg) : long) || is(typeof(arg) : ulong)) 25 25 { 26 26 if (i != index) continue; 27 27 return cast(int)(arg); 28 28 } 29 29 else
