Changeset 815
- Timestamp:
- 12/23/10 20:36:27 (14 years ago)
- Files:
-
- trunk/test/combinations.d (added)
- trunk/test/compilable/extra-files/header.di (modified) (1 diff)
- trunk/test/compilable/header.d (modified) (1 diff)
- trunk/test/do_test.sh (added)
- trunk/test/fail_compilation/fail194.d (modified) (1 diff)
- trunk/test/fail_compilation/fail332.d (modified) (1 diff)
- trunk/test/Makefile (modified) (1 diff)
- trunk/test/runnable/imports/argufile.d (modified) (1 diff)
- trunk/test/runnable/imports/inline2a.d (modified) (1 diff)
- trunk/test/runnable/interface2.d (modified) (1 diff)
- trunk/test/runnable/lazy.d (modified) (3 diffs)
- trunk/test/runnable/opover2.d (modified) (2 diffs)
- trunk/test/runnable/sdtor.d (modified) (1 diff)
- trunk/test/runnable/test15.d (modified) (7 diffs)
- trunk/test/runnable/test20.d (modified) (2 diffs)
- trunk/test/runnable/testdate.d (modified) (1 diff)
- trunk/test/runnable/testdstress.d (modified) (1 diff)
- trunk/test/runnable/testtypeid.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/test/compilable/extra-files/header.di
r663 r815 1 1 module foo.bar; 2 private import std.stdio;3 2 import core.vararg; 3 import std.stdio; 4 4 pragma (lib, "test"); 5 5 pragma (msg, "Hello World"); 6 6 typedef double mydbl = 10; 7 7 int main() 8 8 in 9 9 { 10 10 assert(1 + (2 + 3) == -(1 - 2 * 3)); 11 11 } 12 12 out(result) 13 13 { 14 14 assert(result == 0); 15 15 } 16 16 body 17 17 { 18 18 float f = (float).infinity; 19 19 int i = cast(int)f; 20 20 writeln((i , 1),2); 21 21 writeln(cast(int)(float).max); 22 22 assert(i == cast(int)(float).max); 23 23 assert(i == -2147483648u); trunk/test/compilable/header.d
r624 r815 1 1 // PERMUTE_ARGS: 2 2 // REQUIRED_ARGS: -H -Hdtest_results/compilable 3 3 // POST_SCRIPT: compilable/extra-files/header-postscript.sh 4 4 5 5 module foo.bar; 6 6 7 private import std.stdio; 7 import core.vararg; 8 import std.stdio; 8 9 9 10 pragma(lib, "test"); 10 11 pragma(msg, "Hello World"); 11 12 12 13 typedef double mydbl = 10; 13 14 14 15 int main() 15 16 in 16 17 { 17 18 assert(1+(2+3) == -(1 - 2*3)); 18 19 } 19 20 out (result) 20 21 { 21 22 assert(result == 0); 22 23 } 23 24 body 24 25 { 25 26 float f = float.infinity; 26 27 int i = cast(int) f; 27 28 writeln((i,1),2); trunk/test/fail_compilation/fail194.d
r576 r815 1 import core.vararg; 1 2 2 3 void bar(int i, ...) { } 3 4 4 5 void foo() { } 5 6 void foo(int) { } 6 7 7 8 void main() 8 9 { 9 10 //bar(1, cast(void function())&foo); 10 11 bar(1, &foo); 11 12 } trunk/test/fail_compilation/fail332.d
r576 r815 1 import core.vararg; 2 1 3 void foo(int,...) {} 2 4 3 5 void bar(){ 4 6 foo(); 5 7 } 6 8 trunk/test/Makefile
r799 r815 76 76 export SEP=$(shell echo '\') 77 77 # bug in vim syntax hilighting, needed to kick it back into life: ') 78 78 else 79 79 export ARGS=-inline -release -gc -O -unittest -fPIC 80 80 export DMD=../src/dmd 81 81 export EXE= 82 82 export OBJ=.o 83 83 export DSEP=/ 84 84 export SEP=/ 85 85 endif 86 86 87 87 runnable_tests=$(wildcard runnable/*.d) $(wildcard runnable/*.html) $(wildcard runnable/*.sh) 88 88 runnable_test_results=$(addsuffix .out,$(addprefix $(RESULTS_DIR)/,$(runnable_tests))) 89 89 90 90 compilable_tests=$(wildcard compilable/*.d) 91 91 compilable_test_results=$(addsuffix .out,$(addprefix $(RESULTS_DIR)/,$(compilable_tests))) 92 92 93 93 fail_compilation_tests=$(wildcard fail_compilation/*.d) 94 94 fail_compilation_test_results=$(addsuffix .out,$(addprefix $(RESULTS_DIR)/,$(fail_compilation_tests))) 95 95 96 all: run_tests 97 98 ifeq ($(MODEL),64) 99 DISABLED_TESTS = \ 100 a20 \ 101 argufilem \ 102 arrayop \ 103 builtin \ 104 complex \ 105 constfold \ 106 cov2 \ 107 delegate \ 108 dhry \ 109 eh2 \ 110 foreach4 \ 111 foreach5 \ 112 hello-profile \ 113 hospital \ 114 ifti \ 115 implicit \ 116 inner \ 117 integrate \ 118 interpret2 \ 119 interpret \ 120 lazy \ 121 mixin1 \ 122 mixin2 \ 123 nested \ 124 pi \ 125 printargs \ 126 s2ir \ 127 sieve \ 128 statictor \ 129 stress \ 130 template1 \ 131 template4 \ 132 template6 \ 133 template9 \ 134 test11 \ 135 test12 \ 136 test16 \ 137 test19 \ 138 test20 \ 139 test22 \ 140 test23 \ 141 test28 \ 142 test34 \ 143 test36 \ 144 test37 \ 145 test42 \ 146 test4 \ 147 test52 \ 148 test60 \ 149 test7 \ 150 test8 \ 151 testaa2 \ 152 testaa \ 153 testarray \ 154 testconst \ 155 testdate \ 156 testdstress \ 157 testformat \ 158 testgc2 \ 159 testgc3 \ 160 testline \ 161 testmath \ 162 testmmfile \ 163 testregexp2 \ 164 testsignals \ 165 testfile \ 166 testswitch \ 167 testthread2 \ 168 testtypeid \ 169 testzip \ 170 traits \ 171 untag \ 172 variadic \ 173 wc2 \ 174 wc3 \ 175 wc \ 176 xtest46 \ 177 xtest55 178 179 $(addsuffix .d.out,$(addprefix $(RESULTS_DIR)/runnable/,$(DISABLED_TESTS))): $(RESULTS_DIR)/.created 180 $(QUIET) echo " ... $@ - disabled" 181 $(QUIET) touch $@ 182 183 $(RESULTS_DIR)/runnable/test2.sh.out: 184 $(QUIET) echo " ... $@ - disabled" 185 $(QUIET) touch $@ 186 187 $(RESULTS_DIR)/runnable/%.d.out: runnable/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/combinations $(DMD) 188 $(QUIET) ./do_test.sh $(<D) $* d 189 190 $(RESULTS_DIR)/runnable/%.html.out: runnable/%.html $(RESULTS_DIR)/.created $(RESULTS_DIR)/combinations $(DMD) 191 $(QUIET) ./do_test.sh $(<D) $* html 192 193 $(RESULTS_DIR)/runnable/%.sh.out: runnable/%.sh $(RESULTS_DIR)/.created $(RESULTS_DIR)/combinations $(DMD) 194 $(QUIET) echo " ... $(<D)/$*.sh" 195 $(QUIET) ./$(<D)/$*.sh 196 197 $(RESULTS_DIR)/compilable/%.d.out: compilable/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/combinations $(DMD) 198 $(QUIET) ./do_test.sh $(<D) $* d 199 200 $(RESULTS_DIR)/fail_compilation/%.d.out: fail_compilation/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/combinations $(DMD) 201 $(QUIET) ./do_test.sh $(<D) $* d 202 else 96 203 $(RESULTS_DIR)/runnable/%.d.out: runnable/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test $(DMD) 97 204 $(QUIET) ./$(RESULTS_DIR)/d_do_test $(<D) $* d 98 205 99 206 $(RESULTS_DIR)/runnable/%.html.out: runnable/%.html $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test $(DMD) 100 207 $(QUIET) ./$(RESULTS_DIR)/d_do_test $(<D) $* html 101 208 102 209 $(RESULTS_DIR)/runnable/%.sh.out: runnable/%.sh $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test $(DMD) 103 210 $(QUIET) echo " ... $(<D)/$*.sh" 104 211 $(QUIET) ./$(<D)/$*.sh 105 212 106 213 $(RESULTS_DIR)/compilable/%.d.out: compilable/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test $(DMD) 107 214 $(QUIET) ./$(RESULTS_DIR)/d_do_test $(<D) $* d 108 215 109 216 $(RESULTS_DIR)/fail_compilation/%.d.out: fail_compilation/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test $(DMD) 110 217 $(QUIET) ./$(RESULTS_DIR)/d_do_test $(<D) $* d 111 112 all: run_tests 218 endif 113 219 114 220 quick: 115 221 $(MAKE) ARGS="" run_tests 116 222 117 223 clean: 118 224 @echo "Removing output directory: $(RESULTS_DIR)" 119 225 $(QUIET)if [ -e $(RESULTS_DIR) ]; then rm -rf $(RESULTS_DIR); fi 120 226 121 227 $(RESULTS_DIR)/.created: 122 228 @echo Creating output directory: $(RESULTS_DIR) 123 229 $(QUIET)if [ ! -d $(RESULTS_DIR) ]; then mkdir $(RESULTS_DIR); fi 124 230 $(QUIET)if [ ! -d $(RESULTS_DIR)/runnable ]; then mkdir $(RESULTS_DIR)/runnable; fi 125 231 $(QUIET)if [ ! -d $(RESULTS_DIR)/compilable ]; then mkdir $(RESULTS_DIR)/compilable; fi 126 232 $(QUIET)if [ ! -d $(RESULTS_DIR)/fail_compilation ]; then mkdir $(RESULTS_DIR)/fail_compilation; fi 127 233 $(QUIET)touch $(RESULTS_DIR)/.created 128 234 129 235 run_tests: start_runnable_tests start_compilable_tests start_fail_compilation_tests 130 236 131 237 run_runnable_tests: $(runnable_test_results) 132 238 133 239 start_runnable_tests: $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test 134 240 @echo "Running runnable tests" 135 241 $(QUIET)$(MAKE) --no-print-directory run_runnable_tests 136 242 137 243 run_compilable_tests: $(compilable_test_results) 138 244 139 245 start_compilable_tests: $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test 140 246 @echo "Running compilable tests" 141 247 $(QUIET)$(MAKE) --no-print-directory run_compilable_tests 142 248 143 249 run_fail_compilation_tests: $(fail_compilation_test_results) 144 250 145 251 start_fail_compilation_tests: $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test 146 252 @echo "Running fail compilation tests" 147 253 $(QUIET)$(MAKE) --no-print-directory run_fail_compilation_tests 148 254 149 255 $(RESULTS_DIR)/d_do_test: d_do_test.d $(RESULTS_DIR)/.created 150 256 @echo "Building d_do_test tool" 151 257 $(QUIET)$(DMD) -m$(MODEL) -od$(RESULTS_DIR) -of$(RESULTS_DIR)$(DSEP)d_do_test d_do_test.d 152 258 259 $(RESULTS_DIR)/combinations: combinations.d $(RESULTS_DIR)/.created 260 @echo "Building combinations tool" 261 $(QUIET)$(DMD) -m$(MODEL) -od$(RESULTS_DIR) -of$(RESULTS_DIR)$(DSEP)combinations combinations.d 262 trunk/test/runnable/imports/argufile.d
r575 r815 1 1 // argufile.d ---------------------------------------------------- 2 2 3 3 public: 4 4 5 import core.vararg; 5 6 import std.stdio; 6 7 import std.format; 7 8 import std.utf; 8 9 9 10 dstring formatstring(TypeInfo[] arguments, void *argptr) 10 11 { 11 12 12 13 dstring message = null; 13 14 14 15 void putc(dchar c) 15 16 { 16 17 message ~= c; 17 18 } 18 19 19 20 20 21 std.format.doFormat(&putc, arguments, argptr); 21 22 22 23 23 24 return message; 24 25 } trunk/test/runnable/imports/inline2a.d
r574 r815 137 137 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 138 138 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 139 139 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 140 140 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 141 141 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 142 142 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 143 143 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919 144 144 ]; 145 145 146 146 /********************************************************************* 147 147 148 148 Binary-chop search on sorted data. 149 149 150 150 *********************************************************************/ 151 151 152 152 private static int bsearch (in short[] array, short match) 153 153 { 154 154 int l, u, m; 155 155 156 156 l = -1; 157 u = array.length;157 u = cast(int)array.length; 158 158 159 159 while (l+1 != u) 160 160 { 161 161 m = (l + u) / 2; 162 162 if (array[m] < match) 163 163 l = m; 164 164 else 165 165 u = m; 166 166 } 167 167 168 168 if (u >= array.length || array[u] != match) 169 169 return -u; 170 170 return u; 171 171 } 172 172 173 173 /********************************************************************** 174 174 175 175 return a prime number between 2 and 7919 (inclusive) that 176 176 is equal to or larger than the given 'target' number. 177 177 trunk/test/runnable/interface2.d
r666 r815 637 637 } 638 638 639 639 class Child19 : ICov19, IFoo19 { 640 640 Child19 covfunc() { 641 641 printf("in Child19.covfunc()\n"); 642 642 return this; 643 643 } 644 644 } 645 645 646 646 void test19() 647 647 { 648 648 Child19 c = new Child19(); 649 649 ICov19 icov = c; 650 650 651 651 IFoo19 ifoo = icov.covfunc(); 652 652 653 653 printf("c = %p\n", c); 654 654 printf("icov = %p\n", icov); 655 655 printf("ifoo = %p\n", ifoo); 656 656 657 assert(cast(void*)c + 8== cast(void*)icov);658 assert(cast(void*)c + 12== cast(void*)ifoo);657 assert(cast(void*)c + (2*(void*).sizeof) == cast(void*)icov); 658 assert(cast(void*)c + (3*(void*).sizeof) == cast(void*)ifoo); 659 659 660 660 string s = ifoo.classinfo.name; 661 661 printf("%.*s\n", s.length, s.ptr); 662 662 assert(s == "interface2.IFoo19"); 663 663 664 664 s = (cast(Object)ifoo).toString; 665 665 printf("%.*s\n", s.length, s.ptr); 666 666 assert(s == "interface2.Child19"); 667 667 } 668 668 669 669 /*******************************************************/ 670 670 671 671 interface Iface1 672 672 { 673 673 Iface2 func1(); 674 674 } 675 675 676 676 interface Iface2 677 677 { 678 678 Iface1 func2(); trunk/test/runnable/lazy.d
r574 r815 1 import core.vararg; 1 2 import std.stdio; 2 3 3 4 /*********************************************************/ 4 5 5 6 void ifthen(bool cond, lazy void dg) 6 7 { 7 8 if (cond) 8 9 dg(); 9 10 } 10 11 11 12 void ifthen(bool cond, lazy void dgthen, lazy void dgelse) 12 13 { 13 14 if (cond) 14 15 dgthen(); 15 16 else 16 17 dgelse(); 17 18 } 18 19 19 20 void dotimes(int i, lazy int dg) 20 21 { … … 82 83 { 83 84 dg(); 84 85 } 85 86 86 87 void test2() 87 88 { 88 89 fooa(cast(void)null); 89 90 } 90 91 91 92 /*********************************************************/ 92 93 93 94 void dotimes3(int count, lazy void exp) 94 95 { 95 96 for (int i = 0; i < count; i++) 96 97 exp; 97 98 } 98 99 99 100 void bar3(...) 100 101 { 101 102 assert(_arguments.length == 1); 102 assert( *cast(int *)_argptr== 14);103 assert(va_arg!int(_argptr) == 14); 103 104 } 104 105 105 106 void abc3(int* p) 106 107 { 107 108 writeln(*p); 108 109 assert(*p == 3); 109 110 } 110 111 111 112 void test3() 112 113 { 113 114 114 115 int x = 3; 115 116 dotimes3(10, abc3(&x)); 116 117 dotimes3(10, write(++x)); 117 118 writeln(); 118 119 dotimes3(1, bar3(++x)); 119 120 120 121 int[10] a = new int[10]; 121 122 a[0] = 1; 122 123 a[$ - 1] = 9; … … 152 153 /*********************************************************/ 153 154 154 155 bool nextis(void delegate() dgpositive = {}) 155 156 { 156 157 return true; 157 158 } 158 159 159 160 bool looping(lazy bool condition) 160 161 { 161 162 return true; 162 163 } 163 164 164 165 void test5() 165 166 { 166 167 looping(nextis({})); 167 168 looping(nextis({})); 168 169 } 169 170 170 171 /*********************************************************/ 171 172 172 alias void* va_list; 173 174 template va_arg(T) 175 { 176 T va_arg(ref va_list _argptr) 177 { 178 T arg = *cast(T*)_argptr; // original from Phobos 179 _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); 180 return arg; 181 } 182 } 183 184 185 void foo6(lazy int expr, ...){ 173 void foo6(lazy int expr, ...) 174 { 186 175 char[] tmp_msg = va_arg!(char[])(_argptr); 187 176 if (cast(int)(tmp_msg.ptr)=="food_for_thought".length) 188 177 assert(0, "length is in the pointer!"); 189 178 assert(tmp_msg=="food_for_thought"); 190 179 191 180 } 192 181 193 182 int bar6() { return 3; } 194 183 195 184 void test6() 196 185 { 197 186 foo6(bar6(),"food_for_thought"); 198 187 } 199 188 200 189 /*********************************************************/ 201 190 202 191 int main() 203 192 { 204 193 test1(); 205 194 test2(); trunk/test/runnable/opover2.d
r574 r815 1 1 2 2 // Test operator overloading 3 3 4 4 import std.c.stdio; 5 5 6 6 /**************************************/ 7 7 8 8 class A 9 9 { 10 10 string opUnary(string s)() 11 11 { 12 printf("A.opUnary!(%.*s)\n", s );12 printf("A.opUnary!(%.*s)\n", s.length, s.ptr); 13 13 return s; 14 14 } 15 15 } 16 16 17 17 void test1() 18 18 { 19 19 auto a = new A(); 20 20 21 21 +a; 22 22 -a; 23 23 ~a; 24 24 *a; 25 25 ++a; 26 26 --a; 27 27 28 28 auto x = a++; 29 29 assert(x == a); 30 30 auto y = a--; 31 31 assert(y == a); 32 32 } 33 33 34 34 /**************************************/ 35 35 36 36 class A2 37 37 { 38 38 T opCast(T)() 39 39 { 40 printf("A.opCast!(%.*s)\n", T.stringof); 40 auto s = T.stringof; 41 printf("A.opCast!(%.*s)\n", s.length, s.ptr); 41 42 return T.init; 42 43 } 43 44 } 44 45 45 46 46 47 void test2() 47 48 { 48 49 auto a = new A2(); 49 50 50 51 auto x = cast(int)a; 51 52 assert(x == 0); 52 53 53 54 typedef int myint = 7; 54 55 auto y = cast(myint)a; 55 56 assert(y == 7); 56 57 } 57 58 58 59 /**************************************/ 59 60 60 61 struct A3 61 62 { 62 63 int opBinary(string s)(int i) 63 64 { 64 printf("A.opBinary!(%.*s)\n", s );65 printf("A.opBinary!(%.*s)\n", s.length, s.ptr); 65 66 return 0; 66 67 } 67 68 68 69 int opBinaryRight(string s)(int i) if (s == "/" || s == "*") 69 70 { 70 printf("A.opBinaryRight!(%.*s)\n", s );71 printf("A.opBinaryRight!(%.*s)\n", s.length, s.ptr); 71 72 return 0; 72 73 } 73 74 74 75 T opCast(T)() 75 76 { 76 printf("A.opCast!(%.*s)\n", T.stringof); 77 auto s = T.stringof; 78 printf("A.opCast!(%.*s)\n", s.length, s.ptr); 77 79 return T.init; 78 80 } 79 81 } 80 82 81 83 82 84 void test3() 83 85 { 84 86 A3 a; 85 87 86 88 a + 3; 87 89 4 * a; 88 90 4 / a; 89 91 a & 5; 90 92 } 91 93 92 94 /**************************************/ 93 95 94 96 struct A4 95 97 { 96 98 int opUnary(string s)() 97 99 { 98 printf("A.opUnary!(%.*s)\n", s );100 printf("A.opUnary!(%.*s)\n", s.length, s.ptr); 99 101 return 0; 100 102 } 101 103 102 104 T opCast(T)() 103 105 { 104 printf("A.opCast!(%.*s)\n", T.stringof); 106 auto s = T.stringof; 107 printf("A.opCast!(%.*s)\n", s.length, s.ptr); 105 108 return T.init; 106 109 } 107 110 } 108 111 109 112 110 113 void test4() 111 114 { 112 115 A4 a; 113 116 114 117 if (a) 115 118 int x = 3; 116 119 if (!a) 117 120 int x = 3; 118 121 if (!!a) 119 122 int x = 3; 120 123 } 121 124 122 125 /**************************************/ 123 126 124 127 class A5 125 128 { 126 129 bool opEquals(Object o) 127 130 { 128 131 printf("A.opEquals!(%p)\n", o); 129 132 return 1; 130 133 } 131 134 132 135 int opUnary(string s)() 133 136 { 134 printf("A.opUnary!(%.*s)\n", s );137 printf("A.opUnary!(%.*s)\n", s.length, s.ptr); 135 138 return 0; 136 139 } 137 140 138 141 T opCast(T)() 139 142 { 140 printf("A.opCast!(%.*s)\n", T.stringof); 143 auto s = T.stringof; 144 printf("A.opCast!(%.*s)\n", s.length, s.ptr); 141 145 return T.init; 142 146 } 143 147 } 144 148 145 149 class B5 : A5 146 150 { 147 151 bool opEquals(Object o) 148 152 { 149 153 printf("B.opEquals!(%p)\n", o); 150 154 return 1; 151 155 } 152 156 } 153 157 154 158 155 159 void test5() 156 160 { 157 161 A5 a = new A5(); 158 162 A5 a2 = new A5(); 159 163 B5 b = new B5(); 160 164 A n = null; … … 264 268 S7 s2; 265 269 266 270 if (s1 < s2) 267 271 int x = 3; 268 272 269 273 T7 t; 270 274 271 275 if (s1 < t) 272 276 int x = 3; 273 277 274 278 if (t < s2) 275 279 int x = 3; 276 280 } 277 281 278 282 /**************************************/ 279 283 280 284 struct A8 281 285 { 282 286 int opUnary(string s)() 283 287 { 284 printf("A.opUnary!(%.*s)\n", s );288 printf("A.opUnary!(%.*s)\n", s.length, s.ptr); 285 289 return 0; 286 290 } 287 291 288 292 int opIndexUnary(string s, T)(T i) 289 293 { 290 printf("A.opIndexUnary!(%.*s)(%d)\n", s , i);294 printf("A.opIndexUnary!(%.*s)(%d)\n", s.length, s.ptr, i); 291 295 return 0; 292 296 } 293 297 294 298 int opIndexUnary(string s, T)(T i, T j) 295 299 { 296 printf("A.opIndexUnary!(%.*s)(%d, %d)\n", s , i, j);300 printf("A.opIndexUnary!(%.*s)(%d, %d)\n", s.length, s.ptr, i, j); 297 301 return 0; 298 302 } 299 303 300 304 int opSliceUnary(string s)() 301 305 { 302 printf("A.opSliceUnary!(%.*s)()\n", s );306 printf("A.opSliceUnary!(%.*s)()\n", s.length, s.ptr); 303 307 return 0; 304 308 } 305 309 306 310 int opSliceUnary(string s, T)(T i, T j) 307 311 { 308 printf("A.opSliceUnary!(%.*s)(%d, %d)\n", s , i, j);312 printf("A.opSliceUnary!(%.*s)(%d, %d)\n", s.length, s.ptr, i, j); 309 313 return 0; 310 314 } 311 315 } 312 316 313 317 314 318 void test8() 315 319 { 316 320 A8 a; 317 321 318 322 -a; 319 323 -a[3]; 320 324 -a[3, 4]; 321 325 -a[]; 322 326 -a[5 .. 6]; 323 327 --a[3]; 324 328 } 325 329 326 330 /**************************************/ 327 331 328 332 struct A9 329 333 { 330 334 int opOpAssign(string s)(int i) 331 335 { 332 printf("A.opOpAssign!(%.*s)\n", s );336 printf("A.opOpAssign!(%.*s)\n", s.length, s.ptr); 333 337 return 0; 334 338 } 335 339 336 340 int opIndexOpAssign(string s, T)(int v, T i) 337 341 { 338 printf("A.opIndexOpAssign!(%.*s)(%d, %d)\n", s , v, i);342 printf("A.opIndexOpAssign!(%.*s)(%d, %d)\n", s.length, s.ptr, v, i); 339 343 return 0; 340 344 } 341 345 342 346 int opIndexOpAssign(string s, T)(int v, T i, T j) 343 347 { 344 printf("A.opIndexOpAssign!(%.*s)(%d, %d, %d)\n", s , v, i, j);348 printf("A.opIndexOpAssign!(%.*s)(%d, %d, %d)\n", s.length, s.ptr, v, i, j); 345 349 return 0; 346 350 } 347 351 348 352 int opSliceOpAssign(string s)(int v) 349 353 { 350 printf("A.opSliceOpAssign!(%.*s)(%d)\n", s , v);354 printf("A.opSliceOpAssign!(%.*s)(%d)\n", s.length, s.ptr, v); 351 355 return 0; 352 356 } 353 357 354 358 int opSliceOpAssign(string s, T)(int v, T i, T j) 355 359 { 356 printf("A.opSliceOpAssign!(%.*s)(%d, %d, %d)\n", s , v, i, j);360 printf("A.opSliceOpAssign!(%.*s)(%d, %d, %d)\n", s.length, s.ptr, v, i, j); 357 361 return 0; 358 362 } 359 363 } 360 364 361 365 362 366 void test9() 363 367 { 364 368 A9 a; 365 369 366 370 a += 8; 367 371 a -= 8; 368 372 a *= 8; 369 373 a /= 8; 370 374 a %= 8; 371 375 a &= 8; 372 376 a |= 8; 373 377 a ^= 8; 374 378 a <<= 8; 375 379 a >>= 8; 376 380 a >>>= 8; trunk/test/runnable/sdtor.d
r653 r815 1 1 2 import core.vararg; 2 3 import std.c.stdio; 3 4 4 5 int sdtor; 5 6 6 7 struct S 7 8 { 8 9 ~this() { printf("~S()\n"); sdtor++; } 9 10 } 10 11 11 12 /**********************************/ 12 13 13 14 void test1() 14 15 { 15 16 S* s = new S(); 16 17 delete s; 17 18 assert(sdtor == 1); 18 19 } 19 20 20 21 /**********************************/ 21 22 trunk/test/runnable/test15.d
r749 r815 1 1 // REQUIRED_ARGS: -d 2 2 3 3 import core.stdc.math; 4 import core.vararg; 4 5 import std.math: rndtol; 5 6 import std.stream: File; 6 7 import std.string; 7 8 8 9 extern (C) 9 10 { 10 11 int printf(const char*, ...); 11 12 } 12 13 13 14 void test1() 14 15 { 15 16 int i; 16 17 bool[] b = new bool[10]; 17 18 for (i = 0; i < 10; i++) 18 19 assert(b[i] == false); 19 20 20 21 typedef bool tbit = true; 21 22 tbit[] tb = new tbit[63]; 22 23 for (i = 0; i < 63; i++) 23 24 assert(tb[i] == true); … … 86 87 87 88 void test6() 88 89 { 89 90 assert('\x12'.sizeof == 1); 90 91 assert('\u1234'.sizeof == 2); 91 92 assert('\U00105678'.sizeof == 4); 92 93 93 94 assert('\x12' == 0x12); 94 95 assert('\u1234' == 0x1234); 95 96 assert('\U00105678' == 0x105678); 96 97 97 98 assert("abc\\def" == r"abc\def"); 98 99 } 99 100 100 101 101 102 /************************************/ 102 103 103 104 void test7() 104 105 { 105 106 string s = `hello"there'you`; 106 printf("s = '%.*s'\n", s );107 printf("s = '%.*s'\n", s.length, s.ptr); 107 108 assert(s == "hello\"there'you"); 108 109 ubyte[] b = cast(ubyte[])x"8B 7D f4 0d"; 109 110 for (int i = 0; i < b.length; i++) 110 111 printf("b[%d] = x%02x\n", i, b[i]); 111 112 assert(b.length == 4); 112 113 assert(b[0] == 0x8B); 113 114 assert(b[1] == 0x7D); 114 115 assert(b[2] == 0xF4); 115 116 assert(b[3] == 0x0D); 116 117 } 117 118 118 119 119 120 /************************************/ 120 121 121 122 122 123 void foo8(out bool b) 123 124 { 124 125 b = true; 125 126 } 126 127 … … 319 320 List2.rehash; 320 321 } 321 322 private: 322 323 int delegate(in int arg1) List1[char[]]; 323 324 int List2[char []]; 324 325 } 325 326 326 327 void test15() 327 328 { 328 329 } 329 330 330 331 331 332 /************************************/ 332 333 333 334 void test16() 334 335 { 335 336 char[] a=new char[0]; 336 337 uint c = 200000; 337 338 while (c--) 338 339 a ~= 'x'; 339 //printf("a = '%.*s'\n", a );340 //printf("a = '%.*s'\n", a.length, a.ptr); 340 341 } 341 342 342 343 343 344 /************************************/ 344 345 345 346 class A17 { } 346 347 class B17 : A17 { } 347 348 348 349 void foo17(A17[] a) { } 349 350 350 351 void test17() 351 352 { 352 353 B17[] b; 353 354 foo17(b); 354 355 } 355 356 356 357 357 358 /************************************/ 358 359 359 360 void test18() … … 467 468 468 469 void test25() 469 470 { 470 471 new subbar25(); 471 472 } 472 473 473 474 474 475 /************************************/ 475 476 476 477 void test26() 477 478 { 478 479 string[] instructions = std.string.split("a;b;c", ";"); 479 480 480 481 foreach(ref string instr; instructions) 481 482 { 482 483 std.string.strip(instr); 483 484 } 484 485 485 486 foreach(string instr; instructions) 486 487 { 487 printf("%.*s\n", instr );488 printf("%.*s\n", instr.length, instr.ptr); 488 489 } 489 490 } 490 491 491 492 492 493 /************************************/ 493 494 494 495 void foo27(ClassInfo ci) { } 495 496 496 497 class A27 497 498 { 498 499 } 499 500 500 501 class B27 : A27 501 502 { 502 503 static this() 503 504 { 504 505 foo27(B27.classinfo); 505 506 foo27(A27.classinfo); 506 507 } 507 508 } 508 509 509 510 void test27() 510 511 { 511 512 } 512 513 513 514 514 515 /************************************/ 515 516 516 517 void foo28(ClassInfo ci) 517 518 { 518 printf("%.*s\n", ci.name );519 printf("%.*s\n", ci.name.length, ci.name.ptr); 519 520 520 521 static int i; 521 522 switch (i++) 522 523 { 523 524 case 0: 524 525 case 2: assert(ci.name == "test15.A28"); 525 526 break; 526 527 case 1: assert(ci.name == "test15.B28"); 527 528 break; 528 529 } 529 530 } 530 531 531 532 class A28 532 533 { 533 534 static this() { 534 535 foo28(A28.classinfo ); 535 536 } 536 537 } 537 538 538 539 class B28 : A28 … … 879 880 return a.foo; 880 881 } 881 882 882 883 void test43() 883 884 { 884 885 A43 a = new A43(); 885 886 assert(bar43(a) == 6); 886 887 } 887 888 888 889 889 890 /************************************/ 890 891 891 892 class C44 892 893 { 893 894 const char[][] arrArr=["foo"]; 894 895 } 895 896 896 897 void test44() 897 898 { 898 899 C44 c= new C44(); 899 printf("%.*s\n", c.arrArr[0] );900 printf("%.*s\n", c.arrArr[0].length, c.arrArr[0].ptr); 900 901 assert(c.arrArr[0] == "foo"); 901 902 } 902 903 903 904 904 905 /************************************/ 905 906 906 907 void test45() 907 908 { 908 909 void* p; 909 910 void[] data; 910 911 911 912 data = p[0 .. 5]; 912 913 } 913 914 914 915 /************************************/ 915 916 916 917 union A46 917 918 { 918 919 char c; 919 920 struct { short s; } … … 1141 1142 1142 1143 class Foo56 1143 1144 { 1144 1145 alias int baseType; 1145 1146 } 1146 1147 1147 1148 void test56() 1148 1149 { 1149 1150 Foo56 f = new Foo56; 1150 1151 1151 1152 f.baseType s = 10; 1152 1153 } 1153 1154 1154 1155 1155 1156 /************************************/ 1156 1157 1157 1158 void det(float mat[][]) 1158 1159 { 1159 1160 float newmat[][]; 1160 1161 1161 int i = newmat[0 .. (mat.length - 1)].length;1162 size_t i = newmat[0 .. (mat.length - 1)].length; 1162 1163 } 1163 1164 1164 1165 void test57() 1165 1166 { 1166 1167 } 1167 1168 1168 1169 1169 1170 /************************************/ 1170 1171 1171 1172 int foo58 (int a, int t) { return 2; } 1172 1173 1173 1174 class A58 1174 1175 { 1175 1176 int foo58 ( ) { return 3; } 1176 1177 alias .foo58 foo58; 1177 1178 } 1178 1179 1179 1180 void test58() 1180 1181 { int y, x; 1181 1182 … … 1218 1219 void test60() 1219 1220 { 1220 1221 Foo60 f = new Foo60(); 1221 1222 1222 1223 assert(f.x == 3); 1223 1224 } 1224 1225 1225 1226 1226 1227 /************************************/ 1227 1228 1228 1229 class StdString 1229 1230 { 1230 1231 alias std.string.toString toString; 1231 1232 } 1232 1233 1233 1234 void test61() 1234 1235 { 1235 1236 int i = 123; 1236 1237 StdString g = new StdString(); 1237 1238 string s = g.toString(i); 1238 printf("%.*s\n", s );1239 printf("%.*s\n", s.length, s.ptr); 1239 1240 assert(s == "123"); 1240 1241 } 1241 1242 1242 1243 1243 1244 /************************************/ 1244 1245 1245 1246 void test62() 1246 1247 { char[4] a; 1247 1248 1248 1249 assert(a[0] == 0xFF); 1249 1250 assert(a[1] == 0xFF); 1250 1251 assert(a[2] == 0xFF); 1251 1252 assert(a[3] == 0xFF); 1252 1253 } 1253 1254 1254 1255 1255 1256 /************************************/ 1256 1257 1257 1258 void test63() 1258 1259 { trunk/test/runnable/test20.d
r666 r815 1 import core.vararg; 1 2 2 3 extern(C) int printf(const char*, ...); 3 4 4 5 /*****************************************/ 5 6 6 7 class A1 7 8 { 8 9 union 9 10 { 10 11 struct 11 12 { 12 13 int x; 13 14 public int y; 14 15 } 15 16 protected int z; 16 17 } 17 18 } 18 19 19 20 class A2 20 21 { … … 368 369 369 370 void abc17(ref ubyte[16] bar) 370 371 { 371 372 printf("bar = %p\n", bar.ptr); 372 373 assert(bar.ptr == ptr17); 373 374 } 374 375 375 376 /*****************************************/ 376 377 377 378 struct Iterator18(T) 378 379 { 379 380 T* m_ptr; 380 381 381 382 const bool opEquals(const ref Iterator18 iter) 382 383 { 383 384 return (m_ptr == iter.m_ptr); 384 385 } 385 386 386 387 const int opCmp(const ref Iterator18 iter) 387 388 { 388 return (m_ptr - iter.m_ptr);389 return cast(int)(m_ptr - iter.m_ptr); 389 390 } 390 391 } 391 392 392 393 void test18() 393 394 { 394 395 Iterator18!(int) iter; 395 396 } 396 397 397 398 /*****************************************/ 398 399 399 400 struct S29(T) 400 401 { 401 402 const bool opEquals(const ref S29!(T) len2) 402 403 { 403 404 return 0; 404 405 } 405 406 406 407 const int opCmp(const ref S29!(T) len2) 407 408 { 408 409 return 0; trunk/test/runnable/testdate.d
r575 r815 113 113 { "Wed, 2 Nov 1994 00:00:55 -0600 (CST)" , 783756055 }, 114 114 { "Sun, 6 Nov 1994 01:19:13 -0600 (CST)" , 784106353 }, 115 115 { "Mon, 7 Nov 1994 23:16:57 -0600 (CST)" , 784271817 }, 116 116 { "Tue, 08 Nov 1994 13:21:21 -0600" , 784322481 }, 117 117 { "Mon, 07 Nov 94 13:47:37 PST" , 784244857 }, 118 118 { "Tue, 08 Nov 94 11:23:19 PST" , 784322599 }, 119 119 { "Tue, 01 Nov 1994 11:28:25 -0800" , 783718105 }, 120 120 { "Tue, 15 Nov 1994 13:11:47 -0800" , 784933907 }, 121 121 { "Tue, 15 Nov 1994 13:18:38 -0800" , 784934318 }, 122 122 { "Tue, 15 Nov 1994 0:18:38 -0800" , 784887518 }, 123 123 ]; 124 124 125 125 void test1() 126 126 { 127 127 d_time d; 128 128 string s; 129 129 130 130 d = std.date.getUTCtime(); 131 131 printf("d = %lld\n", d); 132 132 s = std.date.toString(d); 133 printf("s = %.*s\n", s );133 printf("s = %.*s\n", s.length, s.ptr); 134 134 s = std.date.toDateString(d); 135 printf("s = %.*s\n", s );135 printf("s = %.*s\n", s.length, s.ptr); 136 136 s = std.date.toTimeString(d); 137 printf("s = %.*s\n\n", s );137 printf("s = %.*s\n\n", s.length, s.ptr); 138 138 139 139 version (OSX) 140 140 { 141 141 // don't do the test because the timezone on my Mac box is off 142 142 // by an hour for some reason 143 143 int i = 1; 144 144 } 145 145 else 146 146 int i = 0; 147 147 148 148 for (; i < testvectors.length; i++) 149 149 { 150 150 s = testvectors[i].str; 151 151 d = std.date.parse(s); 152 printf("%.*s = %lld, should be %lld\n", s , d, testvectors[i].value * ticksPerSecond);152 printf("%.*s = %lld, should be %lld\n", s.length, s.ptr, d, testvectors[i].value * ticksPerSecond); 153 153 154 154 s = std.date.toString(d); 155 printf("s = %.*s\n\n", s );155 printf("s = %.*s\n\n", s.length, s.ptr); 156 156 157 157 assert(d == testvectors[i].value * ticksPerSecond); 158 158 } 159 159 } 160 160 161 161 /**********************************************/ 162 162 163 163 void test2() 164 164 { 165 165 string fecha= toDateString(getUTCtime()); 166 printf("%.*s\n", fecha);166 printf("%.*s\n", fecha.length, fecha.ptr); 167 167 } 168 168 169 169 /**********************************************/ 170 170 171 171 void test3() 172 172 { 173 173 auto time = parse("Jan 1"); 174 174 assert(time == d_time_nan); 175 175 time = UTCtoLocalTime(time); // Line 11 176 176 assert(time == d_time_nan); 177 177 auto str = toUTCString(time); // Line 12 178 178 writefln(`"%s" = %s (%s)`, "Jan 1", time, str); 179 179 } 180 180 181 181 /**********************************************/ 182 182 183 183 int main() 184 184 { 185 185 test1(); 186 186 test2(); trunk/test/runnable/testdstress.d
r806 r815 1 1 // PERMUTE_ARGS: 2 2 3 3 module dstress.run.module_01; 4 4 5 5 import core.memory; 6 6 import core.exception; 7 import core.vararg; 7 8 8 9 extern(C) void* malloc(size_t size); 9 10 10 11 /* ================================ */ 11 12 12 13 struct MyStruct 13 14 { 14 15 int i; 15 16 } 16 17 17 18 void test1() 18 19 { 19 20 MyStruct inner() 20 21 in{ 21 22 assert(1); 22 23 }out (result){ 23 24 assert(result.i==1); 24 25 }body{ 25 26 MyStruct s; 26 27 s.i = 1; trunk/test/runnable/testtypeid.d
r575 r815 1 1 2 import core.vararg; 2 3 import std.stdio; 3 4 4 5 /******************************************************/ 5 6 6 7 class ABC { } 7 8 8 9 typedef ABC DEF; 9 10 10 11 TypeInfo foo() 11 12 { 12 13 ABC c; 13 14 14 15 return typeid(DEF); 15 16 } 16 17 17 18 void test1() 18 19 { 19 20 TypeInfo ti = foo(); 20 21 21 22 TypeInfo_Typedef td = cast(TypeInfo_Typedef)ti; 22 23 assert(td); 23 24 24 25 ti = td.base; 25 26 26 27 TypeInfo_Class tc = cast(TypeInfo_Class)ti; 27 28 assert(tc); 28 29 29 printf("%.*s\n", tc.info.name );30 printf("%.*s\n", tc.info.name.length, tc.info.name.ptr); 30 31 assert(tc.info.name == "testtypeid.ABC"); 31 32 } 32 33 33 34 /******************************************************/ 34 35 35 36 void test2() 36 37 { 37 38 assert(typeid(int) == typeid(int)); 38 39 assert(typeid(int) != typeid(uint)); 39 40 } 40 41 41 42 /******************************************************/ 42 43 43 44 class FOO3 { } 44 45 45 46 FOO3 foox3; 46 47 47 48 void foo3(int x, ...) 48 49 { 49 50 printf("%d arguments\n", _arguments.length); 50 51 for (int i = 0; i < _arguments.length; i++) 51 52 { writeln(_arguments[i].toString()); 52 53 53 54 if (_arguments[i] is typeid(int)) 54 55 { 55 int j = *cast(int *)_argptr; 56 _argptr += int.sizeof; 56 int j = va_arg!int(_argptr); 57 57 printf("\t%d\n", j); 58 58 assert(j == 2); 59 59 } 60 60 else if (_arguments[i] == typeid(long)) 61 61 { 62 long j = *cast(long *)_argptr; 63 _argptr += long.sizeof; 62 long j = va_arg!long(_argptr); 64 63 printf("\t%lld\n", j); 65 64 assert(j == 3); 66 65 } 67 66 else if (_arguments[i] is typeid(double)) 68 67 { 69 double d = *cast(double *)_argptr; 70 _argptr += double.sizeof; 68 double d = va_arg!double(_argptr); 71 69 printf("\t%g\n", d); 72 70 assert(d == 4.5); 73 71 } 74 72 else if (_arguments[i] is typeid(FOO3)) 75 73 { 76 FOO3 f = *cast(FOO3*)_argptr; 77 _argptr += FOO3.sizeof; 74 FOO3 f = va_arg!FOO3(_argptr); 78 75 printf("\t%p\n", f); 79 76 assert(f is foox3); 80 77 } 81 78 else 82 79 assert(0); 83 80 } 84 81 } 85 82 86 83 void test3() 87 84 { 88 85 FOO3 f = new FOO3(); 89 86 90 87 printf("\t%p\n", f); 91 88 foox3 = f; 92 89 93 90 foo3(1,2,3L,4.5,f); 94 91 foo3(1,2,3L,4.5,f); 95 92 } 96 93 97 94 /******************************************************/ … … 405 402 { 406 403 TypeInfo ti = typeid(void); 407 404 assert(!(ti is null)); 408 405 assert(ti.tsize == void.sizeof); 409 406 assert(ti.toString()=="void"); 410 407 } 411 408 412 409 /******************************************************/ 413 410 414 411 class Foo32 { int x = 3; } 415 412 class Bar32 { long y = 4; } 416 413 417 414 void printargs(int x, ...) 418 415 { 419 416 printf("%d arguments\n", _arguments.length); 420 417 for (int i = 0; i < _arguments.length; i++) 421 418 { writeln(_arguments[i].toString()); 422 419 423 420 if (_arguments[i] == typeid(int)) 424 421 { 425 int j = *cast(int *)_argptr; 426 _argptr += int.sizeof; 422 int j = va_arg!int(_argptr); 427 423 printf("\t%d\n", j); 428 424 } 429 425 else if (_arguments[i] == typeid(long)) 430 426 { 431 long j = *cast(long *)_argptr; 432 _argptr += long.sizeof; 427 long j = va_arg!long(_argptr); 433 428 printf("\t%lld\n", j); 434 429 } 435 430 else if (_arguments[i] == typeid(double)) 436 431 { 437 double d = *cast(double *)_argptr; 438 _argptr += double.sizeof; 432 double d = va_arg!double(_argptr); 439 433 printf("\t%g\n", d); 440 434 } 441 435 else if (_arguments[i] == typeid(Foo32)) 442 436 { 443 Foo32 f = *cast(Foo32*)_argptr;437 Foo32 f = va_arg!Foo32(_argptr); 444 438 assert(f.x == 3); 445 _argptr += Foo32.sizeof;446 439 printf("\t%p\n", f); 447 440 } 448 441 else if (_arguments[i] == typeid(Bar32)) 449 442 { 450 Bar32 b = *cast(Bar32*)_argptr;443 Bar32 b = va_arg!Bar32(_argptr); 451 444 assert(b.y == 4); 452 _argptr += Bar32.sizeof;453 445 printf("\t%p\n", b); 454 446 } 455 447 else 456 448 assert(0); 457 449 } 458 450 } 459 451 460 452 void test32() 461 453 { 462 454 Foo32 f = new Foo32(); 463 455 Bar32 b = new Bar32(); 464 456 465 457 printf("%p\n", f); 466 458 printargs(1, 2, 3L, 4.5, f, b); 467 459 } 468 460 469 461 /******************************************************/ 470 462 471 463 void test33() 472 464 {
