From 1a41bcc1ec9924ccce6a6f708f9285f3ee542f2b Mon Sep 17 00:00:00 2001 From: Leynos Date: Thu, 17 Jul 2025 22:20:35 +0100 Subject: [PATCH 1/3] Add include_lines macro for file fixtures --- tests/common/mod.rs | 14 +++++++ tests/integration.rs | 90 +++++++++----------------------------------- 2 files changed, 32 insertions(+), 72 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 7e90414b..81254248 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -10,6 +10,20 @@ macro_rules! lines_vec { }; } +/// Expands to a `Vec` with one element per line of the file. +/// +/// Example: +/// ``` +/// let input: Vec = include_lines!("data/bold_header_input.txt"); +/// ``` +#[macro_export] +macro_rules! include_lines { + ($path:literal $(,)?) => {{ + const _TXT: &str = include_str!($path); + _TXT.lines().map(|l| l.to_owned()).collect::>() + }}; +} + /// Assert common wrapping expectations for list items. /// /// Verifies the number of lines, prefix on the first line, length of all lines, diff --git a/tests/integration.rs b/tests/integration.rs index 56738e84..8b9244e4 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -465,27 +465,15 @@ fn test_convert_html_table_unclosed_returns_original() { #[test] fn test_convert_html_table_bold_header() { - let input: Vec = include_str!("data/bold_header_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/bold_header_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/bold_header_input.txt"); + let expected: Vec = 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 = include_str!("data/logical_type_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/logical_type_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/logical_type_input.txt"); + let expected: Vec = include_lines!("data/logical_type_expected.txt"); assert_eq!(reflow_table(&input), expected); } @@ -495,40 +483,22 @@ 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 = include_str!("data/option_table_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/option_table_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/option_table_input.txt"); + let expected: Vec = include_lines!("data/option_table_expected.txt"); assert_eq!(reflow_table(&input), expected); } #[test] fn test_month_seconds_table_output_matches() { - let input: Vec = include_str!("data/month_seconds_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/month_seconds_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/month_seconds_input.txt"); + let expected: Vec = include_lines!("data/month_seconds_expected.txt"); assert_eq!(reflow_table(&input), expected); } #[test] fn test_offset_table_output_matches() { - let input: Vec = include_str!("data/offset_table_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/offset_table_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/offset_table_input.txt"); + let expected: Vec = include_lines!("data/offset_table_expected.txt"); assert_eq!(reflow_table(&input), expected); } @@ -536,14 +506,8 @@ fn test_offset_table_output_matches() { /// 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 = include_str!("data/logical_type_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/logical_type_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/logical_type_input.txt"); + let expected: Vec = include_lines!("data/logical_type_expected.txt"); assert_eq!(process_stream(&input), expected); } @@ -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 = include_str!("data/option_table_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/option_table_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/option_table_input.txt"); + let expected: Vec = include_lines!("data/option_table_expected.txt"); assert_eq!(process_stream(&input), expected); } @@ -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 = include_str!("data/regression_table_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/regression_table_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/regression_table_input.txt"); + let expected: Vec = include_lines!("data/regression_table_expected.txt"); assert_eq!(process_stream(&input), expected); } @@ -907,14 +859,8 @@ fn test_renumber_table_in_list() { #[test] fn test_renumber_restart_after_paragraph() { - let input: Vec = include_str!("data/renumber_paragraph_restart_input.txt") - .lines() - .map(str::to_string) - .collect(); - let expected: Vec = include_str!("data/renumber_paragraph_restart_expected.txt") - .lines() - .map(str::to_string) - .collect(); + let input: Vec = include_lines!("data/renumber_paragraph_restart_input.txt"); + let expected: Vec = include_lines!("data/renumber_paragraph_restart_expected.txt"); assert_eq!(renumber_lists(&input), expected); } From 45b53dd8fff9dbab6ef72d52ee44901c8a1b9ca8 Mon Sep 17 00:00:00 2001 From: Leynos Date: Thu, 17 Jul 2025 22:31:10 +0100 Subject: [PATCH 2/3] Scope include_lines macro to tests --- tests/common/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 81254248..c8305fca 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -16,7 +16,6 @@ macro_rules! lines_vec { /// ``` /// let input: Vec = include_lines!("data/bold_header_input.txt"); /// ``` -#[macro_export] macro_rules! include_lines { ($path:literal $(,)?) => {{ const _TXT: &str = include_str!($path); From 1883ec6ddf030786913a372409b81aeb84a71585 Mon Sep 17 00:00:00 2001 From: Leynos Date: Thu, 17 Jul 2025 22:40:07 +0100 Subject: [PATCH 3/3] Simplify include_lines macro --- tests/common/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index c8305fca..f893484b 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -19,7 +19,7 @@ macro_rules! lines_vec { macro_rules! include_lines { ($path:literal $(,)?) => {{ const _TXT: &str = include_str!($path); - _TXT.lines().map(|l| l.to_owned()).collect::>() + _TXT.lines().map(str::to_owned).collect() }}; }