in crates/q_chat/src/command.rs [881:1051]
fn test_command_parse() {
let mut stdout = std::io::stdout();
macro_rules! profile {
($subcommand:expr) => {
Command::Profile {
subcommand: $subcommand,
}
};
}
macro_rules! context {
($subcommand:expr) => {
Command::Context {
subcommand: $subcommand,
}
};
}
macro_rules! compact {
($prompt:expr, $show_summary:expr) => {
Command::Compact {
prompt: $prompt,
show_summary: $show_summary,
help: false,
}
};
}
let tests = &[
("/compact", compact!(None, true)),
(
"/compact custom prompt",
compact!(Some("custom prompt".to_string()), true),
),
("/profile list", profile!(ProfileSubcommand::List)),
(
"/profile create new_profile",
profile!(ProfileSubcommand::Create {
name: "new_profile".to_string(),
}),
),
(
"/profile delete p",
profile!(ProfileSubcommand::Delete { name: "p".to_string() }),
),
(
"/profile rename old new",
profile!(ProfileSubcommand::Rename {
old_name: "old".to_string(),
new_name: "new".to_string(),
}),
),
(
"/profile set p",
profile!(ProfileSubcommand::Set { name: "p".to_string() }),
),
(
"/profile set p",
profile!(ProfileSubcommand::Set { name: "p".to_string() }),
),
("/context show", context!(ContextSubcommand::Show { expand: false })),
(
"/context show --expand",
context!(ContextSubcommand::Show { expand: true }),
),
(
"/context add p1 p2",
context!(ContextSubcommand::Add {
global: false,
force: false,
paths: vec!["p1".into(), "p2".into()]
}),
),
(
"/context add --global --force p1 p2",
context!(ContextSubcommand::Add {
global: true,
force: true,
paths: vec!["p1".into(), "p2".into()]
}),
),
(
"/context rm p1 p2",
context!(ContextSubcommand::Remove {
global: false,
paths: vec!["p1".into(), "p2".into()]
}),
),
(
"/context rm --global p1 p2",
context!(ContextSubcommand::Remove {
global: true,
paths: vec!["p1".into(), "p2".into()]
}),
),
("/context clear", context!(ContextSubcommand::Clear { global: false })),
(
"/context clear --global",
context!(ContextSubcommand::Clear { global: true }),
),
("/issue", Command::Issue { prompt: None }),
("/issue there was an error in the chat", Command::Issue {
prompt: Some("there was an error in the chat".to_string()),
}),
("/issue \"there was an error in the chat\"", Command::Issue {
prompt: Some("\"there was an error in the chat\"".to_string()),
}),
(
"/context hooks",
context!(ContextSubcommand::Hooks { subcommand: None }),
),
(
"/context hooks add test --trigger per_prompt --command 'echo 1' --global",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::Add {
name: "test".to_string(),
global: true,
trigger: "per_prompt".to_string(),
command: "echo 1".to_string()
})
}),
),
(
"/context hooks rm test --global",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::Remove {
name: "test".to_string(),
global: true
})
}),
),
(
"/context hooks enable test --global",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::Enable {
name: "test".to_string(),
global: true
})
}),
),
(
"/context hooks disable test",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::Disable {
name: "test".to_string(),
global: false
})
}),
),
(
"/context hooks enable-all --global",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::EnableAll { global: true })
}),
),
(
"/context hooks disable-all",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::DisableAll { global: false })
}),
),
(
"/context hooks help",
context!(ContextSubcommand::Hooks {
subcommand: Some(HooksSubcommand::Help)
}),
),
];
for (input, parsed) in tests {
assert_eq!(&Command::parse(input, &mut stdout).unwrap(), parsed, "{}", input);
}
}