Skip to content

Commit 73a4447

Browse files
squeek502andrewrk
authored andcommitted
langref: Make pointer_coerce_const_optional test less obfuscated
This test was originally introduced in 5f38d6e, where it looked like this: test "cast *[1][*]const u8 to [*]const ?[*]const u8" { const window_name = [1][*]const u8{c"window name"}; const x: [*]const ?[*]const u8 = &window_name; assert(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name")); } Over the years, this has become more and more obfuscated, to the point that the verbosity of the `expect` call overshadows the point of the example. This commit intends to update this test to match the spirit of the original version of the test, while shedding the obfuscation.
1 parent efde3ed commit 73a4447

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

doc/langref/test_pointer_coerce_const_optional.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const std = @import("std");
22
const expect = std.testing.expect;
33
const mem = std.mem;
44

5-
test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
6-
const window_name = [1][*]const u8{"window name"};
7-
const x: [*]const ?[*]const u8 = &window_name;
8-
try expect(mem.eql(u8, std.mem.sliceTo(@as([*:0]const u8, @ptrCast(x[0].?)), 0), "window name"));
5+
test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" {
6+
const window_name = [1][*:0]const u8{"window name"};
7+
const x: []const ?[*:0]const u8 = &window_name;
8+
try expect(mem.eql(u8, mem.span(x[0].?), "window name"));
99
}
1010

1111
// test

0 commit comments

Comments
 (0)