Skip to content

Commit

Permalink
Added new tests for shortcodes (especially keyworded arguments)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaput committed Feb 11, 2024
1 parent e8b06bd commit 2f0a56c
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/25-shortcode-firstuse/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This test demonstrates how to force the "first / next use" in shortcodes.

The `first_use` argument accepts "boolean" strings:

- `true`
- `false`
- `yes`
- `no`
- `y`
- `n`

It is also case-insensitive: `true`, `TRUE`, and `tRuE` are identical.
14 changes: 14 additions & 0 deletions tests/25-shortcode-firstuse/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# List Of Acronyms {#acronyms_HEADER_LOA .loa}

[RL]{#acronyms_RL}
: Reinforcement Learning

# Introduction {#intro}

This paragraph mentions [Reinforcement Learning (RL)](#acronyms_RL) for the first time.

And now, in this paragraph, [RL](#acronyms_RL) is in short form.

Here, we force the first use again: [Reinforcement Learning (RL)](#acronyms_RL).

And here in "next use" (also case-insensitive): [RL](#acronyms_RL).
16 changes: 16 additions & 0 deletions tests/25-shortcode-firstuse/input.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
acronyms:
keys:
- shortname: RL
longname: Reinforcement Learning
---

# Introduction {#intro}

This paragraph mentions {{< acr RL >}} for the first time.

And now, in this paragraph, {{< acr RL >}} is in short form.

Here, we force the first use again: {{< acr RL first_use=true >}}.

And here in "next use" (also case-insensitive): {{< acr RL first_use=FaLSe >}}.
12 changes: 12 additions & 0 deletions tests/26-shortcode-insertlinks/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This test demonstrates how to force insertion of links in shortcodes.

The `insert_links` argument accepts "boolean" strings:

- `true`
- `false`
- `yes`
- `no`
- `y`
- `n`

It is also case-insensitive: `true`, `TRUE`, and `tRuE` are identical.
10 changes: 10 additions & 0 deletions tests/26-shortcode-insertlinks/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# List Of Acronyms {#acronyms_HEADER_LOA .loa}

[RL]{#acronyms_RL}
: Reinforcement Learning

# Introduction {#intro}

This paragraph has a link: [Reinforcement Learning (RL)](#acronyms_RL).

But this one will not: RL.
12 changes: 12 additions & 0 deletions tests/26-shortcode-insertlinks/input.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
acronyms:
keys:
- shortname: RL
longname: Reinforcement Learning
---

# Introduction {#intro}

This paragraph has a link: {{< acr RL insert_links=true >}}.

But this one will not: {{< acr RL insert_links=false >}}.
2 changes: 2 additions & 0 deletions tests/27-shortcode-nonexisting/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This test demonstrates how to choose the behaviour when an acronym is not found
with shortcodes.
7 changes: 7 additions & 0 deletions tests/27-shortcode-nonexisting/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List Of Acronyms {#acronyms_HEADER_LOA .loa}

# Introduction {#intro}

The non-existing acronym will be replaced by "??": ??.

Here, with its key: RL.
2 changes: 2 additions & 0 deletions tests/27-shortcode-nonexisting/expected.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(W) [acronyms] Acronym key RL not recognized
(W) [acronyms] Acronym key RL not recognized
9 changes: 9 additions & 0 deletions tests/27-shortcode-nonexisting/input.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
acronyms: {}
---

# Introduction {#intro}

The non-existing acronym will be replaced by "??": {{< acr RL non_existing=?? >}}.

Here, with its key: {{< acr RL non_existing=key >}}.
3 changes: 3 additions & 0 deletions tests/run_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ const testDirs = [
'22-shortcode-simple',
'23-shortcode-specific-style',
'24-shortcode-listofacronyms',
'25-shortcode-firstuse',
'26-shortcode-insertlinks',
'27-shortcode-nonexisting',
];


Expand Down

0 comments on commit 2f0a56c

Please sign in to comment.