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 Sep 5, 2022
1 parent 89ff1be commit cd43521
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 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");
}
16 changes: 13 additions & 3 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,23 @@ pub fn addCases(ctx: *TestContext) !void {
\\ );
\\}
, &[_][]const u8{
\\:2:5: error:
\\:2:5: error:
\\ hello!
\\ I'm a multiline error message.
\\ I hope to be very useful!
\\
\\
\\ also I will leave this trailing newline here if you don't mind
\\
\\
});
}

{
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'",
});
}

Expand Down

0 comments on commit cd43521

Please sign in to comment.