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

Code before:
                line_syntax.ok_or_else(|| ErrorKind::UndetectedSyntax("[unknown]".into()).into())
            }
        }
    }

    fn get_extension_syntax(&self, file_name: &OsStr) -> Option<&SyntaxReference> {
        self.syntax_set
            .find_syntax_by_extension(file_name.to_str().unwrap_or_default())
            .or_else(|| {
                let file_path = Path::new(file_name);
                self.syntax_set.find_syntax_by_extension(
                    file_path
                        .extension()
                        .and_then(|x| x.to_str())
                        .unwrap_or_default(),
                ).or_else(|| {
                    let file_str = file_path.to_str().unwrap_or_default();
                    for suffix in IGNORED_SUFFIXES.iter() {
                        if file_str.ends_with(suffix) {
                            return self.get_extension_syntax(
                                OsStr::new(
                                    file_str
                                        .strip_suffix(suffix)
                                        .unwrap_or_default()
                                ));
                        }
                    }
                    None
                })
            })
    }

    fn get_first_line_syntax(&self, reader: &mut InputReader) -> Option<&SyntaxReference> {
        String::from_utf8(reader.first_line.clone())
            .ok()
            .and_then(|l| self.syntax_set.find_syntax_by_first_line(&l))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::ffi::OsStr;

    use std::fs::File;
    use std::io::Write;
    use tempfile::TempDir;

    use crate::input::Input;


Review comment (suggestion):
Instead of using `.ends_with(suffix)`, `.strip_suffix(suffix)` and finally `.unwrap*`, I think you could simply call `strip_suffix` and decide based on the result. Something like:
```rust
if let Some(stripped_filename) = file_str.strip_suffix(suffix) {
    return self.get_extension_syntax(OsStr::new(stripped_filename));
}
```

Code after:
                line_syntax.ok_or_else(|| ErrorKind::UndetectedSyntax("[unknown]".into()).into())
            }
        }
    }

    fn get_extension_syntax(&self, file_name: &OsStr) -> Option<&SyntaxReference> {
        self.syntax_set
            .find_syntax_by_extension(file_name.to_str().unwrap_or_default())
            .or_else(|| {
                let file_path = Path::new(file_name);
                self.syntax_set.find_syntax_by_extension(
                    file_path
                        .extension()
                        .and_then(|x| x.to_str())
                        .unwrap_or_default(),
                ).or_else(|| {
                    if let Some(file_str) = file_path.to_str() {
                        for suffix in IGNORED_SUFFIXES.iter() {
                            if let Some(stripped_filename) = file_str.strip_suffix(suffix) {
                                return self.get_extension_syntax(OsStr::new(stripped_filename));
                            }
                        }
                    }
                    None
                })
            })
    }

    fn get_first_line_syntax(&self, reader: &mut InputReader) -> Option<&SyntaxReference> {
        String::from_utf8(reader.first_line.clone())
            .ok()
            .and_then(|l| self.syntax_set.find_syntax_by_first_line(&l))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::ffi::OsStr;

    use std::fs::File;
    use std::io::Write;
    use tempfile::TempDir;

    use crate::input::Input;

    struct SyntaxDetectionTest<'a> {
        assets: HighlightingAssets,
        pub syntax_mapping: SyntaxMapping<'a>,
        pub temp_dir: TempDir,