mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:55:42 +02:00
Test command names and search terms for redundancy (#6380)
* Test commands for proper names and search terms Assert that the `Command.name()` is equal to `Signature.name` Check that search terms are not just substrings of the command name as they would not help finding the command. * Clean up search terms Remove redundant terms that just replicate the command name. Try to eliminate substring between search terms, clean up where necessary.
This commit is contained in:
committed by
GitHub
parent
ef26d539a7
commit
0afe1e4e67
@ -23,3 +23,55 @@ fn quickcheck_parse(data: String) -> bool {
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signature_name_matches_command_name() {
|
||||
let ctx = crate::create_default_context();
|
||||
let decls = ctx.get_decl_ids_sorted(true);
|
||||
let mut failures = Vec::new();
|
||||
|
||||
for decl_id in decls {
|
||||
let cmd = ctx.get_decl(decl_id);
|
||||
let cmd_name = cmd.name();
|
||||
let sig_name = cmd.signature().name;
|
||||
let category = cmd.signature().category;
|
||||
|
||||
if cmd_name != sig_name {
|
||||
failures.push(format!(
|
||||
"{cmd_name} ({category:?}): Signature name \"{sig_name}\" is not equal to the command name \"{cmd_name}\""
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
assert!(
|
||||
failures.is_empty(),
|
||||
"Name mismatch:\n{}",
|
||||
failures.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_search_term_duplicates() {
|
||||
let ctx = crate::create_default_context();
|
||||
let decls = ctx.get_decl_ids_sorted(true);
|
||||
let mut failures = Vec::new();
|
||||
|
||||
for decl_id in decls {
|
||||
let cmd = ctx.get_decl(decl_id);
|
||||
let cmd_name = cmd.name();
|
||||
let search_terms = cmd.search_terms();
|
||||
let category = cmd.signature().category;
|
||||
|
||||
for search_term in search_terms {
|
||||
if cmd_name.contains(search_term) {
|
||||
failures.push(format!("{cmd_name} ({category:?}): Search term \"{search_term}\" is substring of command name \"{cmd_name}\""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(
|
||||
failures.is_empty(),
|
||||
"Duplication in search terms:\n{}",
|
||||
failures.join("\n")
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user