authorgravatar for frmdstryr@protonmail.comfrmdstryr <frmdstryr@protonmail.com> 2020-10-30 11:20:16-04:00
committergravatar for frmdstryr@protonmail.comfrmdstryr <frmdstryr@protonmail.com> 2020-10-30 11:20:16-04:00
log1d22591299445b6a28b371f8ffcd4255e7d1a364
tree54613b37e0d0820120874abe99ba2ae4e634a870
parent5dd36ee6ceddc6ea5c6e3353198b7f8c2a703365

Add tests and fix \n between comments


2 files changed, 44 insertions(+), 0 deletions(-)

src/stage1/parser.cpp+2
...@@ -513,6 +513,8 @@ static Token *ast_parse_multiline_string_literal(ParseContext *pc, Buf *buf) {...@@ -513,6 +513,8 @@ static Token *ast_parse_multiline_string_literal(ParseContext *pc, Buf *buf) {
513 // if not, we have to revert back to before the doc comment513 // if not, we have to revert back to before the doc comment
514 if (peek_token(pc)->id != TokenIdMultilineStringLiteral) {514 if (peek_token(pc)->id != TokenIdMultilineStringLiteral) {
515 pc->current_token = cur_token;515 pc->current_token = cur_token;
516 } else {
517 buf_append_char(buf, '\n'); // Add a newline between comments
516 }518 }
517 }519 }
518 return first_str_token;520 return first_str_token;
test/stage1/behavior/misc.zig+42
...@@ -166,6 +166,48 @@ test "multiline string" {...@@ -166,6 +166,48 @@ test "multiline string" {
166 expect(mem.eql(u8, s1, s2));166 expect(mem.eql(u8, s1, s2));
167}167}
168168
169test "multiline string comments at start" {
170 const s1 =
171 //\\one
172 \\two)
173 \\three
174 ;
175 const s2 = "two)\nthree";
176 expect(mem.eql(u8, s1, s2));
177}
178
179test "multiline string comments at end" {
180 const s1 =
181 \\one
182 \\two)
183 //\\three
184 ;
185 const s2 = "one\ntwo)";
186 expect(mem.eql(u8, s1, s2));
187}
188
189test "multiline string comments in middle" {
190 const s1 =
191 \\one
192 //\\two)
193 \\three
194 ;
195 const s2 = "one\nthree";
196 expect(mem.eql(u8, s1, s2));
197}
198
199test "multiline string comments at multiple places" {
200 const s1 =
201 \\one
202 //\\two
203 \\three
204 //\\four
205 \\five
206 ;
207 const s2 = "one\nthree\nfive";
208 expect(mem.eql(u8, s1, s2));
209}
210
169test "multiline C string" {211test "multiline C string" {
170 const s1 =212 const s1 =
171 \\one213 \\one