use super::*;
#[test]
fn every_spelling_of_a_named_member_reaches_that_member() {
for spelling in [
"data_matrix",
"dataMatrix",
"DATA_MATRIX",
"data matrix",
"Data-Matrix",
"DATAMATRIX",
] {
assert_eq!(
Symbology::new(spelling),
Symbology::DataMatrix,
"`{spelling}` names one standard"
);
}
}
#[test]
fn the_published_roster_is_the_table_the_doors_walk() {
let table: Vec<_> = ROSTER.iter().map(|(_, canonical)| *canonical).collect();
assert_eq!(table, Symbology::VARIANTS);
assert_eq!(Symbology::VARIANTS.len(), 24);
for (member, canonical) in ROSTER {
assert_eq!(member.as_str(), *canonical);
assert_eq!(Symbology::new(canonical), *member);
assert!(
member.is_registered(),
"{canonical} is a name this crate KNOWS"
);
assert!(!member.is_other());
}
}
#[test]
fn an_unnamed_standard_is_carried_folded_rather_than_refused() {
let seen = Symbology::new("Han Xin");
assert!(seen.is_other());
assert!(!seen.is_registered());
assert_eq!(seen.as_str(), "hanxin");
assert_eq!(
seen,
Symbology::new("HAN-XIN"),
"two producers' spellings of one unknown standard are ONE value"
);
assert!(
!Symbology::VARIANTS.contains(&seen.as_str()),
"the escape is not a member of the roster"
);
}
#[test]
fn the_vision_prefix_is_removed_only_where_a_caller_says_it_is_one() {
assert_eq!(
Symbology::from_vision("VNBarcodeSymbologyQR"),
Symbology::Qr
);
assert_eq!(
Symbology::from_vision("vn_barcode_symbology_qr"),
Symbology::Qr
);
assert_eq!(
Symbology::from_vision("VNBARCODESYMBOLOGY-DATA-MATRIX"),
Symbology::DataMatrix
);
assert_eq!(
Symbology::from_vision("qr"),
Symbology::Qr,
"a word with no prefix reaches the same member, so an adapter may call this unconditionally"
);
assert!(Symbology::new("VNBarcodeSymbologyQR").is_other());
}
#[test]
fn a_bare_prefix_is_carried_rather_than_stripped_to_nothing() {
let bare = Symbology::from_vision("VNBarcodeSymbology");
assert!(bare.is_other());
assert_eq!(bare.as_str(), "vnbarcodesymbology");
assert!(!bare.as_str().is_empty());
}
#[test]
fn a_symbology_round_trips_through_a_cursor_and_canonicalises_a_forged_one() {
for member in [Symbology::Qr, Symbology::Code93i, Symbology::new("han xin")] {
let mut bytes = Vec::new();
CursorValue::write_cursor(&member, &mut bytes);
assert_eq!(
<Symbology as CursorValue>::read_cursor(&bytes),
Some(member)
);
}
assert_eq!(
<Symbology as CursorValue>::read_cursor(b"DATA-MATRIX"),
Some(Symbology::DataMatrix),
"a client's spelling becomes the named member rather than a second value beside it"
);
assert_eq!(
<Symbology as CursorValue>::read_cursor(&[0xff, 0xfe]),
None,
"…and bytes that are not text at all are the one refusal left"
);
}