Lines
100 %
Functions
Branches
use std::sync::LazyLock;
use forms::{Action, Form, TRANSACTION_EDIT};
use super::{form_command, values_of};
const KEYS: [&str; 5] = ["date", "note", "tags", "splits", "split-tags"];
static WITH_CARRIED: LazyLock<Form> = LazyLock::new(|| Form {
name: "test-carried",
title: "Carried",
fields: KEYS
.iter()
.filter_map(|key| {
TRANSACTION_EDIT
.fields
.find(|field| field.key == *key)
})
.copied()
.collect::<Vec<_>>()
.leak(),
action: Action::Mutation,
});
fn command() -> clap::Command {
form_command("edit", "Edit", &WITH_CARRIED)
}
#[test]
fn only_split_tags_of_the_nested_fields_have_an_option() {
assert_eq!(WITH_CARRIED.fields.len(), KEYS.len());
let command = command();
let longs: Vec<_> = command
.get_arguments()
.filter_map(|a| a.get_long())
.collect();
assert_eq!(
longs,
[
"date",
"note",
"tag",
"clear-tags",
"row",
"split-tag",
"clear-split-tags"
]
);
TRANSACTION_EDIT.nested_keys().collect::<Vec<_>>(),
["split-tags"]
for rejected in ["--split-tags", "--tags-split", "--clear-split-tag"] {
assert!(
command
.clone()
.try_get_matches_from(["edit", rejected, "x"])
.is_err(),
"{rejected}"
.try_get_matches_from(["edit", "--split-tag", "1:a=b"])
.is_ok()
.try_get_matches_from(["edit", "--row", "value=1"])
fn carried_fields_stay_out_of_the_overrides() {
let matches = command()
.try_get_matches_from(["edit", "--note", "x", "--row", "value=1"])
.unwrap();
let values = values_of(&WITH_CARRIED, &matches);
assert_eq!(values.text("note"), Some("x"));
.nested_keys()
.all(|key| values.rows(key).is_none())
assert_eq!(values.rows("splits").map(<[_]>::len), Some(1));
fn transaction_forms_take_tag_options() {
for form in [&forms::TRANSACTION_CREATE, &forms::TRANSACTION_EDIT] {
let matches = form_command("f", "F", form)
.try_get_matches_from(["f", "--tag", "name=trip,description=ski"])
let tags = values_of(form, &matches);
assert_eq!(tags.rows("tags").map(<[_]>::len), Some(1));
let cleared = form_command("f", "F", form)
.try_get_matches_from(["f", "--clear-tags"])
assert_eq!(values_of(form, &cleared).rows("tags"), Some(&[][..]));