From c5aa4c9772c74eaf5106f74fa8da1400a606ccaf Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Thu, 8 Apr 2021 22:41:41 -0700 Subject: [PATCH] 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. --- vtparse/src/transitions.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/vtparse/src/transitions.rs b/vtparse/src/transitions.rs index 357067014..d61529cff 100644 --- a/vtparse/src/transitions.rs +++ b/vtparse/src/transitions.rs @@ -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)) + } +}