Skip to content

Commit 6480394

Browse files
committed
Add some more tests to find regression more easily
1 parent f9a5413 commit 6480394

2 files changed

Lines changed: 146 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: "Code annotations with highlight-style: none"
3+
highlight-style: none
4+
format:
5+
latex: default
6+
_quarto:
7+
tests:
8+
latex:
9+
ensureFileRegexMatches:
10+
# matches: With highlighting disabled, LaTeX uses verbatim with (1) annotation
11+
# noMatches: Should NOT have syntax highlighting tokens
12+
- ['\(1\)', '\\circled\{1\}', "Variable assignment"]
13+
- ['\\CommentTok', '\\begin\{Shaded\}']
14+
---
15+
16+
Code with annotation using deprecated highlight-style option:
17+
18+
```python
19+
x = 1 # <1>
20+
```
21+
1. Variable assignment
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* text-highlighting.test.ts
3+
*
4+
* Copyright (C) 2020-2022 Posit Software, PBC
5+
*/
6+
7+
import { unitTest } from "../test.ts";
8+
import { assertEquals } from "testing/asserts";
9+
import {
10+
hasAdaptiveTheme,
11+
hasTextHighlighting,
12+
isAdaptiveTheme,
13+
} from "../../src/quarto-core/text-highlighting.ts";
14+
import { FormatPandoc } from "../../src/config/types.ts";
15+
16+
// deno-lint-ignore require-await
17+
unitTest("text-highlighting - returns true when no options set (default applies)", async () => {
18+
const pandoc: FormatPandoc = {};
19+
assertEquals(hasTextHighlighting(pandoc), true);
20+
});
21+
22+
// deno-lint-ignore require-await
23+
unitTest("text-highlighting - returns false when disabled with 'none'", async () => {
24+
const pandoc: FormatPandoc = { "syntax-highlighting": "none" };
25+
assertEquals(hasTextHighlighting(pandoc), false);
26+
});
27+
28+
// deno-lint-ignore require-await
29+
unitTest("text-highlighting - returns true for explicit theme", async () => {
30+
const pandoc: FormatPandoc = { "syntax-highlighting": "github" };
31+
assertEquals(hasTextHighlighting(pandoc), true);
32+
});
33+
34+
// deno-lint-ignore require-await
35+
unitTest("text-highlighting - returns true for deprecated highlight-style", async () => {
36+
const pandoc: FormatPandoc = { "highlight-style": "monokai" };
37+
assertEquals(hasTextHighlighting(pandoc), true);
38+
});
39+
40+
// deno-lint-ignore require-await
41+
unitTest("text-highlighting - syntax-highlighting takes precedence over highlight-style", async () => {
42+
// New option takes precedence - "none" disables regardless of deprecated option
43+
const pandoc: FormatPandoc = {
44+
"syntax-highlighting": "none",
45+
"highlight-style": "github",
46+
};
47+
// "none" is truthy so it's selected, then hasTextHighlighting returns false
48+
assertEquals(hasTextHighlighting(pandoc), false);
49+
});
50+
51+
// deno-lint-ignore require-await
52+
unitTest("text-highlighting - returns false for deprecated highlight-style: none", async () => {
53+
const pandoc: FormatPandoc = { "highlight-style": "none" };
54+
assertEquals(hasTextHighlighting(pandoc), false);
55+
});
56+
57+
// isAdaptiveTheme tests
58+
59+
// deno-lint-ignore require-await
60+
unitTest("isAdaptiveTheme - returns true for known adaptive themes", async () => {
61+
const adaptiveThemes = [
62+
"a11y",
63+
"arrow",
64+
"atom-one",
65+
"ayu",
66+
"breeze",
67+
"github",
68+
"gruvbox",
69+
"monochrome",
70+
];
71+
for (const theme of adaptiveThemes) {
72+
assertEquals(isAdaptiveTheme(theme), true, `Expected ${theme} to be adaptive`);
73+
}
74+
});
75+
76+
// deno-lint-ignore require-await
77+
unitTest("isAdaptiveTheme - returns false for non-adaptive themes", async () => {
78+
const nonAdaptiveThemes = ["monokai", "tango", "zenburn", "kate", "pygments"];
79+
for (const theme of nonAdaptiveThemes) {
80+
assertEquals(isAdaptiveTheme(theme), false, `Expected ${theme} to be non-adaptive`);
81+
}
82+
});
83+
84+
// deno-lint-ignore require-await
85+
unitTest("isAdaptiveTheme - returns true for object with dark and light", async () => {
86+
const theme = { dark: "monokai", light: "tango" };
87+
assertEquals(isAdaptiveTheme(theme), true);
88+
});
89+
90+
// deno-lint-ignore require-await
91+
unitTest("isAdaptiveTheme - returns false for object without both dark and light", async () => {
92+
// Only dark
93+
assertEquals(isAdaptiveTheme({ dark: "monokai" }), false);
94+
// Only light
95+
assertEquals(isAdaptiveTheme({ light: "tango" }), false);
96+
// Neither (empty object)
97+
assertEquals(isAdaptiveTheme({}), false);
98+
});
99+
100+
// hasAdaptiveTheme tests
101+
102+
// deno-lint-ignore require-await
103+
unitTest("hasAdaptiveTheme - returns true for adaptive syntax-highlighting", async () => {
104+
const pandoc: FormatPandoc = { "syntax-highlighting": "github" };
105+
assertEquals(hasAdaptiveTheme(pandoc), true);
106+
});
107+
108+
// deno-lint-ignore require-await
109+
unitTest("hasAdaptiveTheme - returns false for non-adaptive theme", async () => {
110+
const pandoc: FormatPandoc = { "syntax-highlighting": "monokai" };
111+
assertEquals(hasAdaptiveTheme(pandoc), false);
112+
});
113+
114+
// deno-lint-ignore require-await
115+
unitTest("hasAdaptiveTheme - returns true for deprecated highlight-style", async () => {
116+
const pandoc: FormatPandoc = { "highlight-style": "github" };
117+
assertEquals(hasAdaptiveTheme(pandoc), true);
118+
});
119+
120+
// deno-lint-ignore require-await
121+
unitTest("hasAdaptiveTheme - uses default theme when nothing set", async () => {
122+
// Default theme is "arrow" which is adaptive
123+
const pandoc: FormatPandoc = {};
124+
assertEquals(hasAdaptiveTheme(pandoc), true);
125+
});

0 commit comments

Comments
 (0)