Skip to content

Commit

Permalink
add outliner tests for code blocks in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed Nov 14, 2024
1 parent 2d14228 commit 5b98f8f
Showing 1 changed file with 256 additions and 62 deletions.
318 changes: 256 additions & 62 deletions outline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,68 +128,6 @@ and more of this mess
- ### h3-2 with a subheading
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});
await t.step("should handle multiline lists", () => {
const input = `
paragraph
- a list
of items
- and nested items
- with more items
- inside
them
another paragraph
`.trim();

const expectedOutput = `
- paragraph
- a list
of items
- and nested items
- with more items
- inside
them
- another paragraph
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});

await t.step("newlines shouldn't break lists", () => {
const input = `
- this is a list
- with a sub list
> with a quote
> that continues here
> but then there is a quote
> at the first level
> and it's another quote
- then the list goes on
- sub item after a newline
- and the last one
`.trim();

const expectedOutput = `
- this is a list
- with a sub list
> with a quote
> that continues here
> but then there is a quote
> at the first level
> and it's another quote
- then the list goes on
- sub item after a newline
- and the last one
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});
});
Expand Down Expand Up @@ -325,3 +263,259 @@ quote
);
});
});

Deno.test("outlineMarkdown handling lists", async (t) => {
await t.step("should handle multiline lists", () => {
const input = `
paragraph
- a list
of items
- and nested items
- with more items
- inside
them
another paragraph
`.trim();

const expectedOutput = `
- paragraph
- a list
of items
- and nested items
- with more items
- inside
them
- another paragraph
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});

await t.step("newlines shouldn't break lists", () => {
const input = `
- this is a list
- with a sub list
#+BEGIN_QUOTE
with a quote
that continues here
#+END_QUOTE
#+BEGIN_QUOTE
but then there is a quote
at the first level
and it's another quote
#+END_QUOTE
- then the list goes on
- sub item after a newline
- and the last one
`.trim();
});
});

Deno.test("outlineMarkdown handling code blocks in lists", async (t) => {
await t.step("should handle indented code blocks inside lists", () => {
const input = `
- list item
- nested item
\`\`\`text
code block
\`\`\`
- another nested item
\`\`\`
another code block
\`\`\`
- another list item
\`\`\`
code block at first level
\`\`\`
`.trim();

const expectedOutput = `
- list item
- nested item
\`\`\`text
code block
\`\`\`
- another nested item
\`\`\`
another code block
\`\`\`
- another list item
\`\`\`
code block at first level
\`\`\`
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});

await t.step("should handle text after a code block", () => {
const input = `
- list item
\`\`\`
code block
\`\`\`
text after code block
- another list item
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
`.trim();

const expectedOutput = `
- list item
\`\`\`
code block
\`\`\`
text after code block
- another list item
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});

await t.step("should handle blank lines before/after code blocks", () => {
const input = `
- list item
\`\`\`
code block
\`\`\`
text after code block
- another list item
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
`.trim();

const expectedOutput = `
- list item
\`\`\`
code block
\`\`\`
text after code block
- another list item
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});

await t.step(
"should handle code blocks on different levels of nested lists",
() => {
const input = `
- list item
\`\`\`
code block at first level
\`\`\`
- nested item
\`\`\`
code block at nested level
\`\`\`
- deeper nested item
\`\`\`
code block at deeper nested level
\`\`\`
`.trim();

const expectedOutput = `
- list item
\`\`\`
code block at first level
\`\`\`
- nested item
\`\`\`
code block at nested level
\`\`\`
- deeper nested item
\`\`\`
code block at deeper nested level
\`\`\`
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
},
);

await t.step("should handle edge cases with code blocks", () => {
const input = `
- list item
\`\`\`
code block
\`\`\`
text after code block
- another list item
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
- list item with no blank lines
\`\`\`
code block
\`\`\`
text after code block
- another list item with no blank lines
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
`.trim();

const expectedOutput = `
- list item
\`\`\`
code block
\`\`\`
text after code block
- another list item
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
- list item with no blank lines
\`\`\`
code block
\`\`\`
text after code block
- another list item with no blank lines
- nested item
\`\`\`
nested code block
\`\`\`
text after nested code block
`.trim();

assertEquals(outlineMarkdown(input), expectedOutput);
});
});

0 comments on commit 5b98f8f

Please sign in to comment.