|
| 1 | +import { expect, it } from 'vitest' |
| 2 | +import { parseMarkdown, stringifyMarkdown } from '../utils/parser' |
| 3 | + |
| 4 | +it('Add space before and after :br', async () => { |
| 5 | + const input = `Hello\\\nWorld` |
| 6 | + |
| 7 | + const { body } = await parseMarkdown(input) |
| 8 | + const output = await stringifyMarkdown(body) |
| 9 | + |
| 10 | + expect(output).toBe(`Hello :br\nWorld\n`) |
| 11 | +}) |
| 12 | + |
| 13 | +it('Add space before :br', async () => { |
| 14 | + const input = `\\\nWorld` |
| 15 | + |
| 16 | + const { body } = await parseMarkdown(input) |
| 17 | + const output = await stringifyMarkdown(body) |
| 18 | + |
| 19 | + expect(output).toBe(`:br\nWorld\n`) |
| 20 | +}) |
| 21 | + |
| 22 | +it('Do not change spacings of binding elements', async () => { |
| 23 | + const inputs = [ |
| 24 | + `Hello{{ name }}`, |
| 25 | + `Hello {{ name }}`, |
| 26 | + `Hello{{ name }},`, |
| 27 | + `Hello {{ name }},`, |
| 28 | + `Hello {{ name }} ,` |
| 29 | + ] |
| 30 | + |
| 31 | + for (const input of inputs) { |
| 32 | + const { body } = await parseMarkdown(input) |
| 33 | + const output = await stringifyMarkdown(body) |
| 34 | + |
| 35 | + expect(output).toBe(input + '\n') |
| 36 | + } |
| 37 | +}) |
| 38 | + |
| 39 | +it('Ensure spacing between inline components', async () => { |
| 40 | + const input = `This is a :test :for components :spacing` |
| 41 | + |
| 42 | + const { body } = await parseMarkdown(input) |
| 43 | + const output = await stringifyMarkdown(body) |
| 44 | + |
| 45 | + expect(output).toBe(`This is a :test :for components :spacing\n`) |
| 46 | +}) |
| 47 | + |
| 48 | +it('Allow punctuation after inline components', async () => { |
| 49 | + const input = `This is a :test :for components :spacing,` |
| 50 | + |
| 51 | + const { body } = await parseMarkdown(input) |
| 52 | + const output = await stringifyMarkdown(body) |
| 53 | + |
| 54 | + expect(output).toBe(`This is a :test :for components :spacing,\n`) |
| 55 | +}) |
| 56 | + |
| 57 | +it('No spacing inside inline components', async () => { |
| 58 | + const inputs = [ |
| 59 | + `**:component[text]{.class}**`, |
| 60 | + `*:component[text]{.class}*`, |
| 61 | + `[:component[text]{.class}]` |
| 62 | + ] |
| 63 | + |
| 64 | + for (const input of inputs) { |
| 65 | + const { body } = await parseMarkdown(input) |
| 66 | + const output = await stringifyMarkdown(body) |
| 67 | + |
| 68 | + expect(output).toBe(input + '\n') |
| 69 | + } |
| 70 | +}) |
0 commit comments