Skip to content

Commit 219d4e5

Browse files
committed
Add tests for carriage return handling
1 parent 15abc79 commit 219d4e5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/compare_output.zig

+9
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
535535
\\debug: free - len: 5
536536
\\
537537
);
538+
539+
cases.add("valid carriage return example", "const io = @import(\"std\").io;\r\n" ++ // Testing CRLF line endings are valid
540+
"\r\n" ++
541+
"pub \r fn main() void {\r\n" ++ // Testing isolated carriage return as whitespace is valid
542+
" const stdout = io.getStdOut().writer();\r\n" ++
543+
" stdout.print(\\\\A Multiline\r\n" ++ // testing CRLF at end of multiline string line is valid and normalises to \n in the output
544+
" \\\\String\r\n" ++
545+
" , .{}) catch unreachable;\r\n" ++
546+
"}\r\n", "A Multiline\nString");
538547
}

test/compile_errors.zig

+10
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ pub fn addCases(ctx: *TestContext) !void {
174174
});
175175
}
176176

177+
{
178+
const case = ctx.obj("isolated carriage return in multiline string literal", .{});
179+
case.backend = .stage2;
180+
181+
case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{
182+
":1:19: error: expected ';' after declaration",
183+
":1:20: note: invalid byte: '\\r'",
184+
});
185+
}
186+
177187
{
178188
const case = ctx.obj("missing semicolon at EOF", .{});
179189
case.addError(

0 commit comments

Comments
 (0)