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:
Stefan Holderbach 2022-08-24 11:16:47 +02:00 committed by GitHub
parent ef26d539a7
commit 0afe1e4e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 126 additions and 91 deletions

8
Cargo.lock generated
View file

@ -4456,9 +4456,9 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.143" version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -4475,9 +4475,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.143" version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -49,7 +49,7 @@ impl Command for BytesIndexOf {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["pattern", "match", "find", "search", "index"] vec!["pattern", "match", "find", "search"]
} }
fn run( fn run(

View file

@ -39,7 +39,7 @@ impl Command for BytesLen {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["len", "size", "count"] vec!["size", "count"]
} }
fn run( fn run(

View file

@ -29,7 +29,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "binary", "bytes", "bin"] vec!["convert", "bytes"]
} }
fn run( fn run(

View file

@ -103,7 +103,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "date", "time", "timezone", "UTC"] vec!["convert", "timezone", "UTC"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -28,7 +28,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "number", "size", "bytes"] vec!["convert", "number", "bytes"]
} }
fn run( fn run(

View file

@ -38,7 +38,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "str", "text"] vec!["convert", "text"]
} }
fn run( fn run(

View file

@ -29,7 +29,7 @@ impl Command for ErrorMake {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["err", "panic", "crash", "throw"] vec!["panic", "crash", "throw"]
} }
fn run( fn run(

View file

@ -34,7 +34,7 @@ impl Command for CollectDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "collect"] vec!["database"]
} }
fn run( fn run(

View file

@ -47,7 +47,7 @@ impl Command for DescribeDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "SQLite", "describe"] vec!["database", "SQLite"]
} }
fn run( fn run(

View file

@ -41,7 +41,7 @@ impl Command for FromDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "from"] vec!["database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -49,7 +49,7 @@ impl Command for IntoSqliteDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "sqlite", "database"] vec!["convert", "database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -47,7 +47,7 @@ impl Command for JoinDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "join"] vec!["database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -34,7 +34,7 @@ impl Command for LimitDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "limit"] vec!["database", "head", "tail"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -29,7 +29,7 @@ impl Command for OpenDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "open"] vec!["database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -37,7 +37,7 @@ impl Command for OrderByDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "order-by"] vec!["database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -34,7 +34,7 @@ impl Command for SchemaDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "info", "SQLite", "schema"] vec!["database", "info", "SQLite"]
} }
fn run( fn run(

View file

@ -33,7 +33,7 @@ impl Command for ProjectionDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "select"] vec!["database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -30,7 +30,7 @@ impl Command for ToDataBase {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "into", "db"] vec!["database", "convert"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -31,7 +31,7 @@ impl Command for WhereDb {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "where"] vec!["database"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -30,7 +30,7 @@ impl Command for AndExpr {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "and", "expression"] vec!["database", "expression"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -30,7 +30,7 @@ impl Command for OrExpr {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "or", "expression"] vec!["database", "expression"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -92,7 +92,7 @@ impl Command for OverExpr {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["database", "over", "expression"] vec!["database", "expression"]
} }
fn run( fn run(

View file

@ -23,7 +23,6 @@ impl Command for Date {
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec![ vec![
"date",
"time", "time",
"now", "now",
"today", "today",

View file

@ -35,7 +35,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["date", "format", "strftime"] vec!["fmt", "strftime"]
} }
fn run( fn run(

View file

@ -22,8 +22,6 @@ impl Command for SubCommand {
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec![ vec![
"date",
"humanize",
"relative", "relative",
"now", "now",
"today", "today",

View file

@ -22,7 +22,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["UTC", "GMT", "timezone", "list", "list-timezone"] vec!["UTC", "GMT", "tz"]
} }
fn run( fn run(

View file

@ -19,7 +19,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["date", "now", "present", "current-time"] vec!["present", "current-time"]
} }
fn run( fn run(

View file

@ -23,7 +23,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["date", "to", "record", "structured", "table"] vec!["structured", "table"]
} }
fn run( fn run(

View file

@ -23,7 +23,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["date", "to", "record", "structured", "table"] vec!["structured"]
} }
fn run( fn run(

View file

@ -34,9 +34,7 @@ impl Command for SubCommand {
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec![ vec![
"date", "tz",
"to",
"timezone",
"transform", "transform",
"convert", "convert",
"UTC", "UTC",

View file

@ -20,7 +20,7 @@ impl Command for IsAdmin {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["root", "admin", "administrator", "superuser", "supervisor"] vec!["root", "administrator", "superuser", "supervisor"]
} }
fn run( fn run(

View file

@ -20,7 +20,7 @@ impl Command for Cd {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["cd", "change", "directory", "dir", "folder", "switch"] vec!["change", "directory", "dir", "folder", "switch"]
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {

View file

@ -36,7 +36,7 @@ impl Command for Cp {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["cp", "copy", "file", "files"] vec!["copy", "file", "files"]
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {

View file

@ -33,7 +33,7 @@ impl Command for Glob {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["glob", "files", "folders", "list", "ls"] vec!["pattern", "files", "folders", "list", "ls"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -33,15 +33,7 @@ impl Command for Mkdir {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec![ vec!["directory", "folder", "create", "make_dirs"]
"mkdir",
"make",
"directory",
"dir",
"folder",
"make_dir",
"make_dirs",
]
} }
fn run( fn run(

View file

@ -31,7 +31,7 @@ impl Command for Mv {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["mv", "move"] vec!["move"]
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {

View file

@ -28,7 +28,7 @@ impl Command for Open {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["open", "load", "read", "load_file", "read_file"] vec!["load", "read", "load_file", "read_file"]
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {

View file

@ -40,7 +40,7 @@ impl Command for Rm {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["rm", "remove"] vec!["delete", "remove"]
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {

View file

@ -25,7 +25,7 @@ impl Command for Touch {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["touch"] vec!["create", "file"]
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {

View file

@ -19,7 +19,7 @@ impl Command for EachWhile {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["for", "loop", "iterate", "while"] vec!["for", "loop", "iterate"]
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {

View file

@ -25,7 +25,7 @@ impl Command for Length {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["count", "len", "size", "wc"] vec!["count", "size", "wc"]
} }
fn run( fn run(

View file

@ -68,7 +68,7 @@ impl Command for ToText {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["text", "convert"] vec!["convert"]
} }
} }

View file

@ -21,7 +21,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["average", "mean"] vec!["average", "mean", "statistics"]
} }
fn run( fn run(

View file

@ -19,7 +19,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["ceiling"] vec!["ceiling", "round up", "rounding", "integer"]
} }
fn run( fn run(

View file

@ -19,7 +19,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["floor"] vec!["round down", "rounding", "integer"]
} }
fn run( fn run(

View file

@ -23,7 +23,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["middle", "median"] vec!["middle", "statistics"]
} }
fn run( fn run(

View file

@ -23,7 +23,14 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["SD", "standard", "deviation", "dispersion", "variation"] vec![
"SD",
"standard",
"deviation",
"dispersion",
"variation",
"statistics",
]
} }
fn run( fn run(

View file

@ -22,7 +22,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["deviation", "dispersion", "variance", "variation"] vec!["deviation", "dispersion", "variation", "statistics"]
} }
fn run( fn run(

View file

@ -94,7 +94,7 @@ impl Command for SubCommand {
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec![ vec![
"network", "fetch", "get", "pull", "request", "http", "download", "curl", "wget", "network", "get", "pull", "request", "http", "download", "curl", "wget",
] ]
} }

View file

@ -32,7 +32,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["network", "http", "port"] vec!["network", "http"]
} }
fn run( fn run(

View file

@ -80,7 +80,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["network", "post", "send", "push", "http"] vec!["network", "send", "push", "http"]
} }
fn run( fn run(

View file

@ -26,7 +26,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["url", "host", "hostname"] vec!["hostname"]
} }
fn run( fn run(

View file

@ -25,10 +25,6 @@ impl Command for SubCommand {
"Get the path of a URL" "Get the path of a URL"
} }
fn search_terms(&self) -> Vec<&str> {
vec!["url", "path"]
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View file

@ -26,7 +26,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["url", "query", "parameter"] vec!["parameter"]
} }
fn run( fn run(

View file

@ -26,7 +26,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["url", "scheme", "protocol"] vec!["protocol"]
} }
fn run( fn run(

View file

@ -22,7 +22,7 @@ impl Command for Url {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["url", "network", "parse"] vec!["network", "parse"]
} }
fn run( fn run(

View file

@ -35,7 +35,7 @@ impl Command for FileSize {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "display", "pattern", "file", "size"] vec!["convert", "display", "pattern", "human readable"]
} }
fn run( fn run(

View file

@ -34,7 +34,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["column", "separate", "divide"] vec!["separate", "divide"]
} }
fn run( fn run(

View file

@ -28,7 +28,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["list", "separate", "divide"] vec!["separate", "divide"]
} }
fn run( fn run(

View file

@ -34,7 +34,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["row", "separate", "divide"] vec!["separate", "divide"]
} }
fn run( fn run(

View file

@ -45,7 +45,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["word", "separate", "divide"] vec!["separate", "divide"]
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View file

@ -29,7 +29,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "style", "snake", "underscore", "convention"] vec!["convert", "style", "underscore", "convention"]
} }
fn run( fn run(

View file

@ -29,14 +29,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec![ vec!["convert", "style", "underscore", "lower", "convention"]
"convert",
"style",
"snake",
"underscore",
"lower",
"convention",
]
} }
fn run( fn run(

View file

@ -30,7 +30,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["convert", "style", "title", "convention"] vec!["convert", "style", "convention"]
} }
fn run( fn run(

View file

@ -52,7 +52,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["pattern", "match", "find", "search", "index"] vec!["pattern", "match", "find", "search"]
} }
fn run( fn run(

View file

@ -28,7 +28,7 @@ impl Command for SubCommand {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["len", "size", "count"] vec!["size", "count"]
} }
fn run( fn run(

View file

@ -23,3 +23,55 @@ fn quickcheck_parse(data: String) -> bool {
} }
true 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")
);
}