Update tests to compile again.
This commit is contained in:
@@ -239,67 +239,56 @@ fn get_context_item_indent<'r, 's>(context: Context<'r, 's>) -> Option<&'r usize
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ContextTree;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use crate::parser::Source;
|
||||
|
||||
#[test]
|
||||
fn plain_list_item_empty() {
|
||||
let input = "1.";
|
||||
let input = OrgSource::new("1.");
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(&document_context);
|
||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(&initial_context);
|
||||
let (remaining, result) = plain_list_item_matcher(input).unwrap();
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(Into::<&str>::into(remaining), "");
|
||||
assert_eq!(result.source, "1.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_list_item_simple() {
|
||||
let input = "1. foo";
|
||||
let input = OrgSource::new("1. foo");
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(&document_context);
|
||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(&initial_context);
|
||||
let (remaining, result) = plain_list_item_matcher(input).unwrap();
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(Into::<&str>::into(remaining), "");
|
||||
assert_eq!(result.source, "1. foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_list_empty() {
|
||||
let input = "1.";
|
||||
let input = OrgSource::new("1.");
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&initial_context);
|
||||
let (remaining, result) = plain_list_matcher(input).unwrap();
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(Into::<&str>::into(remaining), "");
|
||||
assert_eq!(result.source, "1.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_list_simple() {
|
||||
let input = "1. foo";
|
||||
let input = OrgSource::new("1. foo");
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&initial_context);
|
||||
let (remaining, result) = plain_list_matcher(input).unwrap();
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(Into::<&str>::into(remaining), "");
|
||||
assert_eq!(result.source, "1. foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_list_cant_start_line_with_asterisk() {
|
||||
// Plain lists with an asterisk bullet must be indented or else they would be a headline
|
||||
let input = "* foo";
|
||||
let input = OrgSource::new("* foo");
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&initial_context);
|
||||
let result = plain_list_matcher(input);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
@@ -307,32 +296,30 @@ mod tests {
|
||||
#[test]
|
||||
fn indented_can_start_line_with_asterisk() {
|
||||
// Plain lists with an asterisk bullet must be indented or else they would be a headline
|
||||
let input = " * foo";
|
||||
let input = OrgSource::new(" * foo");
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(&initial_context);
|
||||
let result = plain_list_matcher(input);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_blank_lines_ends_list() {
|
||||
let input = r#"1. foo
|
||||
let input = OrgSource::new(
|
||||
r#"1. foo
|
||||
2. bar
|
||||
baz
|
||||
3. lorem
|
||||
|
||||
|
||||
ipsum
|
||||
"#;
|
||||
"#,
|
||||
);
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(element(true))(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(element(true))(&initial_context);
|
||||
let (remaining, result) =
|
||||
plain_list_matcher(input).expect("Should parse the plain list successfully.");
|
||||
assert_eq!(remaining, " ipsum\n");
|
||||
assert_eq!(Into::<&str>::into(remaining), " ipsum\n");
|
||||
assert_eq!(
|
||||
result.get_source(),
|
||||
r#"1. foo
|
||||
@@ -347,18 +334,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn two_blank_lines_ends_nested_list() {
|
||||
let input = r#"1. foo
|
||||
let input = OrgSource::new(
|
||||
r#"1. foo
|
||||
1. bar
|
||||
|
||||
|
||||
baz"#;
|
||||
baz"#,
|
||||
);
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(element(true))(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(element(true))(&initial_context);
|
||||
let (remaining, result) =
|
||||
plain_list_matcher(input).expect("Should parse the plain list successfully.");
|
||||
assert_eq!(remaining, "baz");
|
||||
assert_eq!(Into::<&str>::into(remaining), "baz");
|
||||
assert_eq!(
|
||||
result.get_source(),
|
||||
r#"1. foo
|
||||
@@ -371,7 +358,8 @@ baz"#;
|
||||
|
||||
#[test]
|
||||
fn interior_trailing_whitespace() {
|
||||
let input = r#"1. foo
|
||||
let input = OrgSource::new(
|
||||
r#"1. foo
|
||||
|
||||
bar
|
||||
|
||||
@@ -382,14 +370,13 @@ baz"#;
|
||||
ipsum
|
||||
|
||||
|
||||
dolar"#;
|
||||
dolar"#,
|
||||
);
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let document_context =
|
||||
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||
let plain_list_matcher = parser_with_context!(element(true))(&document_context);
|
||||
let plain_list_matcher = parser_with_context!(element(true))(&initial_context);
|
||||
let (remaining, result) =
|
||||
plain_list_matcher(input).expect("Should parse the plain list successfully.");
|
||||
assert_eq!(remaining, "dolar");
|
||||
assert_eq!(Into::<&str>::into(remaining), "dolar");
|
||||
assert_eq!(
|
||||
result.get_source(),
|
||||
r#"1. foo
|
||||
|
||||
Reference in New Issue
Block a user