-
Notifications
You must be signed in to change notification settings - Fork 0
Restructure integration tests by feature #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
68f35d8
Split integration tests by feature
leynos 26ed71f
Replace String::new with empty string in table test
leynos a05a251
Add whitespace tests and test prelude
leynos f8abfd1
Refine test modules per review
leynos 7913237
Refine table fixtures
leynos ae2f17b
Refine prelude module and wrap docs
leynos daca755
Centralise fixtures and re-export macros
leynos 2269ad5
Document wrap tests and adjust lint expects
leynos 4bb5642
Address review feedback
leynos 8a52a67
Add missing doc comments to wrap tests
leynos 7fb1072
Document wrap tests and unify inputs
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| //! Integration tests for formatting thematic breaks. | ||
| //! | ||
| //! Verifies `format_breaks` function and `--breaks` CLI option. | ||
|
|
||
| use std::borrow::Cow; | ||
|
|
||
| use mdtablefix::{THEMATIC_BREAK_LEN, format_breaks}; | ||
|
|
||
| #[macro_use] | ||
| mod prelude; | ||
| use prelude::*; | ||
|
|
||
| #[test] | ||
| fn test_format_breaks_basic() { | ||
| let input = lines_vec!["foo", "***", "bar"]; | ||
| let expected: Vec<Cow<str>> = vec![ | ||
| input[0].as_str().into(), | ||
| Cow::Owned("_".repeat(THEMATIC_BREAK_LEN)), | ||
| input[2].as_str().into(), | ||
| ]; | ||
| assert_eq!(format_breaks(&input), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_format_breaks_ignores_code() { | ||
| let input = lines_vec!["```", "---", "```"]; | ||
| let expected: Vec<Cow<str>> = input.iter().map(|s| s.as_str().into()).collect(); | ||
| assert_eq!(format_breaks(&input), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_format_breaks_mixed_chars() { | ||
| let input = lines_vec!["-*-*-"]; | ||
| let expected: Vec<Cow<str>> = input.iter().map(|s| s.as_str().into()).collect(); | ||
| assert_eq!(format_breaks(&input), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_format_breaks_with_spaces_and_indent() { | ||
| let input = lines_vec![" - - - "]; | ||
| let expected: Vec<Cow<str>> = vec![Cow::Owned("_".repeat(THEMATIC_BREAK_LEN))]; | ||
| assert_eq!(format_breaks(&input), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_format_breaks_with_tabs_and_underscores() { | ||
| let input = lines_vec!["\t_\t_\t_\t"]; | ||
| let expected: Vec<Cow<str>> = vec![Cow::Owned("_".repeat(THEMATIC_BREAK_LEN))]; | ||
| assert_eq!(format_breaks(&input), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_format_breaks_mixed_chars_excessive_length() { | ||
| let input = lines_vec!["***---___"]; | ||
| let expected: Vec<Cow<str>> = input.iter().map(|s| s.as_str().into()).collect(); | ||
| assert_eq!(format_breaks(&input), expected); | ||
| } | ||
|
|
||
| /// Tests the CLI `--breaks` option to ensure thematic breaks are normalised. | ||
| /// | ||
| /// Provides a single line of hyphens and asserts the output is the standard | ||
| /// underscore-based thematic break. | ||
| #[test] | ||
| fn test_cli_breaks_option() { | ||
| let output = Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--breaks") | ||
| .write_stdin("---\n") | ||
| .output() | ||
| .expect("Failed to execute mdtablefix command"); | ||
| assert!(output.status.success()); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&output.stdout), | ||
| format!("{}\n", "_".repeat(THEMATIC_BREAK_LEN)) | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| //! Integration tests for CLI interface behaviour of the `mdtablefix` tool. | ||
| //! | ||
| //! This module validates the command-line interface functionality, including: | ||
| //! - File handling with the `--in-place` flag | ||
| //! - Ellipsis replacement with the `--ellipsis` option | ||
| //! - Error handling for invalid argument combinations | ||
| //! - Processing of Markdown files through the CLI interface | ||
|
|
||
| use std::{fs::File, io::Write}; | ||
|
|
||
| use tempfile::tempdir; | ||
|
|
||
| #[macro_use] | ||
| mod prelude; | ||
| use prelude::*; | ||
|
|
||
| /// Verifies that the CLI fails when the `--in-place` flag is used without specifying a file. | ||
| /// | ||
| /// This test ensures that running `mdtablefix --in-place` without a file argument results in a | ||
| /// command failure. | ||
| #[test] | ||
| fn test_cli_in_place_requires_file() { | ||
| Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--in-place") | ||
| .assert() | ||
| .failure(); | ||
| } | ||
|
|
||
| /// Tests that the CLI processes a file containing a broken Markdown table and outputs the corrected | ||
| /// table to stdout. | ||
| /// | ||
| /// This test creates a temporary file with a malformed table, runs the `mdtablefix` binary on it, | ||
| /// and asserts that the output is the expected fixed table. | ||
| #[rstest] | ||
| fn test_cli_process_file(broken_table: Vec<String>) { | ||
| let dir = tempdir().expect("failed to create temporary directory"); | ||
| let file_path = dir.path().join("sample.md"); | ||
| let mut f = File::create(&file_path).expect("failed to create temporary file"); | ||
| for line in &broken_table { | ||
| writeln!(f, "{line}").expect("failed to write line"); | ||
| } | ||
| f.flush().expect("failed to flush file"); | ||
| drop(f); | ||
| Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg(&file_path) | ||
| .assert() | ||
| .success() | ||
| .stdout("| A | B |\n| 1 | 2 |\n| 3 | 4 |\n"); | ||
| } | ||
|
|
||
| /// Tests that the `--ellipsis` option replaces triple dots with a Unicode ellipsis character. | ||
| /// | ||
| /// Verifies that the CLI correctly processes input containing "..." and outputs "…". | ||
| #[test] | ||
| fn test_cli_ellipsis_option() { | ||
| let output = Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--ellipsis") | ||
| .write_stdin("foo...\n") | ||
| .output() | ||
| .expect("Failed to execute mdtablefix command"); | ||
| assert!(output.status.success()); | ||
| assert_eq!(String::from_utf8_lossy(&output.stdout), "foo…\n"); | ||
| } | ||
|
|
||
| /// Tests that the `--ellipsis` option preserves dots within inline code spans. | ||
| /// | ||
| /// Verifies that triple dots inside backtick-delimited code spans are not converted to ellipsis. | ||
| #[test] | ||
| fn test_cli_ellipsis_code_span() { | ||
| let output = Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--ellipsis") | ||
| .write_stdin("before `dots...` after\n") | ||
| .output() | ||
| .expect("Failed to execute mdtablefix command"); | ||
| assert!(output.status.success()); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&output.stdout), | ||
| "before `dots...` after\n" | ||
| ); | ||
| } | ||
|
|
||
| /// Tests that the `--ellipsis` option does not alter fenced code blocks. | ||
| /// | ||
| /// Ensures that sequences like "..." inside a fenced code block remain unchanged. | ||
| #[test] | ||
| fn test_cli_ellipsis_fenced_block() { | ||
| let output = Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--ellipsis") | ||
| .write_stdin("```\nlet x = ...;\n```\n") | ||
| .output() | ||
| .expect("Failed to execute mdtablefix command"); | ||
| assert!(output.status.success()); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&output.stdout), | ||
| "```\nlet x = ...;\n```\n" | ||
| ); | ||
| } | ||
|
|
||
| /// Tests ellipsis replacement for sequences longer than three characters. | ||
| /// | ||
| /// Confirms that only the first three dots are replaced with an ellipsis. | ||
| #[test] | ||
| fn test_cli_ellipsis_long_sequence() { | ||
| let output = Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--ellipsis") | ||
| .write_stdin("wait....\n") | ||
| .output() | ||
| .expect("Failed to execute mdtablefix command"); | ||
| assert!(output.status.success()); | ||
| assert_eq!(String::from_utf8_lossy(&output.stdout), "wait….\n"); | ||
| } | ||
|
|
||
| /// Tests that the `--ellipsis` option handles multiple ellipsis sequences in one line. | ||
| /// | ||
| /// Verifies that all occurrences of "..." are replaced with "…". | ||
| #[test] | ||
| fn test_cli_ellipsis_multiple_sequences() { | ||
| let output = Command::cargo_bin("mdtablefix") | ||
| .expect("Failed to create cargo command for mdtablefix") | ||
| .arg("--ellipsis") | ||
| .write_stdin("First... then second... done.\n") | ||
| .output() | ||
| .expect("Failed to execute mdtablefix command"); | ||
| assert!(output.status.success()); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&output.stdout), | ||
| "First… then second… done.\n" | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.