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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ impl Command for Cd {
}
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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ impl Command for Open {
}
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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -68,7 +68,7 @@ impl Command for ToText {
}
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> {
vec!["average", "mean"]
vec!["average", "mean", "statistics"]
}
fn run(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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")
);
}