-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathmod.rs
47 lines (41 loc) · 1.4 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::path::PathBuf;
use cargo::util::command_prelude::*;
use cargo_test_support::cargo_test;
#[cargo_test]
fn test_get_example_candidates() {
let current_dir = std::env::current_dir().expect("Failed to get current directory");
let cwd = PathBuf::from(file!()).parent().unwrap().join("template");
let cwd = current_dir.join(cwd);
let expected = snapbox::str![
"example1
example2"
];
let actual = print_candidates(get_example_candidates(Some(cwd)));
snapbox::assert_data_eq!(actual, expected);
}
#[cargo_test]
fn test_get_registry_candidates() {
let current_dir = std::env::current_dir().expect("Failed to get current directory");
let cwd = PathBuf::from(file!()).parent().unwrap().join("template");
let cwd = current_dir.join(cwd);
let expected = snapbox::str![
"my-registry1
my-registry2"
];
let actual = print_candidates(get_registry_candidates(Some(cwd)).unwrap());
snapbox::assert_data_eq!(actual, expected);
}
fn print_candidates(candidates: Vec<clap_complete::CompletionCandidate>) -> String {
candidates
.into_iter()
.map(|candidate| {
let compl = candidate.get_value().to_str().unwrap();
if let Some(help) = candidate.get_help() {
format!("{compl}\t{help}")
} else {
compl.to_owned()
}
})
.collect::<Vec<_>>()
.join("\n")
}