Commit 9e88356282
Changed files (3)
test
behavior
doc/langref.html.in
@@ -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
test/behavior/bugs/3779.zig
@@ -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]);
+}
test/behavior/bugs/3779_file_to_embed.txt
@@ -0,0 +1,1 @@
+hello zig