use super::*;
#[test]
fn the_divisor_is_positive_for_every_pair_a_constructor_admits() {
for (a, b, expected) in [
(0, 1, 1),
(0, 90_000, 90_000),
(1, 1, 1),
(2, 4, 2),
(60_000, 2002, 2),
(i32::MAX, i32::MAX, i32::MAX),
(1 << 30, 2, 2),
] {
assert_eq!(gcd(a, b), expected, "gcd({a}, {b})");
assert!(gcd(a, b) > 0, "the quotient below must be total");
}
}
#[cfg(feature = "sqlx")]
#[test]
fn each_affix_wraps_the_operand_at_its_own_end() {
let of = |operand, affix| {
pattern(Some(operand), affix)
.expect("the alphabet is digits and a slash")
.expect("an operand was given")
};
assert_eq!(of("1/", Affix::Prefix).as_str(), "1/%");
assert_eq!(of("90000", Affix::Suffix).as_str(), "%90000");
assert_eq!(of("/9", Affix::Contains).as_str(), "%/9%");
assert_eq!(of("", Affix::Contains).as_str(), "%%");
}
#[cfg(feature = "sqlx")]
#[test]
fn an_absent_operand_builds_no_pattern() {
assert_eq!(pattern(None, Affix::Contains), Ok(None));
}
#[cfg(feature = "sqlx")]
#[test]
fn a_character_the_rendering_cannot_hold_is_refused_by_name() {
for outside in ['%', '_', '\\', 'e', ' ', '-', '.'] {
let operand = format!("1{outside}");
for affix in [Affix::Prefix, Affix::Suffix, Affix::Contains] {
assert_eq!(pattern(Some(&operand), affix), Err(outside), "{operand:?}");
}
}
assert_eq!(pattern(Some("%_"), Affix::Contains), Err('%'));
}
#[cfg(feature = "sqlx")]
#[test]
fn a_pattern_stays_inside_the_inline_representation() {
let widest = format!("{}/{}", i32::MAX, i32::MAX);
for operand in ["1/", "/90000", "/9", "1001/30000", widest.as_str()] {
let built = pattern(Some(operand), Affix::Contains)
.expect("the alphabet holds")
.expect("an operand was given");
assert!(
built.is_inline(),
"`{built}` ({} bytes) spilled to the heap",
built.len()
);
}
}