use serde_json::json;
use super::{fanned, said};
use crate::cli::verdict::REFUSED;
use crate::verbs::doors::{CEILING, PRICE};
#[test]
fn the_money_words_fan_their_envelopes() {
assert_eq!(fanned(&["prices"]), json!({ "op": "prices" }));
assert_eq!(
fanned(&["price", "anthropic", "*", "3", "15", "0.3"]),
json!({ "op": "price", "provider": "anthropic", "model": "*",
"rates": { "input": 3, "output": 15, "cache_read": 0.3, "cache_write": 0 } })
);
assert_eq!(
fanned(&["price", "anthropic", "m", "off"]),
json!({ "op": "price", "provider": "anthropic", "model": "m" })
);
assert_eq!(
fanned(&["ceiling", "25"]),
json!({ "op": "ceiling", "usd": 25 })
);
assert_eq!(fanned(&["ceiling", "off"]), json!({ "op": "ceiling" }));
}
#[test]
fn a_rate_or_bound_that_is_no_number_earns_the_door_s_usage() {
let refusal = said(&["ceiling", "lots"]);
assert_eq!(refusal.code, REFUSED);
assert!(refusal.text.contains("\"lots\""), "{}", refusal.text);
assert!(refusal.text.contains(&CEILING.usage()), "{}", refusal.text);
let refusal = said(&["price", "anthropic", "*", "3"]);
assert!(
refusal.text.contains("two to four rates"),
"{}",
refusal.text
);
assert!(refusal.text.contains(&PRICE.usage()), "{}", refusal.text);
let refusal = said(&["price", "anthropic", "*", "--json"]);
assert!(
refusal.text.contains("`--json` goes BEFORE the word"),
"{}",
refusal.text
);
}
#[test]
fn a_wrong_arity_earns_the_door_s_range() {
for words in [
vec!["price", "anthropic"],
vec!["price", "a", "m", "1", "2", "3", "4", "5"],
vec!["ceiling"],
vec!["ceiling", "1", "2"],
] {
let refusal = said(&words);
assert_eq!(refusal.code, REFUSED, "{words:?}");
assert!(
refusal.text.contains("argument(s)"),
"{words:?}: {}",
refusal.text
);
}
}