Add tests and fix \n between comments

This commit is contained in:
frmdstryr
2020-10-30 11:20:16 -04:00
parent 5dd36ee6ce
commit 1d22591299
2 changed files with 44 additions and 0 deletions

View File

@@ -513,6 +513,8 @@ static Token *ast_parse_multiline_string_literal(ParseContext *pc, Buf *buf) {
// if not, we have to revert back to before the doc comment
if (peek_token(pc)->id != TokenIdMultilineStringLiteral) {
pc->current_token = cur_token;
} else {
buf_append_char(buf, '\n'); // Add a newline between comments
}
}
return first_str_token;

View File

@@ -166,6 +166,48 @@ test "multiline string" {
expect(mem.eql(u8, s1, s2));
}
test "multiline string comments at start" {
const s1 =
//\\one
\\two)
\\three
;
const s2 = "two)\nthree";
expect(mem.eql(u8, s1, s2));
}
test "multiline string comments at end" {
const s1 =
\\one
\\two)
//\\three
;
const s2 = "one\ntwo)";
expect(mem.eql(u8, s1, s2));
}
test "multiline string comments in middle" {
const s1 =
\\one
//\\two)
\\three
;
const s2 = "one\nthree";
expect(mem.eql(u8, s1, s2));
}
test "multiline string comments at multiple places" {
const s1 =
\\one
//\\two
\\three
//\\four
\\five
;
const s2 = "one\nthree\nfive";
expect(mem.eql(u8, s1, s2));
}
test "multiline C string" {
const s1 =
\\one