Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
bibliography: references.bib
---

Welcome to valid basics 2.

```{=html}
<div>hi</div>
```

`hi`{=html}

```{{r}}
1 + 1
```

> This is a block quote this is the same block quote

| this is a line block
| this is another line block

This is *emphasized* text

This is also *emphasized* text

hello [underline]{.underline} ~~strikethrough~~ ^super^ ~sub~ [smallcaps]{.smallcaps}

<!--# this is an html comment -->

definition term

: definition content

definition term 2

: definition content 2

------------------------------------------------------------------------

::: {#thm-pythagoras}
#### Pythagoras's Theorem

In a right triangle, the lengths of the two shorter sides $a$, $b$ and the longer side $c$ stand in the relation $$
a^2 + b^2 = c^2.
$$
:::

See @thm-pythagoras for details.

{{< meta title >}}

| Col1 | Col2 | Col3 |
|------|------|-----:|
| 11 | 21 | 31 |
| 12 | 22 | 32 |
| 13 | 23 | 33 |

: table caption

@riehl2023

[@riehl2023]

hey footnote[^1]

[^1]: hello I'm a foot node

be careful of newline at end of file, roundtripping removes it:
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
````{=markdown}
```{=markdown}
hi
```
````

```{{python}}
a = 3
```

> ```
> 1+1
> ```
>
> $$
> 3 = 1 + 1 + 1 = 2 + 1 = 1 + 2
> $$
>
> > block quote in block quote
>
> +-----+-------+
> | $$ | ``` r |
> | 1+0 | 1+1 |
> | $$ | ``` |
> +-----+-------+
> | 3 | 4 |
> +-----+-------+
>
> : my table caption
>
> ::: hello
> fenced div in block quote
> :::
14 changes: 14 additions & 0 deletions apps/vscode/src/test/examples/references.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@article{riehl2023,
title = {Could ∞-Category Theory Be Taught to Undergraduates?},
author = {Riehl, Emily},
year = {2023},
month = {05},
date = {2023-05-01},
journal = {Notices of the American Mathematical Society},
pages = {1},
volume = {70},
number = {05},
doi = {10.1090/noti2692},
url = {http://dx.doi.org/10.1090/noti2692},
langid = {en}
}
15 changes: 0 additions & 15 deletions apps/vscode/src/test/examples/roundtrip-changes.qmd

This file was deleted.

69 changes: 69 additions & 0 deletions apps/vscode/src/test/examples/valid-basics-2.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
bibliography: references.bib
---

Welcome to valid basics 2.

```{=html}
<div>hi</div>
```

`hi`{=html}

```{{r}}
1 + 1
```

> This is a block quote
> this is the same block quote

| this is a line block
| this is another line block

This is *emphasized* text

This is also _emphasized_ text

hello [underline]{.underline} ~~strikethrough~~ ^super^ ~sub~ [smallcaps]{.smallcaps}

<!--# this is an html comment -->

definition term

: definition content

definition term 2

: definition content 2

------------------------------------------------------------------------

::: {#thm-pythagoras}
#### Pythagoras's Theorem
In a right triangle, the lengths of the two shorter sides $a$, $b$ and the longer side $c$ stand in the relation
$$
a^2 + b^2 = c^2.
$$
:::

See @thm-pythagoras for details.

{{< meta title >}}

| Col1 | Col2 | Col3 |
|------|------|-----:|
| 11 | 21 | 31 |
| 12 | 22 | 32 |
| 13 | 23 | 33 |

: table caption

@riehl2023

[@riehl2023]

hey footnote[^1]

[^1]: hello I'm a foot node

be careful of newline at end of file, roundtripping removes it:
35 changes: 35 additions & 0 deletions apps/vscode/src/test/examples/valid-nesting.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
``````{=markdown}
```{=markdown}
hi
```
``````

````
```{python}
a = 3
```
````

> ```
> 1+1
> ```
>
> $$
> 3 = 1 + 1 + 1 = 2 + 1 = 1 + 2
> $$
>
> > block quote in block quote
>
> +-----+-------+
> | $$ | ``` r |
> | 1+0 | 1+1 |
> | $$ | ``` |
> +-----+-------+
> | 3 | 4 |
> +-----+-------+
>
> : my table caption
>
> ::: hello
> fenced div in block quote
> :::
48 changes: 22 additions & 26 deletions apps/vscode/src/test/quartoDoc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,34 @@ suite("Quarto basics", function () {
assert.equal(before, after);
});

test("Roundtrip changes roundtrip-changes.qmd", async function () {
// We want this test to fail locally so that we can reference the
// before/affter diff that Mocha logs, but we dont wan't CI to fail.
if (process.env['CI']) this.skip();
roundtripSnapshotTest('valid-basics.qmd');

const { doc } = await openAndShowTextDocument("roundtrip-changes.qmd");
roundtripSnapshotTest('valid-basics-2.qmd');

const { before, after } = await roundtrip(doc);

assert.equal(before, after);
});
roundtripSnapshotTest('valid-nesting.qmd');

test("Roundtripped valid-basics.qmd matches snapshot", async function () {
const { doc } = await openAndShowTextDocument("valid-basics.qmd");
roundtripSnapshotTest('invalid.qmd');

const { after } = await roundtrip(doc);

assert.equal(after, await readOrCreateSnapshot("roundtripped-valid-basics.qmd", after));
});

test("Roundtripped invalid.qmd matches snapshot", async function () {
const { doc } = await openAndShowTextDocument("invalid.qmd");

const { after } = await roundtrip(doc);
roundtripSnapshotTest('capsule-leak.qmd');
});

assert.equal(after, await readOrCreateSnapshot("roundtripped-invalid.qmd", after));
});
test("Roundtripped capsule-leak.qmd matches snapshot", async function () {
const { doc } = await openAndShowTextDocument("capsule-leak.qmd");
/**
*
* When the test is run on the dev's machine for the first time, saves the roundtripped file as a snapshot.
* All subsequent runs of the test compare the roundtripped file to that snapshot.
*
* Useful for capturing the behaviour of roundtripping at a point in time and testing against that.
*
* @param filename A .qmd file in the examples folder to snapshot test
*/
function roundtripSnapshotTest(filename: string) {
const snapshotFileName = `roundtripped-${filename}`;

test(`Roundtripped ${filename} matches snapshot`, async function () {
const { doc } = await openAndShowTextDocument(filename);

const { after } = await roundtrip(doc);

assert.equal(after, await readOrCreateSnapshot("roundtripped-capsule-leak.qmd", after));
assert.equal(after, await readOrCreateSnapshot(snapshotFileName, after));
});
});
}
15 changes: 14 additions & 1 deletion apps/vscode/src/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,28 @@ export async function roundtrip(doc: vscode.TextDocument) {
return { before, after };
}

const YELLOW_COLOR_ESCAPE_CODE = '\x1b[33m';
const RESET_COLOR_ESCAPE_CODE = '\x1b[0m';

export async function readOrCreateSnapshot(fileName: string, content: string) {
const snapshotUri = examplesUri(path.join('generated_snapshots', fileName));
try {
const doc = await vscode.workspace.openTextDocument(snapshotUri);
return doc.getText();
} catch {
if (process.env['CI']) throw 'Attempted to create snapshot in CI!';

console.warn(`${YELLOW_COLOR_ESCAPE_CODE}
⚠︎ Created snapshot in file:
${snapshotUri}
Please take a look at the snapshot file and ensure it is what you expect
If it looks good to you, please commit the generated snapshot along with your test code
If you did not intend to create a snapshot, please carefully check your test code and delete the snapshot file
${RESET_COLOR_ESCAPE_CODE}`);

await vscode.workspace.fs.writeFile(
snapshotUri,
Buffer.from(content, 'utf8')
Buffer.from(content, 'utf8') as Uint8Array
);
return content;
}
Expand Down