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() + ); +}