Skip to content

Commit

Permalink
fix: improve snaptest rendering and add more inline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfejzic committed Aug 19, 2023
1 parent 9ef866d commit 4896019
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 48 deletions.
38 changes: 15 additions & 23 deletions inline/tests/parser/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,7 @@ impl AsSnapshot for Snapshot<&VecDeque<Inline>> {

impl AsSnapshot for Snapshot<&Inline> {
fn as_snapshot(&self) -> String {
let start = match self.0 {
Inline::Bold(_) => "Bold",
Inline::Italic(_) => "Italic",
Inline::Underline(_) => "Underline",
Inline::Subscript(_) => "Subscript",
Inline::Superscript(_) => "Superscript",
Inline::Overline(_) => "Overline",
Inline::Strikethrough(_) => "Strikethrough",
Inline::Highlight(_) => "Highlight",
Inline::Verbatim(_) => "Verbatim",
Inline::Quote(_) => "Quote",
Inline::Math(_) => "Math",
Inline::Parentheses(_) => "Parentheses",
Inline::TextGroup(_) => "TextGroup",
Inline::Attributes(_) => "Attributes",
Inline::Substitution(_) => "Substitution",
Inline::Newline(_) => "Newline",
Inline::Whitespace(_) => "Whitespace",
Inline::EndOfLine(_) => "EndOfLine",
Inline::Plain(_) => "Plain",
Inline::Multiple(_) => "Multiple",
};

let start = self.variant_str();
let inner = Snapshot::snap(self.inner());

let mut res = String::from(start);
Expand All @@ -62,6 +40,20 @@ impl AsSnapshot for Snapshot<&Inline> {
res.push_str(" ");
res.push_str(content);
res.push('\n');

if matches!(
self.0,
Inline::Plain(_)
| Inline::Verbatim(_)
| Inline::Parentheses(_)
| Inline::Newline(_)
| Inline::Whitespace(_)
| Inline::EndOfLine(_)
) {
res.push_str(" ");
res.push_str(&"^".repeat(self.span().len_grapheme().unwrap_or(1)));
res.push('\n');
}
}

res.push_str(")\n");
Expand Down
12 changes: 9 additions & 3 deletions inline/tests/spec/snapshots/lexer/bold/bold-not-bold.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: inline/tests/lexer/mod.rs
info: "Test 'bold-not-bold' from: 'bold.yml'"
info: "Test 'bold-not-bold' from 'bold.yml'"
---
**Bold** not bold.
**
Expand All @@ -9,8 +9,14 @@ info: "Test 'bold-not-bold' from: 'bold.yml'"
^^^^ -> Plain @ (1:3)->(1:7)
**
^^ -> Bold @ (1:7)->(1:9)
not bold.
^^^^^^^^^^ -> Plain @ (1:9)->(1:19)

^ -> Whitespace @ (1:9)->(1:10)
not
^^^ -> Plain @ (1:10)->(1:13)

^ -> Whitespace @ (1:13)->(1:14)
bold.
^^^^^ -> Plain @ (1:14)->(1:19)
^ -> Newline @ (1:19)->(2:1)

Expand Down
14 changes: 11 additions & 3 deletions inline/tests/spec/snapshots/lexer/bold/not-bold.snap
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
---
source: inline/tests/lexer/mod.rs
info: "Test 'not-bold' from: 'bold.yml'"
info: "Test 'not-bold' from 'bold.yml'"
---
** not bold **
**
^^ -> Plain @ (1:1)->(1:3)
not bold
^^^^^^^^^^ -> Plain @ (1:3)->(1:13)

^ -> Whitespace @ (1:3)->(1:4)
not
^^^ -> Plain @ (1:4)->(1:7)

^ -> Whitespace @ (1:7)->(1:8)
bold
^^^^ -> Plain @ (1:8)->(1:12)

^ -> Whitespace @ (1:12)->(1:13)
**
^^ -> Plain @ (1:13)->(1:15)
Expand Down
12 changes: 9 additions & 3 deletions inline/tests/spec/snapshots/lexer/bold/not-closed-bold.snap
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
---
source: inline/tests/lexer/mod.rs
info: "Test 'not-closed-bold' from: 'bold.yml'"
info: "Test 'not-closed-bold' from 'bold.yml'"
---
**not bold **
**
^^ -> Plain @ (1:1)->(1:3)
not bold
^^^^^^^^^ -> Plain @ (1:3)->(1:12)
not
^^^ -> Plain @ (1:3)->(1:6)

^ -> Whitespace @ (1:6)->(1:7)
bold
^^^^ -> Plain @ (1:7)->(1:11)

^ -> Whitespace @ (1:11)->(1:12)
**
^^ -> Plain @ (1:12)->(1:14)
Expand Down
12 changes: 9 additions & 3 deletions inline/tests/spec/snapshots/lexer/bold/not-opened-bold.snap
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
---
source: inline/tests/lexer/mod.rs
info: "Test 'not-opened-bold' from: 'bold.yml'"
info: "Test 'not-opened-bold' from 'bold.yml'"
---
** not bold**
**
^^ -> Plain @ (1:1)->(1:3)
not bold
^^^^^^^^^ -> Plain @ (1:3)->(1:12)

^ -> Whitespace @ (1:3)->(1:4)
not
^^^ -> Plain @ (1:4)->(1:7)

^ -> Whitespace @ (1:7)->(1:8)
bold
^^^^ -> Plain @ (1:8)->(1:12)
**
^^ -> Plain @ (1:12)->(1:14)
Expand Down
26 changes: 23 additions & 3 deletions inline/tests/spec/snapshots/lexer/plain/breaking-unicode.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
---
source: inline/tests/lexer/mod.rs
info: "Test 'breaking-unicode' from: 'plain.yml'"
info: "Test 'breaking-unicode' from 'plain.yml'"
---
The character 𝛂 broke some stuff.
The character 𝛂 broke some stuff.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -> Plain @ (1:1)->(1:34)
The
^^^ -> Plain @ (1:1)->(1:4)

^ -> Whitespace @ (1:4)->(1:5)
character
^^^^^^^^^ -> Plain @ (1:5)->(1:14)

^ -> Whitespace @ (1:14)->(1:15)
𝛂
^ -> Plain @ (1:15)->(1:16)

^ -> Whitespace @ (1:16)->(1:17)
broke
^^^^^ -> Plain @ (1:17)->(1:22)

^ -> Whitespace @ (1:22)->(1:23)
some
^^^^ -> Plain @ (1:23)->(1:27)

^ -> Whitespace @ (1:27)->(1:28)
stuff.
^^^^^^ -> Plain @ (1:28)->(1:34)
^ -> Newline @ (1:34)->(2:1)

Expand Down
10 changes: 7 additions & 3 deletions inline/tests/spec/snapshots/lexer/plain/simple-plain.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
---
source: inline/tests/lexer/mod.rs
info: "Test 'simple-plain' from: 'plain.yml'"
info: "Test 'simple-plain' from 'plain.yml'"
---
Simple text.
Simple text.
^^^^^^^^^^^^ -> Plain @ (1:1)->(1:13)
Simple
^^^^^^ -> Plain @ (1:1)->(1:7)

^ -> Whitespace @ (1:7)->(1:8)
text.
^^^^^ -> Plain @ (1:8)->(1:13)
^ -> Newline @ (1:13)->(2:1)

Expand Down
4 changes: 3 additions & 1 deletion inline/tests/spec/snapshots/parser/bold/bold-not-bold.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'bold-not-bold' from: 'bold.yml'"
info: "Test 'bold-not-bold' from 'bold.yml'"
---
Bold @ (1:1)->(1:9) (
Plain @ (1:3)->(1:7) (
Bold
^^^^
)
)
Plain @ (1:9)->(1:19) (
not bold.
^^^^^^^^^^
)

---
Expand Down
3 changes: 2 additions & 1 deletion inline/tests/spec/snapshots/parser/bold/not-bold.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'not-bold' from: 'bold.yml'"
info: "Test 'not-bold' from 'bold.yml'"
---
Plain @ (1:1)->(1:15) (
** not bold **
^^^^^^^^^^^^^^
)

---
Expand Down
3 changes: 2 additions & 1 deletion inline/tests/spec/snapshots/parser/bold/not-closed-bold.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'not-closed-bold' from: 'bold.yml'"
info: "Test 'not-closed-bold' from 'bold.yml'"
---
Plain @ (1:1)->(1:14) (
**not bold **
^^^^^^^^^^^^^
)

---
Expand Down
3 changes: 2 additions & 1 deletion inline/tests/spec/snapshots/parser/bold/not-opened-bold.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'not-opened-bold' from: 'bold.yml'"
info: "Test 'not-opened-bold' from 'bold.yml'"
---
Plain @ (1:1)->(1:14) (
** not bold**
^^^^^^^^^^^^^
)

---
Expand Down
3 changes: 2 additions & 1 deletion inline/tests/spec/snapshots/parser/bold/simple-bold.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'simple-bold' from: 'bold.yml'"
info: "Test 'simple-bold' from 'bold.yml'"
---
Bold @ (1:1)->(1:9) (
Plain @ (1:3)->(1:7) (
Bold
^^^^
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'breaking-unicode' from: 'plain.yml'"
info: "Test 'breaking-unicode' from 'plain.yml'"
---
Plain @ (1:1)->(1:34) (
The character 𝛂 broke some stuff.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)

---
Expand Down
3 changes: 2 additions & 1 deletion inline/tests/spec/snapshots/parser/plain/simple-plain.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
source: inline/tests/parser/mod.rs
info: "Test 'simple-plain' from: 'plain.yml'"
info: "Test 'simple-plain' from 'plain.yml'"
---
Plain @ (1:1)->(1:13) (
Simple text.
^^^^^^^^^^^^
)

---
Expand Down

0 comments on commit 4896019

Please sign in to comment.