Repository: nushell/nushell
File: crates/nu-cmd-extra/src/extra/formats/to/html.rs (Rust)

Code before:
    #[test]
    fn test_examples() {
        use crate::test_examples;

        test_examples(ToHtml {})
    }

    #[test]
    fn get_theme_from_asset_file_returns_default() {
        let result = super::get_theme_from_asset_file(false, None);

        assert!(result.is_ok(), "Expected Ok result for None theme");

        let theme_map = result.unwrap();

        assert_eq!(
            theme_map.get("background").map(String::as_str),
            Some("white"),
            "Expected default background color to be white"
        );

        assert_eq!(
            theme_map.get("foreground").map(String::as_str),
            Some("black"),
            "Expected default foreground color to be black"
        );

        assert!(
            theme_map.contains_key("red"),
            "Expected default theme to have a 'red' color"
        );

        assert!(
            theme_map.contains_key("bold_green"),
            "Expected default theme to have a 'bold_green' color"
        );
    }

    #[test]
    fn returns_a_valid_theme() {
        let theme_name = "Dracula".to_string().into_spanned(Span::new(0, 7));
        let result = super::get_theme_from_asset_file(false, Some(&theme_name));

        assert!(result.is_ok(), "Expected Ok result for valid theme");
        let theme_map = result.unwrap();
        let required_keys = [
            "background",
            "foreground",
            "red",
            "green",
            "blue",

Review comment (suggestion):
Is there any reason to change this using `test_examples_with_commands(ToHtml {}, &[&ToXml])?`.  If you meaned for further changes on `ToXml` in the future, I think it's good to keep it as it is here.

Code after:
        ),
    );
}

fn run_regexes(hash: &HashMap<u32, (&'static str, String)>, contents: &str) -> String {
    let mut working_string = contents.to_owned();
    let hash_count: u32 = hash.len() as u32;
    for n in 0..hash_count {
        let value = hash.get(&n).expect("error getting hash at index");
        let re = Regex::new(value.0).expect("problem with color regex");
        let after = re.replace_all(&working_string, &value.1[..]).to_string();
        working_string = after;
    }
    working_string
}

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

    #[test]
    fn test_examples() {
        use crate::test_examples_with_commands;
        use nu_command::ToXml;

        test_examples_with_commands(ToHtml {}, &[&ToXml])
    }

    #[test]
    fn get_theme_from_asset_file_returns_default() {
        let result = super::get_theme_from_asset_file(false, None);

        assert!(result.is_ok(), "Expected Ok result for None theme");

        let theme_map = result.unwrap();

        assert_eq!(
            theme_map.get("background").map(String::as_str),
            Some("white"),
            "Expected default background color to be white"
        );

        assert_eq!(
            theme_map.get("foreground").map(String::as_str),
            Some("black"),
            "Expected default foreground color to be black"
        );

        assert!(
            theme_map.contains_key("red"),
            "Expected default theme to have a 'red' color"