Skip to content

Commit

Permalink
Add tests for carriage return handling
Browse files Browse the repository at this point in the history
  • Loading branch information
moosichu committed Oct 8, 2022
1 parent bc322aa commit 2bc3a48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/compare_output.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
10 changes: 10 additions & 0 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2bc3a48

Please sign in to comment.