src/tools/tidy/src/extra_checks/tests.rs RUST 87 lines View on github.com → Search inside
1use std::str::FromStr;23use crate::extra_checks::{ExtraCheckArg, ExtraCheckKind, ExtraCheckLang, ExtraCheckParseError};45#[test]6fn test_extra_check_arg_from_str_ok() {7    let test_cases = [8        (9            "auto:if-installed:spellcheck",10            ExtraCheckArg {11                auto: true,12                if_installed: true,13                lang: ExtraCheckLang::Spellcheck,14                kind: None,15            },16        ),17        (18            "if-installed:auto:spellcheck",19            ExtraCheckArg {20                auto: true,21                if_installed: true,22                lang: ExtraCheckLang::Spellcheck,23                kind: None,24            },25        ),26        (27            "auto:spellcheck",28            ExtraCheckArg {29                auto: true,30                if_installed: false,31                lang: ExtraCheckLang::Spellcheck,32                kind: None,33            },34        ),35        (36            "if-installed:spellcheck",37            ExtraCheckArg {38                auto: false,39                if_installed: true,40                lang: ExtraCheckLang::Spellcheck,41                kind: None,42            },43        ),44        (45            "spellcheck",46            ExtraCheckArg {47                auto: false,48                if_installed: false,49                lang: ExtraCheckLang::Spellcheck,50                kind: None,51            },52        ),53        (54            "js:lint",55            ExtraCheckArg {56                auto: false,57                if_installed: false,58                lang: ExtraCheckLang::Js,59                kind: Some(ExtraCheckKind::Lint),60            },61        ),62    ];6364    for (s, expected) in test_cases {65        assert_eq!(ExtraCheckArg::from_str(s), Ok(expected));66    }67}6869#[test]70fn test_extra_check_arg_from_str_err() {71    let test_cases = [72        ("some:spellcheck", ExtraCheckParseError::UnknownLang("some".to_string())),73        ("spellcheck:some", ExtraCheckParseError::UnknownKind("some".to_string())),74        ("spellcheck:lint", ExtraCheckParseError::UnsupportedKindForLang),75        ("auto:spellcheck:some", ExtraCheckParseError::UnknownKind("some".to_string())),76        ("auto:js:lint:some", ExtraCheckParseError::TooManyParts),77        ("some", ExtraCheckParseError::UnknownLang("some".to_string())),78        ("auto", ExtraCheckParseError::AutoRequiresLang),79        ("if-installed", ExtraCheckParseError::IfInstalledRequiresLang),80        ("", ExtraCheckParseError::Empty),81    ];8283    for (s, expected) in test_cases {84        assert_eq!(ExtraCheckArg::from_str(s), Err(expected));85    }86}

Code quality findings 4

Performance Info: Calling .to_string() (especially on &str) allocates a new String. If done repeatedly in loops, consider alternatives like working with &str or using crates like `itoa`/`ryu` for number-to-string conversion.
info performance to-string-in-loop
("some:spellcheck", ExtraCheckParseError::UnknownLang("some".to_string())),
Performance Info: Calling .to_string() (especially on &str) allocates a new String. If done repeatedly in loops, consider alternatives like working with &str or using crates like `itoa`/`ryu` for number-to-string conversion.
info performance to-string-in-loop
("spellcheck:some", ExtraCheckParseError::UnknownKind("some".to_string())),
Performance Info: Calling .to_string() (especially on &str) allocates a new String. If done repeatedly in loops, consider alternatives like working with &str or using crates like `itoa`/`ryu` for number-to-string conversion.
info performance to-string-in-loop
("auto:spellcheck:some", ExtraCheckParseError::UnknownKind("some".to_string())),
Performance Info: Calling .to_string() (especially on &str) allocates a new String. If done repeatedly in loops, consider alternatives like working with &str or using crates like `itoa`/`ryu` for number-to-string conversion.
info performance to-string-in-loop
("some", ExtraCheckParseError::UnknownLang("some".to_string())),

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.