Lines
100 %
Functions
Branches
use super::*;
const LOW: Uuid = Uuid::from_u128(0xabcd_0000_0000_0000_0000_0000_0000_0001);
const HIGH: Uuid = Uuid::from_u128(0xabcd_9000_0000_0000_0000_0000_0000_0002);
const OTHER: Uuid = Uuid::from_u128(0x1234_0000_0000_0000_0000_0000_0000_0003);
fn entry(id: Uuid, text: &str) -> (Uuid, Vec<String>) {
(id, vec![text.to_string()])
}
fn path(id: Uuid, names: &[&str]) -> (Uuid, Vec<String>) {
(id, names.iter().map(|name| name.to_string()).collect())
fn exact(text: &str) -> String {
text.to_string()
fn lower(text: &str) -> String {
text.to_lowercase()
#[test]
fn a_shared_prefix_is_lengthened_for_both_whatever_the_input_order() {
let forward = unique_labels(&[entry(LOW, "Cash"), entry(HIGH, "Cash")], exact);
let backward = unique_labels(&[entry(HIGH, "Cash"), entry(LOW, "Cash")], exact);
assert_eq!(forward, ["Cash ‹abcd0›", "Cash ‹abcd9›"]);
assert_eq!(backward, ["Cash ‹abcd9›", "Cash ‹abcd0›"]);
fn a_member_of_a_group_does_not_depend_on_unrelated_entries() {
let labels = unique_labels(
&[
entry(OTHER, "Bank"),
entry(HIGH, "Cash"),
entry(LOW, "Cash"),
],
exact,
);
assert_eq!(labels, ["Bank", "Cash ‹abcd9›", "Cash ‹abcd0›"]);
fn padding_follows_the_full_id_when_every_prefix_is_taken() {
let base = LOW.to_string();
let hex = LOW.simple().to_string();
let mut entries = vec![entry(LOW, &base)];
entries
.extend((MIN_PREFIX..=HEX_LEN).map(|n| entry(OTHER, &format!("{base} ‹{}›", &hex[..n]))));
let labels = unique_labels(&entries, exact);
assert_eq!(labels[0], format!("{base} ‹{hex}-›"));
fn every_uuid_shape_is_reserved() {
let id = LOW.to_string();
for shape in [
LOW.simple().to_string(),
format!("{{{id}}}"),
id.to_uppercase(),
format!("urn:uuid:{id}"),
] {
let labels = unique_labels(&[entry(HIGH, &shape)], exact);
assert_eq!(labels, [format!("{shape} ‹abcd›")], "{shape}");
fn the_suffix_is_compared_after_the_case_fold() {
let entries = [
entry(LOW, "EUR"),
entry(HIGH, "eur"),
entry(OTHER, "EUR ‹ABCD›"),
];
let labels = unique_labels(&entries, lower);
assert_eq!(labels, ["EUR ‹abcd0›", "eur ‹abcd9›", "EUR ‹ABCD›"]);
fn exact_fold_keeps_case_distinct_names_apart() {
let labels = unique_labels(&[entry(LOW, "EUR"), entry(HIGH, "eur")], exact);
assert_eq!(labels, ["EUR", "eur"]);
fn pipes_and_line_breaks_are_made_cell_safe() {
let labels = unique_labels(&[entry(LOW, "A|B\r\nC\nD\rE")], exact);
assert_eq!(labels, ["A¦B C D E"]);
fn a_unique_name_is_shown_without_its_path() {
path(LOW, &["Transportation", "JR"]),
path(OTHER, &["Transportation"]),
assert_eq!(labels, ["JR", "Transportation"]);
fn a_shared_name_gets_the_shortest_parent_context() {
path(LOW, &["Expenses", "Food", "Cafe"]),
path(HIGH, &["Expenses", "Drinks", "Cafe"]),
path(OTHER, &["Expenses", "Food"]),
assert_eq!(labels, ["Food:Cafe", "Drinks:Cafe", "Food"]);
fn a_root_sharing_its_name_with_a_child_is_suffixed() {
&[path(LOW, &["Cafe"]), path(HIGH, &["Food", "Cafe"])],
assert_eq!(labels, ["Cafe ‹abcd›", "Food:Cafe"]);
fn siblings_of_one_path_are_suffixed_on_the_whole_path() {
&[path(LOW, &["Food", "Cafe"]), path(HIGH, &["Food", "Cafe"])],
assert_eq!(labels, ["Food:Cafe ‹abcd0›", "Food:Cafe ‹abcd9›"]);
fn a_context_form_is_never_another_entrys_name() {
path(LOW, &["Food", "Cafe"]),
path(HIGH, &["Bar", "Cafe"]),
path(OTHER, &["Food:Cafe"]),
assert_eq!(labels, ["Food:Cafe ‹abcd›", "Bar:Cafe", "Food:Cafe ‹1234›"]);