diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-14 12:15:17 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-14 12:15:17 +0200 |
commit | 0e4c4b5e63efd2a2bee038e69faf1aedb14a2043 (patch) | |
tree | 7077b4396d5a4d4f48c15ebc0f938d3d07862970 | |
parent | 5f6ed1864018bbf3816a8e2d0583166289aa456d (diff) | |
download | markdown-rs-0e4c4b5e63efd2a2bee038e69faf1aedb14a2043.tar.gz markdown-rs-0e4c4b5e63efd2a2bee038e69faf1aedb14a2043.tar.bz2 markdown-rs-0e4c4b5e63efd2a2bee038e69faf1aedb14a2043.zip |
Add some tests for mdx parse types, `must_use`
-rw-r--r-- | src/lib.rs | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -198,6 +198,7 @@ pub enum MdxExpressionKind { /// Can be passed as `mdx_expression_parse` in [`ParseOptions`][] to support /// expressions according to a certain grammar (typically, a programming /// language). +/// pub type MdxExpressionParse = dyn Fn(&str, &MdxExpressionKind) -> MdxSignal; /// Control which constructs are enabled. @@ -1579,6 +1580,9 @@ mod tests { #[test] fn test_constructs() { + #![allow(unused_must_use)] + Constructs::default(); + let constructs = Constructs::default(); assert!(constructs.attention, "should default to `CommonMark` (1)"); assert!( @@ -1618,6 +1622,9 @@ mod tests { #[test] fn test_parse_options() { + #![allow(unused_must_use)] + ParseOptions::default(); + let options = ParseOptions::default(); assert!( options.constructs.attention, @@ -1682,6 +1689,9 @@ mod tests { #[test] fn test_compile_options() { + #![allow(unused_must_use)] + CompileOptions::default(); + let options = CompileOptions::default(); assert!( !options.allow_dangerous_html, @@ -1705,6 +1715,9 @@ mod tests { #[test] fn test_options() { + #![allow(unused_must_use)] + Options::default(); + let options = Options::default(); assert!( options.parse.constructs.attention, @@ -1744,6 +1757,9 @@ mod tests { #[test] fn test_to_html() { + #![allow(unused_must_use)] + to_html("a"); + assert_eq!( to_html("a"), "<p>a</p>", @@ -1753,6 +1769,9 @@ mod tests { #[test] fn test_to_html_with_options() { + #![allow(unused_must_use)] + to_html_with_options("a", &Options::default()); + assert_eq!( to_html_with_options("a", &Options::default()).unwrap(), "<p>a</p>", @@ -1762,6 +1781,9 @@ mod tests { #[test] fn test_to_mdast() { + #![allow(unused_must_use)] + to_mdast("a", &ParseOptions::default()); + assert!( matches!( to_mdast("a", &ParseOptions::default()).unwrap(), @@ -1770,4 +1792,42 @@ mod tests { "should support turning markdown into mdast with `to_mdast`" ); } + + #[test] + fn test_mdx_expression_parse() { + fn func(_value: &str, _kind: &MdxExpressionKind) -> MdxSignal { + MdxSignal::Ok + } + + let func_accepting = |_a: Box<MdxExpressionParse>| true; + + assert!( + matches!(func("a", &MdxExpressionKind::Expression), MdxSignal::Ok), + "should expose an `MdxExpressionParse` type (1)" + ); + + assert!( + func_accepting(Box::new(func)), + "should expose an `MdxExpressionParse` type (2)" + ); + } + + #[test] + fn test_mdx_esm_parse() { + fn func(_value: &str) -> MdxSignal { + MdxSignal::Ok + } + + let func_accepting = |_a: Box<MdxEsmParse>| true; + + assert!( + matches!(func("a"), MdxSignal::Ok), + "should expose an `MdxEsmParse` type (1)" + ); + + assert!( + func_accepting(Box::new(func)), + "should expose an `MdxEsmParse` type (2)" + ); + } } |