| author | |
| committer | |
| log | 9e88356282861e5812d95587cb8fab7f902bc85b |
| tree | 2d6321739d507435dc14bfca7057807b6a9f3c2a |
| parent | 9be2f767417ef4eb69f35b67348bb3e2ec752d4a |
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.3 files changed, 13 insertions(+), 1 deletions(-)
doc/langref.html.in+1-1| ... | ... | @@ -7447,7 +7447,7 @@ test "main" { |
| 7447 | 7447 | {#see_also|@divFloor|@divExact#} |
| 7448 | 7448 | {#header_close#} |
| 7449 | 7449 | {#header_open|@embedFile#} |
| 7450 | <pre>{#syntax#}@embedFile(comptime path: []const u8) *const [X:0]u8{#endsyntax#}</pre> | |
| 7450 | <pre>{#syntax#}@embedFile(comptime path: []const u8) *const [N:0]u8{#endsyntax#}</pre> | |
| 7451 | 7451 | <p> |
| 7452 | 7452 | This function returns a compile time constant pointer to null-terminated, |
| 7453 | 7453 | fixed-size array with length equal to the byte count of the file given by |
test/behavior/bugs/3779.zig+11| ... | ... | @@ -29,3 +29,14 @@ test "@typeName() returns a string literal" { |
| 29 | 29 | try std.testing.expectEqualStrings("TestType", type_name); |
| 30 | 30 | try std.testing.expectEqualStrings("TestType", ptr_type_name[0..type_name.len]); |
| 31 | 31 | } |
| 32 | ||
| 33 | const actual_contents = @embedFile("3779_file_to_embed.txt"); | |
| 34 | const ptr_actual_contents: [*:0]const u8 = actual_contents; | |
| 35 | const expected_contents = "hello zig\n"; | |
| 36 | ||
| 37 | test "@embedFile() returns a string literal" { | |
| 38 | try std.testing.expectEqual(*const [expected_contents.len:0]u8, @TypeOf(actual_contents)); | |
| 39 | try std.testing.expect(std.mem.eql(u8, expected_contents, actual_contents)); | |
| 40 | try std.testing.expectEqualStrings(expected_contents, actual_contents); | |
| 41 | try std.testing.expectEqualStrings(expected_contents, ptr_actual_contents[0..actual_contents.len]); | |
| 42 | } |
test/behavior/bugs/3779_file_to_embed.txt created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | hello zig |