|
| 1 | +import { describe, expect, test } from 'vitest' |
| 2 | +import { |
| 3 | + stripHtmlComments, |
| 4 | + stripHtmlCommentsAndNormalizeWhitespace, |
| 5 | +} from '@/article-api/lib/strip-html-comments' |
| 6 | + |
| 7 | +describe('stripHtmlComments', () => { |
| 8 | + test('removes single-line HTML comments', () => { |
| 9 | + const input = '<!-- markdownlint-disable GHD053 -->' |
| 10 | + const expected = '' |
| 11 | + expect(stripHtmlComments(input)).toBe(expected) |
| 12 | + }) |
| 13 | + |
| 14 | + test('removes multiple HTML comments', () => { |
| 15 | + const input = '<!-- comment 1 -->\nSome content\n<!-- comment 2 -->' |
| 16 | + const expected = 'Some content' |
| 17 | + expect(stripHtmlComments(input)).toBe(expected) |
| 18 | + }) |
| 19 | + |
| 20 | + test('removes inline HTML comments', () => { |
| 21 | + const input = 'Text before <!-- comment --> text after' |
| 22 | + const expected = 'Text before text after' |
| 23 | + expect(stripHtmlComments(input)).toBe(expected) |
| 24 | + }) |
| 25 | + |
| 26 | + test('preserves content without HTML comments', () => { |
| 27 | + const input = 'Just regular markdown content' |
| 28 | + const expected = 'Just regular markdown content' |
| 29 | + expect(stripHtmlComments(input)).toBe(expected) |
| 30 | + }) |
| 31 | + |
| 32 | + test('handles multiple comments on same line', () => { |
| 33 | + const input = '<!-- comment 1 --> text <!-- comment 2 -->' |
| 34 | + const expected = 'text' |
| 35 | + expect(stripHtmlComments(input)).toBe(expected) |
| 36 | + }) |
| 37 | +}) |
| 38 | + |
| 39 | +describe('stripHtmlCommentsAndNormalizeWhitespace', () => { |
| 40 | + test('removes HTML comments and normalizes blank lines', () => { |
| 41 | + const input = `<!-- markdownlint-disable GHD053 --> |
| 42 | +
|
| 43 | +<!-- markdownlint-disable GHD030 --> |
| 44 | +
|
| 45 | +Content here` |
| 46 | + const expected = 'Content here' |
| 47 | + expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected) |
| 48 | + }) |
| 49 | + |
| 50 | + test('normalizes multiple blank lines to at most two', () => { |
| 51 | + const input = `Line 1 |
| 52 | +
|
| 53 | +
|
| 54 | +
|
| 55 | +Line 2` |
| 56 | + const expected = `Line 1 |
| 57 | +
|
| 58 | +Line 2` |
| 59 | + expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected) |
| 60 | + }) |
| 61 | + |
| 62 | + test('handles real CodeQL CLI content pattern', () => { |
| 63 | + const input = `# database analyze |
| 64 | +
|
| 65 | +Analyze a database, producing meaningful results |
| 66 | +
|
| 67 | +<!-- markdownlint-disable GHD053 --> |
| 68 | +
|
| 69 | +<!-- markdownlint-disable GHD030 --> |
| 70 | +
|
| 71 | +<!-- Content after this section is automatically generated --> |
| 72 | +
|
| 73 | +## Synopsis |
| 74 | +
|
| 75 | +\`\`\`shell |
| 76 | +codeql database analyze |
| 77 | +\`\`\`` |
| 78 | + |
| 79 | + const expected = `# database analyze |
| 80 | +
|
| 81 | +Analyze a database, producing meaningful results |
| 82 | +
|
| 83 | +## Synopsis |
| 84 | +
|
| 85 | +\`\`\`shell |
| 86 | +codeql database analyze |
| 87 | +\`\`\`` |
| 88 | + |
| 89 | + expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected) |
| 90 | + }) |
| 91 | + |
| 92 | + test('preserves intentional double line breaks', () => { |
| 93 | + const input = `# Title |
| 94 | +
|
| 95 | +Paragraph 1 |
| 96 | +
|
| 97 | +Paragraph 2` |
| 98 | + const expected = `# Title |
| 99 | +
|
| 100 | +Paragraph 1 |
| 101 | +
|
| 102 | +Paragraph 2` |
| 103 | + expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected) |
| 104 | + }) |
| 105 | +}) |
0 commit comments