Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ macro_rules! lines_vec {
};
}

/// Expands to a `Vec<String>` with one element per line of the file.
///
/// Example:
/// ```
/// let input: Vec<String> = include_lines!("data/bold_header_input.txt");
/// ```
macro_rules! include_lines {
($path:literal $(,)?) => {{
const _TXT: &str = include_str!($path);
_TXT.lines().map(str::to_owned).collect()
}};
Comment thread
leynos marked this conversation as resolved.
}

/// Assert common wrapping expectations for list items.
///
/// Verifies the number of lines, prefix on the first line, length of all lines,
Expand Down
90 changes: 18 additions & 72 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,27 +465,15 @@ fn test_convert_html_table_unclosed_returns_original() {

#[test]
fn test_convert_html_table_bold_header() {
let input: Vec<String> = include_str!("data/bold_header_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/bold_header_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/bold_header_input.txt");
let expected: Vec<String> = include_lines!("data/bold_header_expected.txt");
assert_eq!(convert_html_tables(&input), expected);
}

#[test]
fn test_logical_type_table_output_matches() {
let input: Vec<String> = include_str!("data/logical_type_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/logical_type_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/logical_type_input.txt");
let expected: Vec<String> = include_lines!("data/logical_type_expected.txt");
assert_eq!(reflow_table(&input), expected);
}

Expand All @@ -495,55 +483,31 @@ fn test_logical_type_table_output_matches() {
/// Loads the input and expected output from external files and asserts that the
/// `reflow_table` function transforms the input table to match the expected result.
fn test_option_table_output_matches() {
let input: Vec<String> = include_str!("data/option_table_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/option_table_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/option_table_input.txt");
let expected: Vec<String> = include_lines!("data/option_table_expected.txt");
assert_eq!(reflow_table(&input), expected);
}

#[test]
fn test_month_seconds_table_output_matches() {
let input: Vec<String> = include_str!("data/month_seconds_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/month_seconds_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/month_seconds_input.txt");
let expected: Vec<String> = include_lines!("data/month_seconds_expected.txt");
assert_eq!(reflow_table(&input), expected);
}

#[test]
fn test_offset_table_output_matches() {
let input: Vec<String> = include_str!("data/offset_table_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/offset_table_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/offset_table_input.txt");
let expected: Vec<String> = include_lines!("data/offset_table_expected.txt");
assert_eq!(reflow_table(&input), expected);
}

#[test]
/// Tests that `process_stream` correctly processes a complex Markdown table representing logical
/// types by comparing its output to expected results loaded from a file.
fn test_process_stream_logical_type_table() {
let input: Vec<String> = include_str!("data/logical_type_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/logical_type_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/logical_type_input.txt");
let expected: Vec<String> = include_lines!("data/logical_type_expected.txt");
assert_eq!(process_stream(&input), expected);
}

Expand All @@ -554,14 +518,8 @@ fn test_process_stream_logical_type_table() {
/// Loads input and expected output from test data files, runs `process_stream` on the input, and
/// asserts equality.
fn test_process_stream_option_table() {
let input: Vec<String> = include_str!("data/option_table_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/option_table_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/option_table_input.txt");
let expected: Vec<String> = include_lines!("data/option_table_expected.txt");
assert_eq!(process_stream(&input), expected);
}

Expand Down Expand Up @@ -821,14 +779,8 @@ fn test_preserve_hard_line_breaks() {
/// columns and detailed content pass through the processing pipeline unchanged,
/// preventing regressions that might inadvertently alter correct formatting.
fn test_regression_complex_table() {
let input: Vec<String> = include_str!("data/regression_table_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/regression_table_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/regression_table_input.txt");
let expected: Vec<String> = include_lines!("data/regression_table_expected.txt");
assert_eq!(process_stream(&input), expected);
}

Expand Down Expand Up @@ -907,14 +859,8 @@ fn test_renumber_table_in_list() {

#[test]
fn test_renumber_restart_after_paragraph() {
let input: Vec<String> = include_str!("data/renumber_paragraph_restart_input.txt")
.lines()
.map(str::to_string)
.collect();
let expected: Vec<String> = include_str!("data/renumber_paragraph_restart_expected.txt")
.lines()
.map(str::to_string)
.collect();
let input: Vec<String> = include_lines!("data/renumber_paragraph_restart_input.txt");
let expected: Vec<String> = include_lines!("data/renumber_paragraph_restart_expected.txt");
assert_eq!(renumber_lists(&input), expected);
}

Expand Down