diff options
author | Ethan P <eth-p+git@hidden.email> | 2020-05-13 02:51:49 -0700 |
---|---|---|
committer | Ethan P <eth-p+git@hidden.email> | 2020-05-13 02:53:19 -0700 |
commit | 82981c96636a0e1a418a8611ed67cc6a56ef7096 (patch) | |
tree | 05db2179273cf4dca25b0835b93d4370435d71a6 /tests | |
parent | 157b8dd848a90b021372c8d0a64b2e70abfb36f9 (diff) |
Add regression test for detected syntax differing for stdin and files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/examples/regression_tests/issue_985.js | 5 | ||||
-rw-r--r-- | tests/integration_tests.rs | 39 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/examples/regression_tests/issue_985.js b/tests/examples/regression_tests/issue_985.js new file mode 100644 index 00000000..5e2e2191 --- /dev/null +++ b/tests/examples/regression_tests/issue_985.js @@ -0,0 +1,5 @@ +// This test should be considered a failure if the detected syntax differs between the following two commands: +/* +# bat --map-syntax '*.js:Markdown' --file-name 'issue_985.js' < issue_985.js +# bat --map-syntax '*.js:Markdown' --file-name 'issue_985.js' issue_985.js +*/ diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 89c15832..6e49cff6 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,4 +1,8 @@ use assert_cmd::Command; +use std::path::Path; +use std::str::from_utf8; + +const EXAMPLES_DIR: &str = "tests/examples"; fn bat_with_config() -> Command { let mut cmd = Command::cargo_bin("bat").unwrap(); @@ -670,3 +674,38 @@ fn do_not_panic_regression_tests() { .success(); } } + +#[test] +fn do_not_detect_different_syntax_for_stdin_and_files() { + let file = "regression_tests/issue_985.js"; + + let output_for_file = bat() + .arg("--color=always") + .arg("--map-syntax=*.js:Markdown") + .arg(&format!("--file-name={}", file)) + .arg("--style=plain") + .arg(file) + .assert() + .success() + .get_output() + .stdout + .clone(); + + let output_for_stdin = bat() + .arg("--color=always") + .arg("--map-syntax=*.js:Markdown") + .arg("--style=plain") + .arg(&format!("--file-name={}", file)) + .pipe_stdin(Path::new(EXAMPLES_DIR).join(file)) + .unwrap() + .assert() + .success() + .get_output() + .stdout + .clone(); + + assert_eq!( + from_utf8(&output_for_file).unwrap(), + from_utf8(&output_for_stdin).unwrap() + ); +} |