From 2bc3a486de9289d9205007e3b4fce414804ca304 Mon Sep 17 00:00:00 2001 From: Tom Maenan Read Cutting Date: Mon, 5 Sep 2022 08:51:19 +0100 Subject: [PATCH] Add tests for carriage return handling --- test/compare_output.zig | 9 +++++++++ test/compile_errors.zig | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/test/compare_output.zig b/test/compare_output.zig index 1ebed8222165..7da994bed10b 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -528,4 +528,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\debug: free - len: 5 \\ ); + + cases.add("valid carriage return example", "const io = @import(\"std\").io;\r\n" ++ // Testing CRLF line endings are valid + "\r\n" ++ + "pub \r fn main() void {\r\n" ++ // Testing isolated carriage return as whitespace is valid + " const stdout = io.getStdOut().writer();\r\n" ++ + " stdout.print(\\A Multiline\r\n" ++ // testing CRLF at end of multiline string line is valid and normalises to \n in the output + " \\String\r\n" ++ + " , .{}) catch unreachable;\r\n" ++ + "}\r\n", "A Multiline\nString"); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 96df66d081e7..8b6df733929c 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -174,6 +174,16 @@ pub fn addCases(ctx: *TestContext) !void { }); } + { + const case = ctx.obj("isolated carriage return in multiline string literal", .{}); + case.backend = .stage2; + + case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{ + ":1:19: error: expected ';' after declaration", + ":1:20: note: invalid byte: '\\r'", + }); + } + { const case = ctx.obj("missing semicolon at EOF", .{}); case.addError(