Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hughess committed Jan 22, 2025
1 parent 9571a12 commit 435ca21
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 74 deletions.
80 changes: 44 additions & 36 deletions packages/lib/preprocess/src/add-blank-lines.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,70 @@ import { describe, it, expect } from 'vitest';
import addBlankLines from '../src/add-blank-lines.cjs';

describe('addBlankLines Preprocessor', () => {

it('should add a blank line after a component opening tag', () => {
const input = `<Details title='Definition'>
it('should add a blank line after a component opening tag', () => {
const input = `<Details title='Definition'>
Here is a metric definition
</Details>`;
const expectedOutput = `<Details title='Definition'>
const expectedOutput = `<Details title='Definition'>
Here is a metric definition
</Details>`;
const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});

const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should add a newline after {/each}', () => {
const input = `{#each items as item}
it('should add a newline after {/each}', () => {
const input = `{#each items as item}
{item.name}
{/each}`;
const expectedOutput = `{#each items as item}
const expectedOutput = `{#each items as item}
{item.name}
{/each}
`;

const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should add a newline before {/each}', () => {
const input = `{#each items as item}
const input = `{#each items as item}
{item.name}
{/each}`;
const expectedOutput = `{#each items as item}
const expectedOutput = `{#each items as item}
{item.name}
{/each}`;

const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should add a newline before {:else}', () => {
const input = `{#if condition}
it('should add a newline before {:else}', () => {
const input = `{#if condition}
Condition met
{:else}
Condition not met
{/if}`;
const expectedOutput = `{#if condition}
const expectedOutput = `{#if condition}
Condition met
{:else}
Condition not met
{/if}`;

const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should clean up excessive blank lines in attributes', () => {
const input = `<Component
Expand All @@ -72,19 +78,21 @@ Condition not met
prop1="value1"
prop2="value2"
prop3="value3" />`;

const result = addBlankLines.markup({ content: input, filename: 'test.md' });

expect(result.code.replace(/\s+/g, ' ').trim()).toEqual(expectedOutput.replace(/\s+/g, ' ').trim());
});


it('should handle a component with no attributes', () => {
const input = `<SimpleComponent />`;
const expectedOutput = `<SimpleComponent />`;
expect(result.code.replace(/\s+/g, ' ').trim()).toEqual(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
it('should handle a component with no attributes', () => {
const input = `<SimpleComponent />`;
const expectedOutput = `<SimpleComponent />`;

const result = addBlankLines.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});
});
87 changes: 49 additions & 38 deletions packages/lib/preprocess/src/process-each-blocks.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,95 @@ import { describe, it, expect } from 'vitest';
import processEachBlocks from '../src/process-each-blocks.cjs';

describe('processEachBlocks Preprocessor', () => {

it('should handle text without blank line before closing each tag', () => {
const input = `{#each something as thing}
it('should handle text without blank line before closing each tag', () => {
const input = `{#each something as thing}
<p>text
{/each}</p>`;
const expectedOutput = `{#each something as thing}
const expectedOutput = `{#each something as thing}
<p>text
</p>
{/each}`;

const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toEqual(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toEqual(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should handle unordered lists without blank line before closing each tag', () => {
const input = `
it('should handle unordered lists without blank line before closing each tag', () => {
const input = `
{#each something as thing}<ul>
<li>one
{/each}</li></ul>`;
const expectedOutput = `
const expectedOutput = `
<ul>
{#each something as thing}
<li>one
</li>
{/each}
</ul>`;

const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should handle ordered lists without blank line before closing each tag', () => {
const input = `
it('should handle ordered lists without blank line before closing each tag', () => {
const input = `
{#each something as thing}<ol>
<li>one
{/each}</li></ol>`;
const expectedOutput = `
const expectedOutput = `
<ol>
{#each something as thing}
<li>one
</li>
{/each}
</ol>`;

const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should handle unordered lists contained inside each tags', () => {
const input = `{#each something as thing}<ul>
it('should handle unordered lists contained inside each tags', () => {
const input = `{#each something as thing}<ul>
<li>one</li>
</ul>
{/each}`;
const expectedOutput = `<ul>
const expectedOutput = `<ul>
{#each something as thing}<li>one
</li>
{/each}
</ul>`;

const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should handle ordered lists contained inside each tags', () => {
const input = `{#each something as thing}<ol>
it('should handle ordered lists contained inside each tags', () => {
const input = `{#each something as thing}<ol>
<li>one</li>
</ol>
{/each}`;
const expectedOutput = `<ol>
const expectedOutput = `<ol>
{#each something as thing}<li>one
</li>
{/each}
</ol>`;

const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});

it('should preserve code blocks and inline code snippets', () => {
const input = `# Markdown with Code
const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});

it('should preserve code blocks and inline code snippets', () => {
const input = `# Markdown with Code
\`\`\`js
console.log('Code block');
Expand All @@ -94,7 +103,7 @@ Inline code: \`console.log('inline');\`
<li>{item.name}</li>
</ul>
{/each}`;
const expectedOutput = `# Markdown with Code
const expectedOutput = `# Markdown with Code
\`\`\`js
console.log('Code block');
Expand All @@ -108,7 +117,9 @@ Inline code: \`console.log('inline');\`
{/each}
</ul>`;

const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim());
});
const result = processEachBlocks.markup({ content: input, filename: 'test.md' });
expect(result.code.replace(/\s+/g, ' ').trim()).toBe(
expectedOutput.replace(/\s+/g, ' ').trim()
);
});
});

0 comments on commit 435ca21

Please sign in to comment.