vtparse: add a test about the TRANSITIONS value

Going to change how TRANSITIONS is generated. Add a test to ensure the
value is unlikely changed by the change. Note the string is 14K long
so we only hash its values to keep the code short.
This commit is contained in:
Jun Wu authored and Wez Furlong committed 2021-04-09 08:00:29 -07:00
1 parent 6e6d6a7f06
commit c5aa4c9772
1 file changed
+23
+23
View File
@@ -326,3 +326,26 @@ pub(crate) static EXIT: [Action; 14] = [
Action::OscEnd, // OscString
Action::None, // SosPmApcString
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_transitions() {
let v = format!("{:?}", TRANSITIONS).as_bytes().to_vec();
assert_eq!(
(
v.len(),
hash(&v, 0, 1),
hash(&v, 5381, 33), // djb2
hash(&v, 0, 65599), // sdbm
),
(14021, 626090, 11884276359605205711, 6929800990073628062)
);
}
fn hash(v: &[u8], init: u64, mul: u64) -> u64 {
v.iter()
.fold(init, |a, &b| a.wrapping_mul(mul).wrapping_add(b as u64))
}
}