fix value serialization and add test for boolean value for regression
This commit is contained in:
parent
c81a72ae36
commit
cc6ce1c625
2 changed files with 34 additions and 4 deletions
|
|
@ -250,7 +250,7 @@ impl Serializable for EncodedValue {
|
|||
})?;
|
||||
let [byte] = buffer;
|
||||
let arg = (byte & 0b1110_0000) >> 5;
|
||||
match ValueType(byte & 0b0011_1111) {
|
||||
match ValueType(byte & 0b0001_1111) {
|
||||
VALUE_BYTE => {
|
||||
if arg != 0 {
|
||||
Err(Error::DeserializationError(format!(
|
||||
|
|
@ -669,4 +669,34 @@ impl Serializable for Idx {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: TESTS!!!
|
||||
// TODO: more TESTS!!!
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn boolean_deserialize() {
|
||||
assert_eq!(
|
||||
EncodedValue::deserialize_from_slice(&[0b0001_1111]).unwrap(),
|
||||
EncodedValue::Boolean(false)
|
||||
);
|
||||
assert_eq!(
|
||||
EncodedValue::deserialize_from_slice(&[0b0011_1111]).unwrap(),
|
||||
EncodedValue::Boolean(true)
|
||||
);
|
||||
assert!(EncodedValue::deserialize_from_slice(&[0b0101_1111]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boolean_serialize() {
|
||||
assert_eq!(
|
||||
EncodedValue::Boolean(false).serialize_to_vec().unwrap(),
|
||||
vec![0b0001_1111]
|
||||
);
|
||||
assert_eq!(
|
||||
EncodedValue::Boolean(true).serialize_to_vec().unwrap(),
|
||||
vec![0b0011_1111]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue