<commit_before>use std::path::Path;

#[derive(Debug, PartialEq)]
pub enum Type {
    CoffeeScript,
    JavaScript,
    JSON,
    XML,
    Ruby,
    Rust,
    ERB
}

pub fn from_path(path: &Path) -> Option<Type> {
    match path.to_str() {
        Some(filename) => {
            let extension = filename.split('.').last();
            match extension {
                Some("coffee") => Some(Type::CoffeeScript),
                Some("js") => Some(Type::JavaScript),
                Some("json") => Some(Type::JSON),
                Some("xml") => Some(Type::XML),
                Some("rake") => Some(Type::Ruby),
                Some("rb") => Some(Type::Ruby),
                Some("rs") => Some(Type::Rust),
                Some("erb") => Some(Type::ERB),
                _ => None,
            }
        },
        None => return None,
    }
}

#[cfg(test)]
mod tests {
    use std::path::Path;
    use super::from_path;
    use super::Type;
<commit_msg>Use XML lexer for HTML documents.<commit_after>use std::path::Path;

#[derive(Debug, PartialEq)]
pub enum Type {
    CoffeeScript,
    JavaScript,
    JSON,
    XML,
    Ruby,
    Rust,
    ERB
}

pub fn from_path(path: &Path) -> Option<Type> {
    match path.to_str() {
        Some(filename) => {
            let extension = filename.split('.').last();
            match extension {
                Some("coffee") => Some(Type::CoffeeScript),
                Some("js") => Some(Type::JavaScript),
                Some("json") => Some(Type::JSON),
                Some("html") => Some(Type::XML),
                Some("xml") => Some(Type::XML),
                Some("rake") => Some(Type::Ruby),
                Some("rb") => Some(Type::Ruby),
                Some("rs") => Some(Type::Rust),
                Some("erb") => Some(Type::ERB),
                _ => None,
            }
        },
        None => return None,
    }
}

#[cfg(test)]
mod tests {
    use std::path::Path;
    use super::from_path;
    use super::Type;

{'fraction_non_alphanumeric': 0.17531486146095718, 'fraction_numerical': 0.0, 'mean_word_length': 1.805084745762712, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6484569', 'n_tokens_mistral': 630, 'n_tokens_neox': 603, 'n_words': 119}