|
| 1 | +import {describe, it, expect} from "vitest"; |
| 2 | +import {extractComments} from "../src/lib/utils"; |
| 3 | + |
| 4 | +describe("extractComments", () => { |
| 5 | + it("extracts Python # line comments above a test", () => { |
| 6 | + const code = [ |
| 7 | + " # Calls:", |
| 8 | + " # (415) POST:/v2/pet/{petId}/uploadImage", |
| 9 | + " # Found 1 potential fault of type-code 101", |
| 10 | + " @timeout_decorator.timeout(60)", |
| 11 | + " def test_23_post_on_uploadImage_returnsMismatchResponseWithSchema(self):", |
| 12 | + " pass", |
| 13 | + ].join("\n"); |
| 14 | + |
| 15 | + expect(extractComments(code)).toBe( |
| 16 | + [ |
| 17 | + "Calls:", |
| 18 | + "(415) POST:/v2/pet/{petId}/uploadImage", |
| 19 | + "Found 1 potential fault of type-code 101", |
| 20 | + ].join("\n"), |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + it("extracts Java /** */ Javadoc blocks", () => { |
| 25 | + const code = [ |
| 26 | + " /**", |
| 27 | + " * Calls:", |
| 28 | + " * (200) GET:/pets", |
| 29 | + " */", |
| 30 | + " @Test", |
| 31 | + " public void test_1() { }", |
| 32 | + ].join("\n"); |
| 33 | + |
| 34 | + expect(extractComments(code)).toBe(["Calls:", "(200) GET:/pets"].join("\n")); |
| 35 | + }); |
| 36 | + |
| 37 | + it("extracts // line comments", () => { |
| 38 | + const code = [ |
| 39 | + " // Calls:", |
| 40 | + " // (200) GET:/pets", |
| 41 | + " public void test() { }", |
| 42 | + ].join("\n"); |
| 43 | + |
| 44 | + expect(extractComments(code)).toBe(["Calls:", "(200) GET:/pets"].join("\n")); |
| 45 | + }); |
| 46 | + |
| 47 | + it("separates distinct comment blocks with a blank line", () => { |
| 48 | + const code = [ |
| 49 | + "# first block", |
| 50 | + "# more of first block", |
| 51 | + "", |
| 52 | + "code_line()", |
| 53 | + "# second block", |
| 54 | + ].join("\n"); |
| 55 | + |
| 56 | + expect(extractComments(code)).toBe( |
| 57 | + ["first block\nmore of first block", "second block"].join("\n\n"), |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it("returns empty string when there are no comments", () => { |
| 62 | + const code = ["def test():", " pass"].join("\n"); |
| 63 | + expect(extractComments(code)).toBe(""); |
| 64 | + }); |
| 65 | + |
| 66 | + it("handles a single-line /* ... */ block", () => { |
| 67 | + const code = ["/* hello world */", "def f(): pass"].join("\n"); |
| 68 | + expect(extractComments(code)).toBe("hello world"); |
| 69 | + }); |
| 70 | +}); |
0 commit comments