66 lines
1.8 KiB
Rust
66 lines
1.8 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn parses_server_selection_and_repository_scope() {
|
|
let args = Args::parse(
|
|
["--server", "work", "repo", "show"].map(str::to_owned),
|
|
None,
|
|
)
|
|
.unwrap();
|
|
let repository = RepositoryScope::parse("alice/project").unwrap();
|
|
|
|
assert_eq!(args.server.as_deref(), Some("work"));
|
|
assert_eq!(args.command, ["repo", "show"]);
|
|
assert_eq!(
|
|
(repository.owner.as_str(), repository.repository.as_str()),
|
|
("alice", "project")
|
|
);
|
|
assert_eq!(requested_help(&[]).unwrap(), Some(ROOT_HELP));
|
|
assert_eq!(requested_help(&["repo".into()]).unwrap(), Some(REPO_HELP));
|
|
assert!(
|
|
requested_help(&["repo".into(), "show".into(), "--help".into()])
|
|
.unwrap()
|
|
.unwrap()
|
|
.starts_with("Usage: gotcha repo show")
|
|
);
|
|
assert_eq!(
|
|
login_command(&["auth".into(), "login".into(), "code.example".into()])
|
|
.unwrap()
|
|
.unwrap()
|
|
.1,
|
|
Provider::Gitea
|
|
);
|
|
assert_eq!(
|
|
login_command(&[
|
|
"auth".into(),
|
|
"login".into(),
|
|
"code.example".into(),
|
|
"--provider".into(),
|
|
"forgejo".into(),
|
|
])
|
|
.unwrap()
|
|
.unwrap()
|
|
.1,
|
|
Provider::Forgejo
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn formats_bounded_aligned_tables_without_tabs() {
|
|
let table = format_table(
|
|
&[("INDEX", 8), ("STATE", 10), ("TITLE", 60)],
|
|
&[vec![
|
|
"22".into(),
|
|
"open".into(),
|
|
"A deliberately long issue title that must be shortened".into(),
|
|
]],
|
|
40,
|
|
);
|
|
|
|
assert!(!table.contains('\t'));
|
|
assert!(table.contains('…'));
|
|
assert_eq!(table.lines().count(), 3);
|
|
assert!(table.lines().all(|line| line.chars().count() <= 40));
|
|
assert!(table.lines().next().unwrap().starts_with("INDEX STATE"));
|
|
}
|