Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { expect, test } from 'vitest'; |
| 2 | |
| 3 | import { docComment } from './DocComment'; |
| 4 | import { stringify } from './stringify'; |
| 5 | |
| 6 | test('empty', () => { |
| 7 | expect(stringify(docComment())).toMatchInlineSnapshot(` |
| 8 | "/** |
| 9 | */ |
| 10 | " |
| 11 | `); |
| 12 | }); |
| 13 | |
| 14 | test('one line', () => { |
| 15 | expect(stringify(docComment('I am comment'))).toMatchInlineSnapshot(` |
| 16 | "/** |
| 17 | * I am comment |
| 18 | */ |
| 19 | " |
| 20 | `); |
| 21 | }); |
| 22 | |
| 23 | test('multiline', () => { |
| 24 | expect(stringify(docComment('first\nsecond'))).toMatchInlineSnapshot(` |
| 25 | "/** |
| 26 | * first |
| 27 | * second |
| 28 | */ |
| 29 | " |
| 30 | `); |
| 31 | }); |
| 32 | |
| 33 | test('multiple addText calls', () => { |
| 34 | const comment = docComment('Line 1').addText('Line 2').addText('Line 3'); |
| 35 | expect(stringify(comment)).toMatchInlineSnapshot(` |
| 36 | "/** |
| 37 | * Line 1 |
| 38 | * Line 2 |
| 39 | * Line 3 |
| 40 | */ |
| 41 | " |
| 42 | `); |
| 43 | }); |
| 44 | |
| 45 | test('closing comment delimiters remain inside the comment', () => { |
| 46 | expect(stringify(docComment('Safe text */ globalThis.compromised = true'))) |
| 47 | .toMatchInlineSnapshot(` |
| 48 | "/** |
| 49 | * Safe text *\\/ globalThis.compromised = true |
| 50 | */ |
| 51 | " |
| 52 | `); |
| 53 | }); |
| 54 | |
| 55 | test('tagged template - empty', () => { |
| 56 | expect(stringify(docComment``)).toMatchInlineSnapshot(` |
| 57 | "/** |
| 58 | */ |
| 59 | " |
| 60 | `); |
| 61 | }); |
| 62 | |
| 63 | test('tagged template - spaces only', () => { |
| 64 | expect(stringify(docComment` `)).toMatchInlineSnapshot(` |
| 65 | "/** |
| 66 | */ |
| 67 | " |
| 68 | `); |
| 69 | }); |
| 70 | |
| 71 | test('tagged template - with content', () => { |
| 72 | const comment = docComment` |
| 73 | This is a multiline comment |
| 74 | - this line should be indented |
| 75 | And this should be not |
| 76 | `; |
| 77 | |
| 78 | expect(stringify(comment)).toMatchInlineSnapshot(` |
| 79 | "/** |
| 80 | * This is a multiline comment |
| 81 | * - this line should be indented |
| 82 | * And this should be not |
| 83 | */ |
| 84 | " |
| 85 | `); |
| 86 | }); |
| 87 | |
| 88 | test('tagged template - with substitutions', () => { |
| 89 | const name = 'World'; |
| 90 | const comment = docComment` |
| 91 | Hello, ${name}! |
| 92 | `; |
| 93 | |
| 94 | expect(stringify(comment)).toMatchInlineSnapshot(` |
| 95 | "/** |
| 96 | * Hello, World! |
| 97 | */ |
| 98 | " |
| 99 | `); |
| 100 | }); |