Commit 1d22591299

frmdstryr <frmdstryr@protonmail.com>
2020-10-30 16:20:16
Add tests and fix \n between comments
1 parent 5dd36ee
Changed files (2)
src
stage1
test
stage1
behavior
src/stage1/parser.cpp
@@ -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;
test/stage1/behavior/misc.zig
@@ -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