Repository: sharkdp/bat
File: src/assets.rs (Rust)

Code before:
            content: &str,
            config: &Config,
        ) -> bool {
            let as_file =
                self.syntax_for_real_file_with_content_os(file_name.as_ref(), content, config);
            let as_reader =
                self.syntax_for_file_with_content_os(file_name.as_ref(), content, &config);
            let consistent = as_file == as_reader;
            // TODO: Compare StdIn somehow?

            if !consistent {
                eprintln!(
                    "Inconsistent syntax detection:\nFor File: {}\nFor Reader: {}",
                    as_file, as_reader
                )
            }

            consistent
        }
    }

    #[test]
    fn syntax_detection_basic() {
        let test = SyntaxDetectionTest::new();
        let config = Config::default();

        assert_eq!(test.syntax_for_file("test.rs", &config), "Rust");
        assert_eq!(test.syntax_for_file("test.cpp", &config), "C++");
        assert_eq!(
            test.syntax_for_file("test.build", &config),
            "NAnt Build File"
        );
        assert_eq!(
            test.syntax_for_file("PKGBUILD", &config),
            "Bourne Again Shell (bash)"
        );
        assert_eq!(
            test.syntax_for_file(".bashrc", &config),
            "Bourne Again Shell (bash)"
        );
        assert_eq!(test.syntax_for_file("Makefile", &config), "Makefile");
    }

    #[cfg(unix)]
    #[test]
    fn syntax_detection_invalid_utf8() {
        use std::os::unix::ffi::OsStrExt;

        let test = SyntaxDetectionTest::new();
        let config = Config::default();


Review comment (suggestion):
To make the diff nicer (i.e. easier to review) I would prefer if you kept the signature of `syntax_is_same_for_inputkinds()` and instead handled any new API inside of it. Possibly with a new wrapper for new tests.

In general, I would like old regression tests to remain the same.

Code after:

        assert_eq!(test.syntax_for_file("test.rs"), "Rust");
        assert_eq!(test.syntax_for_file("test.cpp"), "C++");
        assert_eq!(test.syntax_for_file("test.build"), "NAnt Build File");
        assert_eq!(
            test.syntax_for_file("PKGBUILD"),
            "Bourne Again Shell (bash)"
        );
        assert_eq!(test.syntax_for_file(".bashrc"), "Bourne Again Shell (bash)");
        assert_eq!(test.syntax_for_file("Makefile"), "Makefile");
    }

    #[cfg(unix)]
    #[test]
    fn syntax_detection_invalid_utf8() {
        use std::os::unix::ffi::OsStrExt;

        let test = SyntaxDetectionTest::new();

        assert_eq!(
            test.syntax_for_file_os(OsStr::from_bytes(b"invalid_\xFEutf8_filename.rs")),
            "Rust"
        );
    }

    #[test]
    fn syntax_detection_same_for_inputkinds() {
        let mut test = SyntaxDetectionTest::new();

        test.syntax_mapping
            .insert("*.myext", MappingTarget::MapTo("C"))
            .ok();
        test.syntax_mapping
            .insert("MY_FILE", MappingTarget::MapTo("Markdown"))
            .ok();

        assert!(test.syntax_is_same_for_inputkinds("Test.md", ""));
        assert!(test.syntax_is_same_for_inputkinds("Test.txt", "#!/bin/bash"));
        assert!(test.syntax_is_same_for_inputkinds(".bashrc", ""));
        assert!(test.syntax_is_same_for_inputkinds("test.h", ""));
        assert!(test.syntax_is_same_for_inputkinds("test.js", "#!/bin/bash"));
        assert!(test.syntax_is_same_for_inputkinds("test.myext", ""));
        assert!(test.syntax_is_same_for_inputkinds("MY_FILE", ""));
        assert!(test.syntax_is_same_for_inputkinds("MY_FILE", "<?php"));
    }

    #[test]
    fn syntax_detection_well_defined_mapping_for_duplicate_extensions() {
        let test = SyntaxDetectionTest::new();

        assert_eq!(test.syntax_for_file("test.h"), "C++");