1 2 import core.stdc.stdio; 3 4 /**************************************************/ 5 test1()6void test1() 7 { 8 uint[char[]] a; 9 int i; 10 11 a["hello"] = 73; 12 a["world"] = 82; 13 14 foreach (uint u; a) 15 { 16 i++; 17 u++; 18 } 19 assert(i == 2); 20 assert(a["hello"] == 73); 21 assert(a["world"] == 82); 22 } 23 24 /**************************************************/ 25 test2()26void test2() 27 { 28 uint[char[]] a; 29 int i; 30 31 a["hello"] = 73; 32 a["world"] = 82; 33 34 foreach (ref uint u; a) 35 { 36 i++; 37 u++; 38 } 39 assert(i == 2); 40 assert(a["hello"] == 74); 41 assert(a["world"] == 83); 42 } 43 44 /**************************************************/ 45 test3()46void test3() 47 { 48 uint[char[]] a; 49 int i; 50 51 a["hello"] = 73; 52 a["world"] = 82; 53 54 foreach (ref uint u; a) 55 { 56 i++; 57 if (i) 58 break; 59 u++; 60 } 61 assert(i == 1); 62 assert(a["hello"] == 73); 63 assert(a["world"] == 82); 64 } 65 66 /**************************************************/ 67 test4()68void test4() 69 { 70 uint[char[]] a; 71 int i; 72 73 a["hello"] = 73; 74 a["world"] = 82; 75 76 foreach (ref uint u; a) 77 { 78 i++; 79 if (i == 1) 80 continue; 81 u++; 82 } 83 assert(i == 2); 84 assert((a["hello"] == 73 && a["world"] == 83) || 85 (a["hello"] == 74 && a["world"] == 82)); 86 } 87 88 /**************************************************/ 89 test5()90void test5() 91 { 92 uint[char[]] a; 93 int i; 94 95 a["hello"] = 73; 96 a["world"] = 82; 97 98 Loop: 99 while (1) 100 { 101 foreach (ref uint u; a) 102 { 103 i++; 104 if (i) 105 break Loop; 106 u++; 107 } 108 } 109 assert(i == 1); 110 assert(a["hello"] == 73); 111 assert(a["world"] == 82); 112 } 113 114 /**************************************************/ 115 test6()116void test6() 117 { 118 uint[char[]] a; 119 int i; 120 121 a["hello"] = 73; 122 a["world"] = 82; 123 124 Loop: 125 while (1) 126 { 127 foreach (ref uint u; a) 128 { 129 i++; 130 if (i == 1) 131 continue Loop; 132 u++; 133 } 134 break; 135 } 136 assert(i == 3); 137 assert(a["hello"] == 74); 138 assert(a["world"] == 83); 139 } 140 141 /**************************************************/ 142 test7()143void test7() 144 { 145 uint[char[]] a; 146 int i; 147 148 a["hello"] = 73; 149 a["world"] = 82; 150 151 foreach (ref uint u; a) 152 { 153 i++; 154 if (i) 155 goto Label; 156 u++; 157 } 158 assert(0); 159 Label: 160 assert(i == 1); 161 assert(a["hello"] == 73); 162 assert(a["world"] == 82); 163 } 164 165 /**************************************************/ 166 test8_x(uint[char[]]a)167void test8_x(uint[char[]] a) 168 { 169 int i; 170 foreach (ref uint u; a) 171 { 172 i++; 173 if (i) 174 return; 175 u++; 176 } 177 } 178 test8()179void test8() 180 { 181 uint[char[]] a; 182 int i; 183 184 a["hello"] = 73; 185 a["world"] = 82; 186 187 test8_x(a); 188 assert(i == 0); 189 assert(a["hello"] == 73); 190 assert(a["world"] == 82); 191 } 192 193 /**************************************************/ 194 test9_x(uint[char[]]a)195int test9_x(uint[char[]] a) 196 { 197 int i; 198 foreach (ref uint u; a) 199 { 200 i++; 201 if (i) 202 return 67; 203 u++; 204 } 205 return 23; 206 } 207 test9()208void test9() 209 { 210 uint[char[]] a; 211 int i; 212 213 a["hello"] = 73; 214 a["world"] = 82; 215 216 i = test9_x(a); 217 assert(i == 67); 218 assert(a["hello"] == 73); 219 assert(a["world"] == 82); 220 } 221 222 /**************************************************/ 223 test10_x(uint[char[]]a)224int test10_x(uint[char[]] a) 225 { 226 int i; 227 foreach (ref uint u; a) 228 { 229 i++; 230 if (i) 231 return i; 232 u++; 233 } 234 return 23; 235 } 236 test10()237void test10() 238 { 239 uint[char[]] a; 240 int i; 241 242 a["hello"] = 73; 243 a["world"] = 82; 244 245 i = test10_x(a); 246 assert(i == 1); 247 assert(a["hello"] == 73); 248 assert(a["world"] == 82); 249 } 250 251 /**************************************************/ 252 main()253int main() 254 { 255 test1(); 256 test2(); 257 test3(); 258 test4(); 259 test5(); 260 test6(); 261 test7(); 262 test8(); 263 test9(); 264 test10(); 265 266 printf("Success\n"); 267 return 0; 268 } 269