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#"

Node

"# - ); - } - - #[test] - fn needless_three_pipe_anchor() { - assert_eq!( - read_noconfig("|Node|Destination|"), - r#"

Node

"# - ); - } - - #[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#"

The letter s's node: s!

"# - ); - } - - #[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#"

elements

"# - ); - } - - #[test] - fn leading_plural_anchor_at_eoi() { - assert_eq!( - read_noconfig("|element|s"), - r#"

elements

"# - ); - } - - #[test] - fn http_external_anchor() { - assert_eq!( - read_noconfig( - "a |false dichotomy|https://en.wikipedia.org/wiki/False_dilemma|." - ), - r#"

a false dichotomy.

"# - ); - } - - #[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#"

Rust toolchain

"# - ); - } - - #[test] - fn newline_wrapped_anchor() { - assert_eq!( - read_noconfig("\n|SomeAnchor|\n"), - concat!( - "\n", - r#"

SomeAnchor

"# - ), - ); - } - - #[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#"

SomeAnchor

"#, - "\n", - "\n", - r#"

SomeOtherAnchor

"# - ), - ); - } - - #[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 juttyacknowledgmentssource 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: Vec = vec![]; - context::close(&state, &mut vec); - assert_eq!(vec, vec![Token::PreFormat(PreFormat::new(false))]); - } - - #[test] - fn truncated_header_level() { - let u: usize = 999; - let level = Level::from(u); - assert_eq!(level.to_string(), "6"); - } - #[test] fn display_level() { assert_eq!(format!("{}", Level::One), "1"); diff --git a/src/syntax/content/parser/context/anchor.rs b/src/syntax/content/parser/context/anchor.rs index 4902ac9..94e7dd4 100644 --- a/src/syntax/content/parser/context/anchor.rs +++ b/src/syntax/content/parser/context/anchor.rs @@ -139,27 +139,195 @@ pub fn parse( mod tests { use crate::{syntax::content::parser, types::Graph}; - fn read_noconfig(input: &str) -> String { + fn read(input: &str) -> String { parser::read(input, &Graph::new(None).meta.config) } + #[test] + fn flanking_with_trailing_comma() { + assert_eq!(read("|Node|,"), r#"

Node,

"#); + } + + #[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#"

Node

"#); + } + + #[test] + fn needless_three_pipe_anchor() { + assert_eq!( + read("|Node|Destination|"), + r#"

Node

"# + ); + } + + #[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#"

The letter s's node: s!

"# + ); + } + + #[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#"

elements

"# + ); + } + + #[test] + fn leading_plural_anchor_at_eoi() { + assert_eq!( + read("|element|s"), + r#"

elements

"# + ); + } + + #[test] + fn http_external_anchor() { + assert_eq!( + read( + "a |false dichotomy|https://en.wikipedia.org/wiki/False_dilemma|." + ), + r#"

a false dichotomy.

"# + ); + } + + #[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#"

Rust toolchain

"# + ); + } + + #[test] + fn newline_wrapped_anchor() { + assert_eq!( + read("\n|SomeAnchor|\n"), + concat!( + "\n", + r#"

SomeAnchor

"# + ), + ); + } + + #[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#"

SomeAnchor

"#, + "\n", + "\n", + r#"

SomeOtherAnchor

"# + ), + ); + } + + #[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: Vec = vec![]; + context::close(&state, &mut vec); + assert_eq!(vec, vec![Token::PreFormat(PreFormat::new(false))]); + } + + #[test] + fn truncated_header_level() { + let u: usize = 999; + let level = Level::from(u); + assert_eq!(level.to_string(), "6"); + } +} diff --git a/src/syntax/content/parser/point.rs b/src/syntax/content/parser/point.rs index 09b44e9..3d78586 100644 --- a/src/syntax/content/parser/point.rs +++ b/src/syntax/content/parser/point.rs @@ -24,17 +24,27 @@ pub fn parse( mod tests { use crate::{syntax::content::parser, types::Graph}; - fn read_noconfig(input: &str) -> String { + fn read(input: &str) -> String { parser::read(input, &Graph::new(None).meta.config) } #[test] fn oblique() { assert_eq!( - read_noconfig( + read( "_|this anchor is oblique|o as are these literals_ but not these _just these_, not this _and these with an |anchor| again_" ), r#"

this 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

"); + } }