Lines
100 %
Functions
Branches
use std::collections::HashMap;
use uuid::Uuid;
use super::Resolution;
use crate::resolve::Directory;
fn named(name: &str) -> (Uuid, Option<String>) {
(Uuid::new_v4(), Some(name.to_string()))
}
struct Fixture {
directory: Directory,
cafe: Uuid,
fn fixture() -> Fixture {
let (expenses, cafe) = (named("Expenses"), named("Cafe"));
let (lunch, other_lunch) = (named("Lunch"), named("Lunch"));
let mut directory = Directory {
accounts: vec![
expenses.clone(),
cafe.clone(),
lunch.clone(),
other_lunch.clone(),
],
account_paths: Vec::new(),
commodities: vec![named("USD"), named("JPY"), named("jpy")],
parents: HashMap::from([
(cafe.0, expenses.0),
(lunch.0, expenses.0),
(other_lunch.0, expenses.0),
]),
};
directory.account_paths = directory
.accounts
.iter()
.map(|(id, _)| (*id, Some(directory.account_path(*id))))
.collect();
Fixture {
cafe: cafe.0,
directory,
#[test]
fn an_own_id_is_an_id() {
let fx = fixture();
let key = fx.cafe.to_string();
assert_eq!(fx.directory.classify_account(&key), Resolution::Id);
fn a_root_name_is_its_path_and_a_full_path_is_a_path() {
assert_eq!(fx.directory.classify_account("Expenses"), Resolution::Path);
assert_eq!(
fx.directory.classify_account("Expenses:Cafe"),
Resolution::Path
);
fn a_nested_name_is_bare_and_carries_its_path() {
fx.directory.classify_account("Cafe"),
Resolution::Bare("Expenses:Cafe".to_string())
fn a_shared_name_or_path_is_ambiguous() {
fx.directory.classify_account("Lunch"),
Resolution::Ambiguous(2)
fx.directory.classify_account("Expenses:Lunch"),
fn a_missing_key_is_unknown() {
assert_eq!(fx.directory.classify_account("Nope"), Resolution::Unknown);
fx.directory.classify_account(&Uuid::new_v4().to_string()),
Resolution::Unknown
assert_eq!(fx.directory.classify_commodity("EUR"), Resolution::Unknown);
fn commodity_symbols_match_case_insensitively() {
assert_eq!(fx.directory.classify_commodity("usd"), Resolution::Symbol);
fx.directory.classify_commodity("JPY"),