embedFile: change notation from [X:0] to [N:0]
This is for consistency with the documentation on sentinel-terminated
{arrays,slices,pointers} which already use `N` for a comptime-inferred
size rather than `X`.
Also adds a behavioral test to assert that a string literal is returned.
This commit is contained in:
committed by
Daniele Cocca
parent
9be2f76741
commit
9e88356282
@@ -7447,7 +7447,7 @@ test "main" {
|
||||
{#see_also|@divFloor|@divExact#}
|
||||
{#header_close#}
|
||||
{#header_open|@embedFile#}
|
||||
<pre>{#syntax#}@embedFile(comptime path: []const u8) *const [X:0]u8{#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@embedFile(comptime path: []const u8) *const [N:0]u8{#endsyntax#}</pre>
|
||||
<p>
|
||||
This function returns a compile time constant pointer to null-terminated,
|
||||
fixed-size array with length equal to the byte count of the file given by
|
||||
|
||||
@@ -29,3 +29,14 @@ test "@typeName() returns a string literal" {
|
||||
try std.testing.expectEqualStrings("TestType", type_name);
|
||||
try std.testing.expectEqualStrings("TestType", ptr_type_name[0..type_name.len]);
|
||||
}
|
||||
|
||||
const actual_contents = @embedFile("3779_file_to_embed.txt");
|
||||
const ptr_actual_contents: [*:0]const u8 = actual_contents;
|
||||
const expected_contents = "hello zig\n";
|
||||
|
||||
test "@embedFile() returns a string literal" {
|
||||
try std.testing.expectEqual(*const [expected_contents.len:0]u8, @TypeOf(actual_contents));
|
||||
try std.testing.expect(std.mem.eql(u8, expected_contents, actual_contents));
|
||||
try std.testing.expectEqualStrings(expected_contents, actual_contents);
|
||||
try std.testing.expectEqualStrings(expected_contents, ptr_actual_contents[0..actual_contents.len]);
|
||||
}
|
||||
|
||||
1
test/behavior/bugs/3779_file_to_embed.txt
Normal file
1
test/behavior/bugs/3779_file_to_embed.txt
Normal file
@@ -0,0 +1 @@
|
||||
hello zig
|
||||
Reference in New Issue
Block a user