Skip to content

Commit

Permalink
Test sourcepos for all NodeValue variants
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn committed Dec 13, 2024
1 parent 612abd4 commit 38f2403
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 7 deletions.
31 changes: 30 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ caseless = "0.2.1"

[dev-dependencies]
ntest = "0.9"
strum = { version = "0.26.3", features = ["derive"] }
toml = "0.7.3"

[features]
Expand Down
11 changes: 8 additions & 3 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ pub use crate::parser::multiline_block_quote::NodeMultilineBlockQuote;

/// The core AST node enum.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(test, derive(strum::EnumDiscriminants))]
#[cfg_attr(
test,
strum_discriminants(vis(pub(crate)), derive(strum::VariantArray, Hash))
)]
pub enum NodeValue {
/// The root of every CommonMark document. Contains **blocks**.
Document,
Expand Down Expand Up @@ -246,7 +251,7 @@ pub struct NodeTable {
}

/// An inline [code span](https://github.github.com/gfm/#code-spans).
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct NodeCode {
/// The number of backticks
pub num_backticks: usize,
Expand All @@ -259,7 +264,7 @@ pub struct NodeCode {
}

/// The details of a link's destination, or an image's source.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct NodeLink {
/// The URL for the link destination or image source.
pub url: String,
Expand All @@ -272,7 +277,7 @@ pub struct NodeLink {
}

/// The details of a wikilink's destination.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct NodeWikiLink {
/// The URL for the link destination.
pub url: String,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/math.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// An inline math span
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct NodeMath {
/// Whether this is dollar math (`$` or `$$`).
/// `false` indicates it is code math
Expand All @@ -8,7 +8,7 @@ pub struct NodeMath {
/// Whether this is display math (using `$$`)
pub display_math: bool,

/// The literal contents of the math span.
/// The literal contents of the math span.
/// As the contents are not interpreted as Markdown at all,
/// they are contained within this structure,
/// rather than inserted into a child inline of any kind.
Expand Down
2 changes: 1 addition & 1 deletion src/parser/multiline_block_quote.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// The metadata of a multiline blockquote.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct NodeMultilineBlockQuote {
/// The length of the fence.
pub fence_length: usize,
Expand Down
2 changes: 2 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod plugins;
mod regressions;
mod rewriter;
mod shortcodes;
#[path = "tests/sourcepos.rs"]
mod sourcepos_;
mod spoiler;
mod strikethrough;
mod subscript;
Expand Down
Loading

0 comments on commit 38f2403

Please sign in to comment.