use super::*;
#[test]
fn processes_html_and_tables() {
let input = vec![
"<table><tr><td>A</td><td>B</td></tr></table>".to_string(),
"| X | Y |".to_string(),
"|---|---|".to_string(),
"| 1 | 2 |".to_string(),
];
let output = process_stream(&input);
assert!(output.iter().any(|l| l.contains("| A | B |")));
assert!(output.iter().any(|l| l.contains("| X | Y |")));
}
#[test]
fn no_wrap_option() {
let input = vec!["| a | b |".to_string(), "| 1 | 2 |".to_string()];
let out = process_stream_no_wrap(&input);
assert_eq!(out, vec!["| a | b |", "| 1 | 2 |"]);
}
#[test]
fn integrates_code_emphasis_flag() {
let input = vec!["`X`** Y (in **`Z`**)**".to_string()];
let out = process_stream_inner(
&input,
Options {
code_emphasis: true,
..Default::default()
},
);
assert_eq!(out, vec!["**`X` Y (in `Z`)**"]);
}
#[test]
fn converts_headings_when_enabled() {
let input = vec![
"Heading".to_string(),
"====".to_string(),
"Paragraph".to_string(),
];
let disabled = process_stream_inner(
&input,
Options {
headings: false,
..Default::default()
},
);
assert_eq!(disabled, input);
let enabled = process_stream_inner(
&input,
Options {
headings: true,
..Default::default()
},
);
assert_eq!(
enabled,
vec!["# Heading".to_string(), "Paragraph".to_string()]
);
}
#[test]
fn converts_footnote_references_before_the_table_is_measured() {
let input = vec![
"| a | see docs.1 |".to_string(),
"| --- | --- |".to_string(),
];
let out = process_stream_inner(
&input,
Options {
footnotes: true,
..Default::default()
},
);
assert_eq!(
out,
vec![
"| a | see docs.[^1] |".to_string(),
"| --- | ------------- |".to_string(),
]
);
}
#[test]
fn renumbers_footnote_labels_before_the_wrap_measures_them() {
let long = format!("{} [^10]", "w".repeat(75));
let short = format!("{} [^1]", "w".repeat(75));
let options = Options {
wrap: true,
footnotes: true,
..Default::default()
};
let once = process_stream_inner(&[long], options);
assert_eq!(once, vec![short]);
assert_eq!(process_stream_inner(&once, options), once);
}
#[test]
fn process_stream_inner_applies_table_ellipsis_before_reflow() {
let input = vec![
"| example | value |".to_string(),
"| ------- | ----- |".to_string(),
"| ... | tail |".to_string(),
];
let with_ellipsis = process_stream_inner(
&input,
Options {
ellipsis: true,
..Default::default()
},
);
let without_ellipsis = process_stream_inner(&input, Options::default());
assert!(with_ellipsis.iter().any(|line| line.contains('…')));
assert!(!with_ellipsis.iter().any(|line| line.contains("...")));
assert!(without_ellipsis.iter().any(|line| line.contains("...")));
assert!(!without_ellipsis.iter().any(|line| line.contains('…')));
}