//! The column limits, against the DDL that enforces them, and the two helpers.usesuper::*;#[test]fn the_limits_are_the_ones_the_table_checks() {let ddl = cotton_store::schema::ddl::SECRETS_TABLE;for needle in [ format!("length(name) BETWEEN 1 AND {NAME_MAX}"), format!("length(site) BETWEEN 1 AND {SITE_MAX}"), format!("length(username) BETWEEN 1 AND {USERNAME_MAX}"), format!("length(service) BETWEEN 1 AND {SERVICE_MAX}"), ] { assert!(ddl.contains(&needle), "the secrets table no longer says `{needle}`"); }}#[test]fn a_length_is_counted_in_characters_not_bytes() { assert_eq!(char_len("é"), 1); assert_eq!(char_len("日本"), 2); assert!(fits(&"é".repeat(SITE_MAX), SITE_MAX)); assert!(!fits(&"é".repeat(SITE_MAX + 1), SITE_MAX));}#[test]fn an_empty_value_does_not_fit_any_column() { assert!(!fits("", NAME_MAX));}#[test]fn a_value_that_fits_is_not_shortened() {let exact = "n".repeat(NAME_MAX); assert_eq!(shorten(&exact, NAME_MAX), exact); assert_eq!(shorten("Thimble Bank", NAME_MAX), "Thimble Bank");}#[test]fn a_value_one_over_is_cut_to_the_limit_and_ends_in_an_ellipsis() {let long = "n".repeat(NAME_MAX + 1);let short = shorten(&long, NAME_MAX); assert_eq!(char_len(&short), NAME_MAX); assert!(short.ends_with('…'));}#[test]fn shortening_cuts_on_a_character_boundary() {let long = "日".repeat(NAME_MAX * 2);let short = shorten(&long, NAME_MAX); assert_eq!(char_len(&short), NAME_MAX); assert!(fits(&short, NAME_MAX));}#[test]fn a_cut_after_a_space_does_not_leave_the_space_before_the_ellipsis() {// 118 letters, a space, then more: the first 119 end on the space.let long = format!("{} {}", "a".repeat(NAME_MAX - 2), "b".repeat(10));let short = shorten(&long, NAME_MAX); assert!(short.ends_with("a…"), "{short}"); assert!(char_len(&short) <= NAME_MAX);}