| ... | ... | @@ -8,7 +8,7 @@ const builtin = @import("builtin"); |
| 8 | 8 | /// doc comment line 2 |
| 9 | 9 | fn emptyFunctionWithComments() {} |
| 10 | 10 | |
| 11 | | test "emptyFunctionWithComments" { |
| 11 | test "empty function with comments" { |
| 12 | 12 | emptyFunctionWithComments(); |
| 13 | 13 | } |
| 14 | 14 | |
| ... | ... | @@ -16,7 +16,7 @@ export fn disabledExternFn() { |
| 16 | 16 | @setGlobalLinkage(disabledExternFn, builtin.GlobalLinkage.Internal); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | | test "callDisabledExternFn" { |
| 19 | test "call disabled extern fn" { |
| 20 | 20 | disabledExternFn(); |
| 21 | 21 | } |
| 22 | 22 | |
| ... | ... | @@ -59,7 +59,7 @@ const u63 = @IntType(false, 63); |
| 59 | 59 | const i1 = @IntType(true, 1); |
| 60 | 60 | const i63 = @IntType(true, 63); |
| 61 | 61 | |
| 62 | | test "minValueAndMaxValue" { |
| 62 | test "@minValue and @maxValue" { |
| 63 | 63 | assert(@maxValue(u1) == 1); |
| 64 | 64 | assert(@maxValue(u8) == 255); |
| 65 | 65 | assert(@maxValue(u16) == 65535); |
| ... | ... | @@ -88,7 +88,7 @@ test "minValueAndMaxValue" { |
| 88 | 88 | assert(@minValue(i64) == -9223372036854775808); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | | test "maxValueType" { |
| 91 | test "max value type" { |
| 92 | 92 | // If the type of @maxValue(i32) was i32 then this implicit cast to |
| 93 | 93 | // u32 would not work. But since the value is a number literal, |
| 94 | 94 | // it works fine. |
| ... | ... | @@ -96,8 +96,9 @@ test "maxValueType" { |
| 96 | 96 | assert(x == 2147483647); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | | test "shortCircuit" { |
| 99 | test "short circuit" { |
| 100 | 100 | testShortCircuit(false, true); |
| 101 | comptime testShortCircuit(false, true); |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | 104 | fn testShortCircuit(f: bool, t: bool) { |
| ... | ... | @@ -138,21 +139,21 @@ fn first4KeysOfHomeRow() -> []const u8 { |
| 138 | 139 | "aoeu" |
| 139 | 140 | } |
| 140 | 141 | |
| 141 | | test "ReturnStringFromFunction" { |
| 142 | test "return string from function" { |
| 142 | 143 | assert(mem.eql(u8, first4KeysOfHomeRow(), "aoeu")); |
| 143 | 144 | } |
| 144 | 145 | |
| 145 | 146 | const g1 : i32 = 1233 + 1; |
| 146 | 147 | var g2 : i32 = 0; |
| 147 | 148 | |
| 148 | | test "globalVariables" { |
| 149 | test "global variables" { |
| 149 | 150 | assert(g2 == 0); |
| 150 | 151 | g2 = g1; |
| 151 | 152 | assert(g2 == 1234); |
| 152 | 153 | } |
| 153 | 154 | |
| 154 | 155 | |
| 155 | | test "memcpyAndMemsetIntrinsics" { |
| 156 | test "memcpy and memset intrinsics" { |
| 156 | 157 | var foo : [20]u8 = undefined; |
| 157 | 158 | var bar : [20]u8 = undefined; |
| 158 | 159 | |
| ... | ... | @@ -162,7 +163,7 @@ test "memcpyAndMemsetIntrinsics" { |
| 162 | 163 | if (bar[11] != 'A') unreachable; |
| 163 | 164 | } |
| 164 | 165 | |
| 165 | | test "builtinStaticEval" { |
| 166 | test "builtin static eval" { |
| 166 | 167 | const x : i32 = comptime {1 + 2 + 3}; |
| 167 | 168 | assert(x == comptime 6); |
| 168 | 169 | } |
| ... | ... | @@ -184,7 +185,7 @@ test "slicing" { |
| 184 | 185 | } |
| 185 | 186 | |
| 186 | 187 | |
| 187 | | test "constantEqualFunctionPointers" { |
| 188 | test "constant equal function pointers" { |
| 188 | 189 | const alias = emptyFn; |
| 189 | 190 | assert(comptime {emptyFn == alias}); |
| 190 | 191 | } |
| ... | ... | @@ -192,19 +193,19 @@ test "constantEqualFunctionPointers" { |
| 192 | 193 | fn emptyFn() {} |
| 193 | 194 | |
| 194 | 195 | |
| 195 | | test "hexEscape" { |
| 196 | test "hex escape" { |
| 196 | 197 | assert(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello")); |
| 197 | 198 | } |
| 198 | 199 | |
| 199 | | test "stringConcatenation" { |
| 200 | test "string concatenation" { |
| 200 | 201 | assert(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); |
| 201 | 202 | } |
| 202 | 203 | |
| 203 | | test "arrayMultOperator" { |
| 204 | test "array mult operator" { |
| 204 | 205 | assert(mem.eql(u8, "ab" ** 5, "ababababab")); |
| 205 | 206 | } |
| 206 | 207 | |
| 207 | | test "stringEscapes" { |
| 208 | test "string escapes" { |
| 208 | 209 | assert(mem.eql(u8, "\"", "\x22")); |
| 209 | 210 | assert(mem.eql(u8, "\'", "\x27")); |
| 210 | 211 | assert(mem.eql(u8, "\n", "\x0a")); |
| ... | ... | @@ -214,7 +215,7 @@ test "stringEscapes" { |
| 214 | 215 | assert(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69")); |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | | test "multilineString" { |
| 218 | test "multiline string" { |
| 218 | 219 | const s1 = |
| 219 | 220 | \\one |
| 220 | 221 | \\two) |
| ... | ... | @@ -224,7 +225,7 @@ test "multilineString" { |
| 224 | 225 | assert(mem.eql(u8, s1, s2)); |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | | test "multilineCString" { |
| 228 | test "multiline C string" { |
| 228 | 229 | const s1 = |
| 229 | 230 | c\\one |
| 230 | 231 | c\\two) |
| ... | ... | @@ -235,7 +236,7 @@ test "multilineCString" { |
| 235 | 236 | } |
| 236 | 237 | |
| 237 | 238 | |
| 238 | | test "typeEquality" { |
| 239 | test "type equality" { |
| 239 | 240 | assert(&const u8 != &u8); |
| 240 | 241 | } |
| 241 | 242 | |
| ... | ... | @@ -243,17 +244,17 @@ test "typeEquality" { |
| 243 | 244 | const global_a: i32 = 1234; |
| 244 | 245 | const global_b: &const i32 = &global_a; |
| 245 | 246 | const global_c: &const f32 = @ptrCast(&const f32, global_b); |
| 246 | | test "compileTimeGlobalReinterpret" { |
| 247 | test "compile time global reinterpret" { |
| 247 | 248 | const d = @ptrCast(&const i32, global_c); |
| 248 | 249 | assert(*d == 1234); |
| 249 | 250 | } |
| 250 | 251 | |
| 251 | | test "explicitCastMaybePointers" { |
| 252 | test "explicit cast maybe pointers" { |
| 252 | 253 | const a: ?&i32 = undefined; |
| 253 | 254 | const b: ?&f32 = @ptrCast(?&f32, a); |
| 254 | 255 | } |
| 255 | 256 | |
| 256 | | test "genericMallocFree" { |
| 257 | test "generic malloc free" { |
| 257 | 258 | const a = %%memAlloc(u8, 10); |
| 258 | 259 | memFree(u8, a); |
| 259 | 260 | } |
| ... | ... | @@ -264,7 +265,7 @@ fn memAlloc(comptime T: type, n: usize) -> %[]T { |
| 264 | 265 | fn memFree(comptime T: type, memory: []T) { } |
| 265 | 266 | |
| 266 | 267 | |
| 267 | | test "castUndefined" { |
| 268 | test "cast undefined" { |
| 268 | 269 | const array: [100]u8 = undefined; |
| 269 | 270 | const slice = ([]const u8)(array); |
| 270 | 271 | testCastUndefined(slice); |
| ... | ... | @@ -272,7 +273,7 @@ test "castUndefined" { |
| 272 | 273 | fn testCastUndefined(x: []const u8) {} |
| 273 | 274 | |
| 274 | 275 | |
| 275 | | test "castSmallUnsignedToLargerSigned" { |
| 276 | test "cast small unsigned to larger signed" { |
| 276 | 277 | assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); |
| 277 | 278 | assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); |
| 278 | 279 | } |
| ... | ... | @@ -280,7 +281,7 @@ fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x } |
| 280 | 281 | fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x } |
| 281 | 282 | |
| 282 | 283 | |
| 283 | | test "implicitCastAfterUnreachable" { |
| 284 | test "implicit cast after unreachable" { |
| 284 | 285 | assert(outer() == 1234); |
| 285 | 286 | } |
| 286 | 287 | fn inner() -> i32 { 1234 } |
| ... | ... | @@ -289,7 +290,7 @@ fn outer() -> i64 { |
| 289 | 290 | } |
| 290 | 291 | |
| 291 | 292 | |
| 292 | | test "pointerDereferencing" { |
| 293 | test "pointer dereferencing" { |
| 293 | 294 | var x = i32(3); |
| 294 | 295 | const y = &x; |
| 295 | 296 | |
| ... | ... | @@ -299,7 +300,7 @@ test "pointerDereferencing" { |
| 299 | 300 | assert(*y == 4); |
| 300 | 301 | } |
| 301 | 302 | |
| 302 | | test "callResultOfIfElseExpression" { |
| 303 | test "call result of if else expression" { |
| 303 | 304 | assert(mem.eql(u8, f2(true), "a")); |
| 304 | 305 | assert(mem.eql(u8, f2(false), "b")); |
| 305 | 306 | } |
| ... | ... | @@ -310,7 +311,7 @@ fn fA() -> []const u8 { "a" } |
| 310 | 311 | fn fB() -> []const u8 { "b" } |
| 311 | 312 | |
| 312 | 313 | |
| 313 | | test "constExpressionEvalHandlingOfVariables" { |
| 314 | test "const expression eval handling of variables" { |
| 314 | 315 | var x = true; |
| 315 | 316 | while (x) { |
| 316 | 317 | x = false; |
| ... | ... | @@ -319,7 +320,7 @@ test "constExpressionEvalHandlingOfVariables" { |
| 319 | 320 | |
| 320 | 321 | |
| 321 | 322 | |
| 322 | | test "constantEnumInitializationWithDifferingSizes" { |
| 323 | test "constant enum initialization with differing sizes" { |
| 323 | 324 | test3_1(test3_foo); |
| 324 | 325 | test3_2(test3_bar); |
| 325 | 326 | } |
| ... | ... | @@ -353,14 +354,14 @@ fn test3_2(f: &const Test3Foo) { |
| 353 | 354 | } |
| 354 | 355 | |
| 355 | 356 | |
| 356 | | test "characterLiterals" { |
| 357 | test "character literals" { |
| 357 | 358 | assert('\'' == single_quote); |
| 358 | 359 | } |
| 359 | 360 | const single_quote = '\''; |
| 360 | 361 | |
| 361 | 362 | |
| 362 | 363 | |
| 363 | | test "takeAddressOfParameter" { |
| 364 | test "take address of parameter" { |
| 364 | 365 | testTakeAddressOfParameter(12.34); |
| 365 | 366 | } |
| 366 | 367 | fn testTakeAddressOfParameter(f: f32) { |
| ... | ... | @@ -369,7 +370,7 @@ fn testTakeAddressOfParameter(f: f32) { |
| 369 | 370 | } |
| 370 | 371 | |
| 371 | 372 | |
| 372 | | test "pointerComparison" { |
| 373 | test "pointer comparison" { |
| 373 | 374 | const a = ([]const u8)("a"); |
| 374 | 375 | const b = &a; |
| 375 | 376 | assert(ptrEql(b, b)); |
| ... | ... | @@ -379,7 +380,7 @@ fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool { |
| 379 | 380 | } |
| 380 | 381 | |
| 381 | 382 | |
| 382 | | test "cStringConcatenation" { |
| 383 | test "C string concatenation" { |
| 383 | 384 | const a = c"OK" ++ c" IT " ++ c"WORKED"; |
| 384 | 385 | const b = c"OK IT WORKED"; |
| 385 | 386 | |
| ... | ... | @@ -392,7 +393,7 @@ test "cStringConcatenation" { |
| 392 | 393 | assert(b[len] == 0); |
| 393 | 394 | } |
| 394 | 395 | |
| 395 | | test "castSliceToU8Slice" { |
| 396 | test "cast slice to u8 slice" { |
| 396 | 397 | assert(@sizeOf(i32) == 4); |
| 397 | 398 | var big_thing_array = []i32{1, 2, 3, 4}; |
| 398 | 399 | const big_thing_slice: []i32 = big_thing_array[0...]; |
| ... | ... | @@ -412,7 +413,7 @@ test "castSliceToU8Slice" { |
| 412 | 413 | assert(bytes[11] == @maxValue(u8)); |
| 413 | 414 | } |
| 414 | 415 | |
| 415 | | test "pointerToVoidReturnType" { |
| 416 | test "pointer to void return type" { |
| 416 | 417 | %%testPointerToVoidReturnType(); |
| 417 | 418 | } |
| 418 | 419 | fn testPointerToVoidReturnType() -> %void { |
| ... | ... | @@ -425,14 +426,14 @@ fn testPointerToVoidReturnType2() -> &const void { |
| 425 | 426 | } |
| 426 | 427 | |
| 427 | 428 | |
| 428 | | test "nonConstPtrToAliasedType" { |
| 429 | test "non const ptr to aliased type" { |
| 429 | 430 | const int = i32; |
| 430 | 431 | assert(?&int == ?&i32); |
| 431 | 432 | } |
| 432 | 433 | |
| 433 | 434 | |
| 434 | 435 | |
| 435 | | test "array2DConstDoublePtr" { |
| 436 | test "array 2D const double ptr" { |
| 436 | 437 | const rect_2d_vertexes = [][1]f32 { |
| 437 | 438 | []f32{1.0}, |
| 438 | 439 | []f32{2.0}, |
| ... | ... | @@ -445,7 +446,7 @@ fn testArray2DConstDoublePtr(ptr: &const f32) { |
| 445 | 446 | assert(ptr[1] == 2.0); |
| 446 | 447 | } |
| 447 | 448 | |
| 448 | | test "isInteger" { |
| 449 | test "@isInteger" { |
| 449 | 450 | comptime { |
| 450 | 451 | assert(@isInteger(i8)); |
| 451 | 452 | assert(@isInteger(u8)); |
| ... | ... | @@ -458,7 +459,7 @@ test "isInteger" { |
| 458 | 459 | } |
| 459 | 460 | } |
| 460 | 461 | |
| 461 | | test "isFloat" { |
| 462 | test "@isFloat" { |
| 462 | 463 | comptime { |
| 463 | 464 | assert(!@isFloat(i8)); |
| 464 | 465 | assert(!@isFloat(u8)); |
| ... | ... | @@ -471,7 +472,7 @@ test "isFloat" { |
| 471 | 472 | } |
| 472 | 473 | } |
| 473 | 474 | |
| 474 | | test "canImplicitCast" { |
| 475 | test "@canImplicitCast" { |
| 475 | 476 | comptime { |
| 476 | 477 | assert(@canImplicitCast(i64, i32(3))); |
| 477 | 478 | assert(!@canImplicitCast(i32, f32(1.234))); |
| ... | ... | @@ -479,14 +480,14 @@ test "canImplicitCast" { |
| 479 | 480 | } |
| 480 | 481 | } |
| 481 | 482 | |
| 482 | | test "typeName" { |
| 483 | test "@typeName" { |
| 483 | 484 | comptime { |
| 484 | 485 | assert(mem.eql(u8, @typeName(i64), "i64")); |
| 485 | 486 | assert(mem.eql(u8, @typeName(&usize), "&usize")); |
| 486 | 487 | } |
| 487 | 488 | } |
| 488 | 489 | |
| 489 | | test "volatileLoadAndStore" { |
| 490 | test "volatile load and store" { |
| 490 | 491 | var number: i32 = 1234; |
| 491 | 492 | const ptr = &volatile number; |
| 492 | 493 | *ptr += 1; |
| ... | ... | @@ -500,3 +501,15 @@ test "slice string literal has type []const u8" { |
| 500 | 501 | assert(@typeOf(array[0...]) == []const i32); |
| 501 | 502 | } |
| 502 | 503 | } |
| 504 | |
| 505 | test "global variable initialized to global variable array element" { |
| 506 | assert(global_ptr == &gdt[0]); |
| 507 | } |
| 508 | const GDTEntry = struct { |
| 509 | field: i32, |
| 510 | }; |
| 511 | var gdt = []GDTEntry { |
| 512 | GDTEntry {.field = 1}, |
| 513 | GDTEntry {.field = 2}, |
| 514 | }; |
| 515 | var global_ptr = &gdt[0]; |