| ... | @@ -1,12 +1,6 @@ | ... | @@ -1,12 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | // TODO not passing |
| 2 | const assert = std.debug.assert; | | |
| 3 | const str = std.str; | | |
| 4 | const cstr = std.cstr; | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | fn genericFnWithImplicitCast() { | 2 | fn genericFnWithImplicitCast() { |
| 9 | @setFnTest(this, true); | 3 | @setFnTest(this); |
| 10 | | 4 | |
| 11 | assert(getFirstByte(u8, []u8 {13}) == 13); | 5 | assert(getFirstByte(u8, []u8 {13}) == 13); |
| 12 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); | 6 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); |
| ... | @@ -16,42 +10,10 @@ fn getFirstByte(inline T: type, mem: []T) -> u8 { | ... | @@ -16,42 +10,10 @@ fn getFirstByte(inline T: type, mem: []T) -> u8 { |
| 16 | getByte((&u8)(&mem[0])) | 10 | getByte((&u8)(&mem[0])) |
| 17 | } | 11 | } |
| 18 | | 12 | |
| 19 | fn pointerDereferencing() { | | |
| 20 | @setFnTest(this, true); | | |
| 21 | | | |
| 22 | var x = i32(3); | | |
| 23 | const y = &x; | | |
| 24 | | | |
| 25 | *y += 1; | | |
| 26 | | | |
| 27 | assert(x == 4); | | |
| 28 | assert(*y == 4); | | |
| 29 | } | | |
| 30 | | | |
| 31 | fn constantExpressions() { | | |
| 32 | @setFnTest(this, true); | | |
| 33 | | | |
| 34 | var array : [array_size]u8 = undefined; | | |
| 35 | assert(@sizeOf(@typeOf(array)) == 20); | | |
| 36 | } | | |
| 37 | const array_size : u8 = 20; | | |
| 38 | | | |
| 39 | | | |
| 40 | fn nestedArrays() { | | |
| 41 | @setFnTest(this, true); | | |
| 42 | | | |
| 43 | const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"}; | | |
| 44 | for (array_of_strings) |s, i| { | | |
| 45 | if (i == 0) assert(str.eql(s, "hello")); | | |
| 46 | if (i == 1) assert(str.eql(s, "this")); | | |
| 47 | if (i == 2) assert(str.eql(s, "is")); | | |
| 48 | if (i == 3) assert(str.eql(s, "my")); | | |
| 49 | if (i == 4) assert(str.eql(s, "thing")); | | |
| 50 | } | | |
| 51 | } | | |
| 52 | | 13 | |
| | 14 | // TODO not passing |
| 53 | fn intToPtrCast() { | 15 | fn intToPtrCast() { |
| 54 | @setFnTest(this, true); | 16 | @setFnTest(this); |
| 55 | | 17 | |
| 56 | const x = isize(13); | 18 | const x = isize(13); |
| 57 | const y = (&u8)(x); | 19 | const y = (&u8)(x); |
| ... | @@ -59,81 +21,9 @@ fn intToPtrCast() { | ... | @@ -59,81 +21,9 @@ fn intToPtrCast() { |
| 59 | assert(z == 13); | 21 | assert(z == 13); |
| 60 | } | 22 | } |
| 61 | | 23 | |
| 62 | fn constantStructWithNegation() { | 24 | // TODO not passing |
| 63 | @setFnTest(this, true); | | |
| 64 | | | |
| 65 | assert(vertices[0].x == -0.6); | | |
| 66 | } | | |
| 67 | struct Vertex { | | |
| 68 | x: f32, | | |
| 69 | y: f32, | | |
| 70 | r: f32, | | |
| 71 | g: f32, | | |
| 72 | b: f32, | | |
| 73 | } | | |
| 74 | const vertices = []Vertex { | | |
| 75 | Vertex { .x = -0.6, .y = -0.4, .r = 1.0, .g = 0.0, .b = 0.0 }, | | |
| 76 | Vertex { .x = 0.6, .y = -0.4, .r = 0.0, .g = 1.0, .b = 0.0 }, | | |
| 77 | Vertex { .x = 0.0, .y = 0.6, .r = 0.0, .g = 0.0, .b = 1.0 }, | | |
| 78 | }; | | |
| 79 | | | |
| 80 | | | |
| 81 | fn returnStructByvalFromFunction() { | | |
| 82 | @setFnTest(this, true); | | |
| 83 | | | |
| 84 | const bar = makeBar(1234, 5678); | | |
| 85 | assert(bar.y == 5678); | | |
| 86 | } | | |
| 87 | struct Bar { | | |
| 88 | x: i32, | | |
| 89 | y: i32, | | |
| 90 | } | | |
| 91 | fn makeBar(x: i32, y: i32) -> Bar { | | |
| 92 | Bar { | | |
| 93 | .x = x, | | |
| 94 | .y = y, | | |
| 95 | } | | |
| 96 | } | | |
| 97 | | | |
| 98 | fn functionPointers() { | | |
| 99 | @setFnTest(this, true); | | |
| 100 | | | |
| 101 | const fns = []@typeOf(fn1) { fn1, fn2, fn3, fn4, }; | | |
| 102 | for (fns) |f, i| { | | |
| 103 | assert(f() == u32(i) + 5); | | |
| 104 | } | | |
| 105 | } | | |
| 106 | fn fn1() -> u32 {5} | | |
| 107 | fn fn2() -> u32 {6} | | |
| 108 | fn fn3() -> u32 {7} | | |
| 109 | fn fn4() -> u32 {8} | | |
| 110 | | | |
| 111 | | | |
| 112 | | | |
| 113 | fn staticallyInitalizedStruct() { | | |
| 114 | @setFnTest(this, true); | | |
| 115 | | | |
| 116 | st_init_str_foo.x += 1; | | |
| 117 | assert(st_init_str_foo.x == 14); | | |
| 118 | } | | |
| 119 | struct StInitStrFoo { | | |
| 120 | x: i32, | | |
| 121 | y: bool, | | |
| 122 | } | | |
| 123 | var st_init_str_foo = StInitStrFoo { .x = 13, .y = true, }; | | |
| 124 | | | |
| 125 | fn staticallyInitializedArrayLiteral() { | | |
| 126 | @setFnTest(this, true); | | |
| 127 | | | |
| 128 | const y : [4]u8 = st_init_arr_lit_x; | | |
| 129 | assert(y[3] == 4); | | |
| 130 | } | | |
| 131 | const st_init_arr_lit_x = []u8{1,2,3,4}; | | |
| 132 | | | |
| 133 | | | |
| 134 | | | |
| 135 | fn pointerToVoidReturnType() { | 25 | fn pointerToVoidReturnType() { |
| 136 | @setFnTest(this, true); | 26 | @setFnTest(this); |
| 137 | | 27 | |
| 138 | %%testPointerToVoidReturnType(); | 28 | %%testPointerToVoidReturnType(); |
| 139 | } | 29 | } |
| ... | @@ -142,129 +32,14 @@ fn testPointerToVoidReturnType() -> %void { | ... | @@ -142,129 +32,14 @@ fn testPointerToVoidReturnType() -> %void { |
| 142 | return *a; | 32 | return *a; |
| 143 | } | 33 | } |
| 144 | const test_pointer_to_void_return_type_x = void{}; | 34 | const test_pointer_to_void_return_type_x = void{}; |
| 145 | fn testPointerToVoidReturnType2() -> &void { | 35 | fn testPointerToVoidReturnType2() -> &const void { |
| 146 | return &test_pointer_to_void_return_type_x; | 36 | return &test_pointer_to_void_return_type_x; |
| 147 | } | 37 | } |
| 148 | | 38 | |
| 149 | | 39 | |
| 150 | fn callResultOfIfElseExpression() { | 40 | // TODO not passing (goes in struct.zig) |
| 151 | @setFnTest(this, true); | | |
| 152 | | | |
| 153 | assert(str.eql(f2(true), "a")); | | |
| 154 | assert(str.eql(f2(false), "b")); | | |
| 155 | } | | |
| 156 | fn f2(x: bool) -> []u8 { | | |
| 157 | return (if (x) fA else fB)(); | | |
| 158 | } | | |
| 159 | fn fA() -> []u8 { "a" } | | |
| 160 | fn fB() -> []u8 { "b" } | | |
| 161 | | | |
| 162 | | | |
| 163 | fn constExpressionEvalHandlingOfVariables() { | | |
| 164 | @setFnTest(this, true); | | |
| 165 | | | |
| 166 | var x = true; | | |
| 167 | while (x) { | | |
| 168 | x = false; | | |
| 169 | } | | |
| 170 | } | | |
| 171 | | | |
| 172 | | | |
| 173 | | | |
| 174 | fn constantEnumInitializationWithDifferingSizes() { | | |
| 175 | @setFnTest(this, true); | | |
| 176 | | | |
| 177 | test3_1(test3_foo); | | |
| 178 | test3_2(test3_bar); | | |
| 179 | } | | |
| 180 | enum Test3Foo { | | |
| 181 | One, | | |
| 182 | Two: f32, | | |
| 183 | Three: Test3Point, | | |
| 184 | } | | |
| 185 | struct Test3Point { | | |
| 186 | x: i32, | | |
| 187 | y: i32, | | |
| 188 | } | | |
| 189 | const test3_foo = Test3Foo.Three{Test3Point {.x = 3, .y = 4}}; | | |
| 190 | const test3_bar = Test3Foo.Two{13}; | | |
| 191 | fn test3_1(f: Test3Foo) { | | |
| 192 | @setFnStaticEval(this, false); | | |
| 193 | | | |
| 194 | switch (f) { | | |
| 195 | Three => |pt| { | | |
| 196 | assert(pt.x == 3); | | |
| 197 | assert(pt.y == 4); | | |
| 198 | }, | | |
| 199 | else => @unreachable(), | | |
| 200 | } | | |
| 201 | } | | |
| 202 | fn test3_2(f: Test3Foo) { | | |
| 203 | @setFnStaticEval(this, false); | | |
| 204 | | | |
| 205 | switch (f) { | | |
| 206 | Two => |x| { | | |
| 207 | assert(x == 13); | | |
| 208 | }, | | |
| 209 | else => @unreachable(), | | |
| 210 | } | | |
| 211 | } | | |
| 212 | | | |
| 213 | | | |
| 214 | | | |
| 215 | fn forLoopWithPointerElemVar() { | | |
| 216 | @setFnTest(this, true); | | |
| 217 | | | |
| 218 | const source = "abcdefg"; | | |
| 219 | var target: [source.len]u8 = undefined; | | |
| 220 | @memcpy(&target[0], &source[0], source.len); | | |
| 221 | mangleString(target); | | |
| 222 | assert(str.eql(target, "bcdefgh")); | | |
| 223 | } | | |
| 224 | fn mangleString(s: []u8) { | | |
| 225 | @setFnStaticEval(this, false); | | |
| 226 | | | |
| 227 | for (s) |*c| { | | |
| 228 | *c += 1; | | |
| 229 | } | | |
| 230 | } | | |
| 231 | | | |
| 232 | fn emptyStructMethodCall() { | | |
| 233 | @setFnTest(this, true); | | |
| 234 | | | |
| 235 | const es = EmptyStruct{}; | | |
| 236 | assert(es.method() == 1234); | | |
| 237 | } | | |
| 238 | struct EmptyStruct { | | |
| 239 | fn method(es: EmptyStruct) -> i32 { | | |
| 240 | @setFnStaticEval(this, false); | | |
| 241 | 1234 | | |
| 242 | } | | |
| 243 | | | |
| 244 | } | | |
| 245 | | | |
| 246 | | | |
| 247 | | | |
| 248 | | | |
| 249 | | | |
| 250 | fn returnEmptyStructFromFn() { | | |
| 251 | @setFnTest(this, true); | | |
| 252 | | | |
| 253 | testReturnEmptyStructFromFn(); | | |
| 254 | testReturnEmptyStructFromFnNoeval(); | | |
| 255 | } | | |
| 256 | struct EmptyStruct2 {} | | |
| 257 | fn testReturnEmptyStructFromFn() -> EmptyStruct2 { | | |
| 258 | EmptyStruct2 {} | | |
| 259 | } | | |
| 260 | fn testReturnEmptyStructFromFnNoeval() -> EmptyStruct2 { | | |
| 261 | @setFnStaticEval(this, false); | | |
| 262 | | | |
| 263 | EmptyStruct2 {} | | |
| 264 | } | | |
| 265 | | | |
| 266 | fn passSliceOfEmptyStructToFn() { | 41 | fn passSliceOfEmptyStructToFn() { |
| 267 | @setFnTest(this, true); | 42 | @setFnTest(this); |
| 268 | | 43 | |
| 269 | assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1); | 44 | assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1); |
| 270 | } | 45 | } |
| ... | @@ -273,6 +48,7 @@ fn testPassSliceOfEmptyStructToFn(slice: []EmptyStruct2) -> usize { | ... | @@ -273,6 +48,7 @@ fn testPassSliceOfEmptyStructToFn(slice: []EmptyStruct2) -> usize { |
| 273 | } | 48 | } |
| 274 | | 49 | |
| 275 | | 50 | |
| | 51 | // TODO not passing |
| 276 | fn pointerComparison() { | 52 | fn pointerComparison() { |
| 277 | @setFnTest(this, true); | 53 | @setFnTest(this, true); |
| 278 | | 54 | |
| ... | @@ -284,31 +60,8 @@ fn ptrEql(a: &[]u8, b: &[]u8) -> bool { | ... | @@ -284,31 +60,8 @@ fn ptrEql(a: &[]u8, b: &[]u8) -> bool { |
| 284 | a == b | 60 | a == b |
| 285 | } | 61 | } |
| 286 | | 62 | |
| 287 | fn characterLiterals() { | 63 | // TODO change this test to an issue |
| 288 | @setFnTest(this, true); | 64 | // we're going to change how this works |
| 289 | | | |
| 290 | assert('\'' == single_quote); | | |
| 291 | } | | |
| 292 | const single_quote = '\''; | | |
| 293 | | | |
| 294 | | | |
| 295 | fn switchWithMultipleExpressions() { | | |
| 296 | @setFnTest(this, true); | | |
| 297 | | | |
| 298 | const x: i32 = switch (returnsFive()) { | | |
| 299 | 1, 2, 3 => 1, | | |
| 300 | 4, 5, 6 => 2, | | |
| 301 | else => 3, | | |
| 302 | }; | | |
| 303 | assert(x == 2); | | |
| 304 | } | | |
| 305 | fn returnsFive() -> i32 { | | |
| 306 | @setFnStaticEval(this, false); | | |
| 307 | 5 | | |
| 308 | } | | |
| 309 | | | |
| 310 | | | |
| 311 | | | |
| 312 | fn switchOnErrorUnion() { | 65 | fn switchOnErrorUnion() { |
| 313 | @setFnTest(this, true); | 66 | @setFnTest(this, true); |
| 314 | | 67 | |
| ... | @@ -327,133 +80,14 @@ fn returnsTen() -> %i32 { | ... | @@ -327,133 +80,14 @@ fn returnsTen() -> %i32 { |
| 327 | 10 | 80 | 10 |
| 328 | } | 81 | } |
| 329 | | 82 | |
| 330 | fn takeAddressOfParameter() { | 83 | // TODO not passing |
| 331 | @setFnTest(this, true); | | |
| 332 | | | |
| 333 | testTakeAddressOfParameter(12.34); | | |
| 334 | testTakeAddressOfParameterNoeval(12.34); | | |
| 335 | } | | |
| 336 | fn testTakeAddressOfParameter(f: f32) { | | |
| 337 | const f_ptr = &f; | | |
| 338 | assert(*f_ptr == 12.34); | | |
| 339 | } | | |
| 340 | fn testTakeAddressOfParameterNoeval(f: f32) { | | |
| 341 | @setFnStaticEval(this, false); | | |
| 342 | | | |
| 343 | const f_ptr = &f; | | |
| 344 | assert(*f_ptr == 12.34); | | |
| 345 | } | | |
| 346 | | | |
| 347 | | | |
| 348 | fn ifVarMaybePointer() { | | |
| 349 | @setFnTest(this, true); | | |
| 350 | | | |
| 351 | assert(shouldBeAPlus1(Particle {.a = 14, .b = 1, .c = 1, .d = 1}) == 15); | | |
| 352 | } | | |
| 353 | fn shouldBeAPlus1(p: Particle) -> u64 { | | |
| 354 | @setFnStaticEval(this, false); | | |
| 355 | | | |
| 356 | var maybe_particle: ?Particle = p; | | |
| 357 | if (const *particle ?= maybe_particle) { | | |
| 358 | particle.a += 1; | | |
| 359 | } | | |
| 360 | if (const particle ?= maybe_particle) { | | |
| 361 | return particle.a; | | |
| 362 | } | | |
| 363 | return 0; | | |
| 364 | } | | |
| 365 | struct Particle { | | |
| 366 | a: u64, | | |
| 367 | b: u64, | | |
| 368 | c: u64, | | |
| 369 | d: u64, | | |
| 370 | } | | |
| 371 | | | |
| 372 | fn unsignedWrapping() { | | |
| 373 | @setFnTest(this, true); | | |
| 374 | | | |
| 375 | testUnsignedWrappingEval(@maxValue(u32)); | | |
| 376 | testUnsignedWrappingNoeval(@maxValue(u32)); | | |
| 377 | } | | |
| 378 | fn testUnsignedWrappingEval(x: u32) { | | |
| 379 | const zero = x +% 1; | | |
| 380 | assert(zero == 0); | | |
| 381 | const orig = zero -% 1; | | |
| 382 | assert(orig == @maxValue(u32)); | | |
| 383 | } | | |
| 384 | fn testUnsignedWrappingNoeval(x: u32) { | | |
| 385 | @setFnStaticEval(this, false); | | |
| 386 | | | |
| 387 | const zero = x +% 1; | | |
| 388 | assert(zero == 0); | | |
| 389 | const orig = zero -% 1; | | |
| 390 | assert(orig == @maxValue(u32)); | | |
| 391 | } | | |
| 392 | | | |
| 393 | fn signedWrapping() { | | |
| 394 | @setFnTest(this, true); | | |
| 395 | | | |
| 396 | testSignedWrappingEval(@maxValue(i32)); | | |
| 397 | testSignedWrappingNoeval(@maxValue(i32)); | | |
| 398 | } | | |
| 399 | fn testSignedWrappingEval(x: i32) { | | |
| 400 | const min_val = x +% 1; | | |
| 401 | assert(min_val == @minValue(i32)); | | |
| 402 | const max_val = min_val -% 1; | | |
| 403 | assert(max_val == @maxValue(i32)); | | |
| 404 | } | | |
| 405 | fn testSignedWrappingNoeval(x: i32) { | | |
| 406 | @setFnStaticEval(this, false); | | |
| 407 | | | |
| 408 | const min_val = x +% 1; | | |
| 409 | assert(min_val == @minValue(i32)); | | |
| 410 | const max_val = min_val -% 1; | | |
| 411 | assert(max_val == @maxValue(i32)); | | |
| 412 | } | | |
| 413 | | | |
| 414 | fn negationWrapping() { | | |
| 415 | @setFnTest(this, true); | | |
| 416 | | | |
| 417 | testNegationWrappingEval(@minValue(i16)); | | |
| 418 | testNegationWrappingNoeval(@minValue(i16)); | | |
| 419 | } | | |
| 420 | fn testNegationWrappingEval(x: i16) { | | |
| 421 | assert(x == -32768); | | |
| 422 | const neg = -%x; | | |
| 423 | assert(neg == -32768); | | |
| 424 | } | | |
| 425 | fn testNegationWrappingNoeval(x: i16) { | | |
| 426 | @setFnStaticEval(this, false); | | |
| 427 | | | |
| 428 | assert(x == -32768); | | |
| 429 | const neg = -%x; | | |
| 430 | assert(neg == -32768); | | |
| 431 | } | | |
| 432 | | | |
| 433 | fn shlWrapping() { | | |
| 434 | @setFnTest(this, true); | | |
| 435 | | | |
| 436 | testShlWrappingEval(@maxValue(u16)); | | |
| 437 | testShlWrappingNoeval(@maxValue(u16)); | | |
| 438 | } | | |
| 439 | fn testShlWrappingEval(x: u16) { | | |
| 440 | const shifted = x <<% 1; | | |
| 441 | assert(shifted == 65534); | | |
| 442 | } | | |
| 443 | fn testShlWrappingNoeval(x: u16) { | | |
| 444 | @setFnStaticEval(this, false); | | |
| 445 | | | |
| 446 | const shifted = x <<% 1; | | |
| 447 | assert(shifted == 65534); | | |
| 448 | } | | |
| 449 | | | |
| 450 | fn cStringConcatenation() { | 84 | fn cStringConcatenation() { |
| 451 | @setFnTest(this, true); | 85 | @setFnTest(this, true); |
| 452 | | 86 | |
| 453 | const a = c"OK" ++ c" IT " ++ c"WORKED"; | 87 | const a = c"OK" ++ c" IT " ++ c"WORKED"; |
| 454 | const b = c"OK IT WORKED"; | 88 | const b = c"OK IT WORKED"; |
| 455 | | 89 | |
| 456 | const len = cstr.len(b); | 90 | const len = cstrlen(b); |
| 457 | const len_with_null = len + 1; | 91 | const len_with_null = len + 1; |
| 458 | {var i: u32 = 0; while (i < len_with_null; i += 1) { | 92 | {var i: u32 = 0; while (i < len_with_null; i += 1) { |
| 459 | assert(a[i] == b[i]); | 93 | assert(a[i] == b[i]); |
| ... | @@ -462,23 +96,9 @@ fn cStringConcatenation() { | ... | @@ -462,23 +96,9 @@ fn cStringConcatenation() { |
| 462 | assert(b[len] == 0); | 96 | assert(b[len] == 0); |
| 463 | } | 97 | } |
| 464 | | 98 | |
| 465 | fn genericStruct() { | 99 | // TODO not passing |
| 466 | @setFnTest(this, true); | | |
| 467 | | | |
| 468 | var a1 = GenNode(i32) {.value = 13, .next = null,}; | | |
| 469 | var b1 = GenNode(bool) {.value = true, .next = null,}; | | |
| 470 | assert(a1.value == 13); | | |
| 471 | assert(a1.value == a1.getVal()); | | |
| 472 | assert(b1.getVal()); | | |
| 473 | } | | |
| 474 | struct GenNode(T: type) { | | |
| 475 | value: T, | | |
| 476 | next: ?&GenNode(T), | | |
| 477 | fn getVal(n: &const GenNode(T)) -> T { n.value } | | |
| 478 | } | | |
| 479 | | | |
| 480 | fn castSliceToU8Slice() { | 100 | fn castSliceToU8Slice() { |
| 481 | @setFnTest(this, true); | 101 | @setFnTest(this); |
| 482 | | 102 | |
| 483 | assert(@sizeOf(i32) == 4); | 103 | assert(@sizeOf(i32) == 4); |
| 484 | var big_thing_array = []i32{1, 2, 3, 4}; | 104 | var big_thing_array = []i32{1, 2, 3, 4}; |
| ... | @@ -499,76 +119,19 @@ fn castSliceToU8Slice() { | ... | @@ -499,76 +119,19 @@ fn castSliceToU8Slice() { |
| 499 | assert(bytes[11] == @maxValue(u8)); | 119 | assert(bytes[11] == @maxValue(u8)); |
| 500 | } | 120 | } |
| 501 | | 121 | |
| 502 | fn nullLiteralOutsideFunction() { | 122 | // TODO not passing |
| 503 | @setFnTest(this, true); | | |
| 504 | | | |
| 505 | const is_null = if (const _ ?= here_is_a_null_literal.context) false else true; | | |
| 506 | assert(is_null); | | |
| 507 | } | | |
| 508 | struct SillyStruct { | | |
| 509 | context: ?i32, | | |
| 510 | } | | |
| 511 | const here_is_a_null_literal = SillyStruct { | | |
| 512 | .context = null, | | |
| 513 | }; | | |
| 514 | | | |
| 515 | fn constDeclsInStruct() { | | |
| 516 | @setFnTest(this, true); | | |
| 517 | | | |
| 518 | assert(GenericDataThing(3).count_plus_one == 4); | | |
| 519 | } | | |
| 520 | struct GenericDataThing(count: isize) { | | |
| 521 | const count_plus_one = count + 1; | | |
| 522 | } | | |
| 523 | | | |
| 524 | fn useGenericParamInGenericParam() { | | |
| 525 | @setFnTest(this, true); | | |
| 526 | | | |
| 527 | assert(aGenericFn(i32, 3, 4) == 7); | | |
| 528 | } | | |
| 529 | fn aGenericFn(inline T: type, inline a: T, b: T) -> T { | | |
| 530 | return a + b; | | |
| 531 | } | | |
| 532 | | | |
| 533 | | | |
| 534 | fn unsigned64BitDivision() { | | |
| 535 | @setFnTest(this, true); | | |
| 536 | | | |
| 537 | const result = div(1152921504606846976, 34359738365); | | |
| 538 | assert(result.quotient == 33554432); | | |
| 539 | assert(result.remainder == 100663296); | | |
| 540 | } | | |
| 541 | fn div(a: u64, b: u64) -> DivResult { | | |
| 542 | @setFnStaticEval(this, false); | | |
| 543 | | | |
| 544 | DivResult { | | |
| 545 | .quotient = a / b, | | |
| 546 | .remainder = a % b, | | |
| 547 | } | | |
| 548 | } | | |
| 549 | struct DivResult { | | |
| 550 | quotient: u64, | | |
| 551 | remainder: u64, | | |
| 552 | } | | |
| 553 | | | |
| 554 | fn intToEnum() { | 123 | fn intToEnum() { |
| 555 | @setFnTest(this, true); | 124 | @setFnTest(this); |
| 556 | | 125 | |
| 557 | testIntToEnumEval(3); | 126 | testIntToEnumEval(3); |
| 558 | testIntToEnumNoeval(3); | | |
| 559 | } | 127 | } |
| 560 | fn testIntToEnumEval(x: i32) { | 128 | fn testIntToEnumEval(x: i32) { |
| 561 | assert(IntToEnumNumber(x) == IntToEnumNumber.Three); | 129 | assert(IntToEnumNumber(x) == IntToEnumNumber.Three); |
| 562 | } | 130 | } |
| 563 | fn testIntToEnumNoeval(x: i32) { | 131 | const IntToEnumNumber = enum { |
| 564 | @setFnStaticEval(this, false); | | |
| 565 | | | |
| 566 | assert(IntToEnumNumber(x) == IntToEnumNumber.Three); | | |
| 567 | } | | |
| 568 | enum IntToEnumNumber { | | |
| 569 | Zero, | 132 | Zero, |
| 570 | One, | 133 | One, |
| 571 | Two, | 134 | Two, |
| 572 | Three, | 135 | Three, |
| 573 | Four, | 136 | Four, |
| 574 | } | 137 | }; |