diff --git a/src/syntax/content/parser.rs b/src/syntax/content/parser.rs index 858e336..cfd5a1f 100644 --- a/src/syntax/content/parser.rs +++ b/src/syntax/content/parser.rs @@ -80,9 +80,8 @@ pub(super) fn read(text: &str, config: &Config) -> String { mod tests { use crate::{ types::Graph, - syntax::content::parser::{state::State, token::header::Level}, + syntax::content::parser::{token::header::Level}, }; - use token::{preformat::PreFormat}; use super::*; @@ -103,244 +102,6 @@ mod tests { assert_eq!(read_noconfig(en), html); } - #[test] - fn flanking_with_trailing_comma() { - assert_eq!( - read_noconfig("|Node|,"), - r#"
Node,
"# - ); - } - - #[test] - fn flanking_with_trailing_comma_and_space() { - assert_eq!( - read_noconfig("|Node|, at"), - r#"Node, at
"# - ); - } - - #[test] - fn flanking_at_eoi() { - assert_eq!( - read_noconfig("|Node|"), - r#""# - ); - } - - #[test] - fn needless_three_pipe_anchor() { - assert_eq!( - read_noconfig("|Node|Destination|"), - r#""# - ); - } - - #[test] - fn nonleading_second_pipe() { - assert_eq!( - read_noconfig("Go to Node|Destination|, here"), - r#"Go to Node, here
"#, - ); - } - - #[test] - fn anchor_to_node_s() { - assert_eq!( - read_noconfig("The |letter s|s|'s node: |s|!"), - r#""# - ); - } - - #[test] - fn nonleading_plural_anchor() { - assert_eq!( - read_noconfig("The flower|s bloomed"), - r#"The flowers bloomed
"# - ); - } - - #[test] - fn leading_plural_anchor() { - assert_eq!( - read_noconfig("Interfaces are |element|s of |system|s."), - r#"Interfaces are elements of systems.
"# - ); - } - - #[test] - fn nonleading_plural_anchor_at_eoi() { - assert_eq!( - read_noconfig("element|s"), - r#""# - ); - } - - #[test] - fn leading_plural_anchor_at_eoi() { - assert_eq!( - read_noconfig("|element|s"), - r#""# - ); - } - - #[test] - fn http_external_anchor() { - assert_eq!( - read_noconfig( - "a |false dichotomy|https://en.wikipedia.org/wiki/False_dilemma|." - ), - r#""# - ); - } - - #[test] - fn http_external_anchor_leading_no_third_then_newline() { - assert_eq!( - read_noconfig(concat!( - "|Rust toolchain|https://rustup.rs/", - "\n", - "at rustup.rs", - )), - concat!( - r#"Rust toolchain"#, - "\n", - "at rustup.rs
", - ) - ); - } - - #[test] - fn http_external_anchor_leading_no_third_then_space() { - assert_eq!( - read_noconfig("|Rust toolchain|https://rustup.rs/ at rustup.rs"), - r#"Rust toolchain at rustup.rs
"# - ); - } - - #[test] - fn http_external_anchor_leading_no_third_then_eoi() { - assert_eq!( - read_noconfig("|Rust toolchain|https://rustup.rs/"), - r#""# - ); - } - - #[test] - fn newline_wrapped_anchor() { - assert_eq!( - read_noconfig("\n|SomeAnchor|\n"), - concat!( - "\n", - r#""# - ), - ); - } - - #[test] - fn newline_separated_anchors() { - assert_eq!( - read_noconfig("|SomeAnchor|\n|SomeOtherAnchor|\n"), - concat!( - r#"SomeAnchor"#, - "\n", - r#"SomeOtherAnchor
"# - ) - ); - } - - #[test] - fn empty_line_separated_anchors() { - assert_eq!( - read_noconfig("|SomeAnchor|\n\n|SomeOtherAnchor|\n"), - concat!( - r#""#, - "\n", - "\n", - r#""# - ), - ); - } - - #[test] - fn homepage_footer() { - assert_eq!( - read_noconfig( - "made by jutty|https://jutty.dev • acknowledgments|Acknowledgments • |source code|https://codeberg.org/jutty/en" - ), - r#"made by jutty • acknowledgments • source code
"# - ); - } - - #[test] - fn trailing_anchor() { - assert_eq!( - read_noconfig("see acks|acks"), - r#"see acks
"# - ); - } - - #[test] - fn trailing_anchor_with_newline() { - assert_eq!( - read_noconfig("\nsee acks|acks\n"), - concat!("\n", r#"see acks
"#) - ); - } - - #[test] - fn trailing_oblique() { - assert_eq!(read_noconfig("see _acks_"), "see acks
"); - } - - #[test] - fn trailing_oblique_with_newline() { - assert_eq!(read_noconfig("see _acks_\n"), "see acks
"); - } - - #[test] - fn pre() { - let payload = "D0qdJ184f3q1okbYu3Xm1d93jj6jy615"; - assert_eq!( - read_noconfig(&format!("`\n{payload}\n`\n")), - format!("\n{payload}\n"),
- );
- }
-
- #[test]
- fn eoi_pre() {
- let payload = "Jp8INpWzsQmk20jpIhBFCfMUXOztxv0w";
- assert_eq!(
- read_noconfig(&format!("`\n{payload}\n`")),
- format!("\n{payload}\n"),
- );
- }
-
- #[test]
- #[should_panic(expected = "End of input with open header")]
- fn end_with_open_header() {
- let mut state = State::default();
- state.context.block = Block::Header(1);
-
- context::close(&state, &mut vec![]);
- }
-
- #[test]
- fn end_with_open_preformat() {
- let mut state = State::default();
- state.context.block = Block::PreFormat;
-
- let mut vec: VecNode,
"#); + } + + #[test] + fn flanking_with_trailing_comma_and_space() { + assert_eq!( + read("|Node|, at"), + r#"Node, at
"# + ); + } + + #[test] + fn flanking_at_eoi() { + assert_eq!(read("|Node|"), r#""#); + } + + #[test] + fn needless_three_pipe_anchor() { + assert_eq!( + read("|Node|Destination|"), + r#""# + ); + } + + #[test] + fn nonleading_second_pipe() { + assert_eq!( + read("Go to Node|Destination|, here"), + r#"Go to Node, here
"#, + ); + } + + #[test] + fn anchor_to_node_s() { + assert_eq!( + read("The |letter s|s|'s node: |s|!"), + r#""# + ); + } + + #[test] + fn nonleading_plural_anchor() { + assert_eq!( + read("The flower|s bloomed"), + r#"The flowers bloomed
"# + ); + } + + #[test] + fn leading_plural_anchor() { + assert_eq!( + read("Interfaces are |element|s of |system|s."), + r#"Interfaces are elements of systems.
"# + ); + } + + #[test] + fn nonleading_plural_anchor_at_eoi() { + assert_eq!( + read("element|s"), + r#""# + ); + } + + #[test] + fn leading_plural_anchor_at_eoi() { + assert_eq!( + read("|element|s"), + r#""# + ); + } + + #[test] + fn http_external_anchor() { + assert_eq!( + read( + "a |false dichotomy|https://en.wikipedia.org/wiki/False_dilemma|." + ), + r#""# + ); + } + + #[test] + fn http_external_anchor_leading_no_third_then_newline() { + assert_eq!( + read(concat!( + "|Rust toolchain|https://rustup.rs/", + "\n", + "at rustup.rs", + )), + concat!( + r#"Rust toolchain"#, + "\n", + "at rustup.rs
", + ) + ); + } + + #[test] + fn http_external_anchor_leading_no_third_then_space() { + assert_eq!( + read("|Rust toolchain|https://rustup.rs/ at rustup.rs"), + r#"Rust toolchain at rustup.rs
"# + ); + } + + #[test] + fn http_external_anchor_leading_no_third_then_eoi() { + assert_eq!( + read("|Rust toolchain|https://rustup.rs/"), + r#""# + ); + } + + #[test] + fn newline_wrapped_anchor() { + assert_eq!( + read("\n|SomeAnchor|\n"), + concat!( + "\n", + r#""# + ), + ); + } + + #[test] + fn newline_separated_anchors() { + assert_eq!( + read("|SomeAnchor|\n|SomeOtherAnchor|\n"), + concat!( + r#"SomeAnchor"#, + "\n", + r#"SomeOtherAnchor
"# + ) + ); + } + + #[test] + fn empty_line_separated_anchors() { + assert_eq!( + read("|SomeAnchor|\n\n|SomeOtherAnchor|\n"), + concat!( + r#""#, + "\n", + "\n", + r#""# + ), + ); + } + + #[test] + fn trailing_anchor() { + assert_eq!( + read("see acks|acks"), + r#"see acks
"# + ); + } + + #[test] + fn trailing_anchor_with_newline() { + assert_eq!( + read("\nsee acks|acks\n"), + concat!("\n", r#"see acks
"#) + ); + } + #[test] fn indifferent_trailing_pipe() { - assert_eq!(read_noconfig("|a|a|"), read_noconfig("a|a|")); + assert_eq!(read("|a|a|"), read("a|a|")); } #[test] fn indifferent_leading_pipe() { - assert_eq!(read_noconfig("|a|a|"), read_noconfig("|a|a")); + assert_eq!(read("|a|a|"), read("|a|a")); } #[test] fn indifferent_multiline_trailing_pipe() { - assert_eq!(read_noconfig("|a|a|\nn"), read_noconfig("a|a|\nn")); + assert_eq!(read("|a|a|\nn"), read("a|a|\nn")); } #[test] fn indifferent_multiline_leading_pipe() { - assert_eq!(read_noconfig("|a|a|\nn"), read_noconfig("|a|a\nn")); + assert_eq!(read("|a|a|\nn"), read("|a|a\nn")); } } diff --git a/src/syntax/content/parser/context/block.rs b/src/syntax/content/parser/context/block.rs index a163570..677903e 100644 --- a/src/syntax/content/parser/context/block.rs +++ b/src/syntax/content/parser/context/block.rs @@ -71,3 +71,68 @@ pub fn parse( } false } + +#[cfg(test)] +mod tests { + + use crate::{ + types::Graph, + syntax::content::{ + parser, + parser::{ + token::{preformat::PreFormat}, + state::State, + token::header::Level, + Block, context, Token, + }, + }, + }; + + fn read(input: &str) -> String { + parser::read(input, &Graph::new(None).meta.config) + } + + #[test] + fn pre() { + let payload = "D0qdJ184f3q1okbYu3Xm1d93jj6jy615"; + assert_eq!( + read(&format!("`\n{payload}\n`\n")), + format!("\n{payload}\n"),
+ );
+ }
+
+ #[test]
+ fn eoi_pre() {
+ let payload = "Jp8INpWzsQmk20jpIhBFCfMUXOztxv0w";
+ assert_eq!(
+ read(&format!("`\n{payload}\n`")),
+ format!("\n{payload}\n"),
+ );
+ }
+
+ #[test]
+ #[should_panic(expected = "End of input with open header")]
+ fn end_with_open_header() {
+ let mut state = State::default();
+ state.context.block = Block::Header(1);
+
+ context::close(&state, &mut vec![]);
+ }
+
+ #[test]
+ fn end_with_open_preformat() {
+ let mut state = State::default();
+ state.context.block = Block::PreFormat;
+
+ let mut vec: Vecthis anchor is oblique as are these literals but not these just these, not this and these with an anchor again
"# ); } + + #[test] + fn trailing_oblique() { + assert_eq!(read("see _acks_"), "see acks
"); + } + + #[test] + fn trailing_oblique_with_newline() { + assert_eq!(read("see _acks_\n"), "see acks
"); + } }