aboutsummaryrefslogtreecommitdiff
path: root/test/cli.zig
diff options
context:
space:
mode:
authorErsikan <julien.philippon@epitech.eu>2021-03-14 07:03:22 +0100
committerErsikan <julien.philippon@epitech.eu>2021-03-17 10:26:47 +0100
commita3540000909bdc6a59ba07c85d21afeb3a7e54e2 (patch)
treed671cf5efd931c7b89af4c6fb8612efae085d645 /test/cli.zig
parentf76bd56588e556ea580c1faa63667cc9264cc218 (diff)
downloadzig-a3540000909bdc6a59ba07c85d21afeb3a7e54e2.tar.gz
zig-a3540000909bdc6a59ba07c85d21afeb3a7e54e2.zip
zig fmt: fix non-UTF-8 encoding #2820
Fixes #2820 After reading the source code, the first two bytes are inspected, and if they correspond to a UTF-16 BOM in little-endian order, the source code is converted to UTF-8.
Diffstat (limited to 'test/cli.zig')
-rw-r--r--test/cli.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/cli.zig b/test/cli.zig
index c0702fa54c..db58511d14 100644
--- a/test/cli.zig
+++ b/test/cli.zig
@@ -174,4 +174,13 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
// both files have been formatted, nothing should change now
testing.expect(run_result3.stdout.len == 0);
+
+ // Check UTF-16 decoding
+ const fmt4_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt4.zig" });
+ var unformatted_code_utf16 = "\xff\xfe \x00 \x00 \x00 \x00/\x00/\x00 \x00n\x00o\x00 \x00r\x00e\x00a\x00s\x00o\x00n\x00";
+ try fs.cwd().writeFile(fmt4_zig_path, unformatted_code_utf16);
+
+ const run_result4 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
+ testing.expect(std.mem.startsWith(u8, run_result4.stdout, fmt4_zig_path));
+ testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n');
}