mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 11:06:02 +00:00
proxmox-api/src/cli/completion.rs: add more tests
This commit is contained in:
parent
f9d4dcc540
commit
a9275caa61
@ -47,6 +47,19 @@ fn get_property_completion(
|
|||||||
return completions;
|
return completions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Schema::Boolean(BooleanSchema { .. }) = schema {
|
||||||
|
let mut completions = Vec::new();
|
||||||
|
let mut lowercase_arg = arg.to_string();
|
||||||
|
lowercase_arg.make_ascii_lowercase();
|
||||||
|
for value in ["0", "1", "yes", "no", "true", "false", "on", "off"].iter() {
|
||||||
|
if value.starts_with(&lowercase_arg) {
|
||||||
|
completions.push(value.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +295,7 @@ mod test {
|
|||||||
.default(false)
|
.default(false)
|
||||||
.schema()
|
.schema()
|
||||||
),
|
),
|
||||||
( "reqired-arg", false, &StringSchema::new("Required string argument.").schema()),
|
( "required-arg", false, &StringSchema::new("Required string argument.").schema()),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -322,6 +335,111 @@ mod test {
|
|||||||
assert_eq!((start, expect), (completion_start, completions));
|
assert_eq!((start, expect), (completion_start, completions));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nested_completion() {
|
||||||
|
|
||||||
|
let cmd_def = get_complex_test_cmddef();
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
&["help", "l0c1", "l0c2", "l0c3", "l0sub"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 ",
|
||||||
|
5,
|
||||||
|
&["--optional-arg", "--required-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 -",
|
||||||
|
5,
|
||||||
|
&["--optional-arg", "--required-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --",
|
||||||
|
5,
|
||||||
|
&["--optional-arg", "--required-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 ---",
|
||||||
|
5,
|
||||||
|
&[],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 x",
|
||||||
|
5,
|
||||||
|
&[],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --r",
|
||||||
|
5,
|
||||||
|
&["--required-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg",
|
||||||
|
5,
|
||||||
|
&["--required-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg -",
|
||||||
|
20,
|
||||||
|
// Note: --required-arg is not finished, so it still pops up
|
||||||
|
&["--required-arg", "--optional-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg test -",
|
||||||
|
25,
|
||||||
|
&["--optional-arg"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg test --optional-arg ",
|
||||||
|
40,
|
||||||
|
&["0", "1", "false", "no", "true", "yes", "on", "off"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg test --optional-arg f",
|
||||||
|
40,
|
||||||
|
&["false"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg test --optional-arg F",
|
||||||
|
40,
|
||||||
|
&["false"],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_completions(
|
||||||
|
&cmd_def,
|
||||||
|
"l0c1 --required-arg test --optional-arg Yes",
|
||||||
|
40,
|
||||||
|
&["yes"],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_help_completion() {
|
fn test_help_completion() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user