bump pyo3 and use anyhow for main functions

This commit is contained in:
Jean-Marie Mineau 2023-11-28 16:22:40 +01:00
parent 4e57289bab
commit b8b4e28f2d
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
10 changed files with 401 additions and 115 deletions

View file

@ -78,4 +78,108 @@ impl Serializable for EncodedAnnotation {
}
}
// TODO: add tests
// TODO: add more tests
#[cfg(test)]
mod test {
use super::*;
const ENCODED_ANNOTATION_RAW: &[u8] = &[
0xbe, 0x37, 0x01, 0xa8, 0x9f, 0x03, 0x1d, 0xf6, 0x33, 0x01, 0xd3, 0xe8, 0x02, 0x3f,
];
const ENCODED_ANNOTATION_RAW_2: &[u8] = &[0xf6, 0x33, 0x01, 0xd3, 0xe8, 0x02, 0x3f];
const ANNOTATION_ELEMENT_RAW: &[u8] = &[
0xa8, 0x9f, 0x03, 0x1d, 0xf6, 0x33, 0x01, 0xd3, 0xe8, 0x02, 0x3f,
];
const ENCODED_VALUE_RAW: &[u8] = &[0x1d, 0xf6, 0x33, 0x01, 0xd3, 0xe8, 0x02, 0x3f];
#[test]
fn deserialize_encoded_annotation() {
assert_eq!(
EncodedAnnotation::deserialize_from_slice(ENCODED_ANNOTATION_RAW_2).unwrap(),
EncodedAnnotation {
type_idx: Uleb128(6646),
elements: vec![AnnotationElement {
name_idx: Uleb128(46163),
value: EncodedValue::Boolean(true)
}],
}
);
assert_eq!(
EncodedAnnotation::deserialize_from_slice(ENCODED_ANNOTATION_RAW).unwrap(),
EncodedAnnotation {
type_idx: Uleb128(7102),
elements: vec![AnnotationElement {
name_idx: Uleb128(53160),
value: EncodedValue::Annotation(EncodedAnnotation {
type_idx: Uleb128(6646),
elements: vec![AnnotationElement {
name_idx: Uleb128(46163),
value: EncodedValue::Boolean(true)
}]
})
}],
}
);
}
#[test]
fn serialize_encoded_annotation() {
assert_eq!(
ENCODED_ANNOTATION_RAW_2,
EncodedAnnotation {
type_idx: Uleb128(6646),
elements: vec![AnnotationElement {
name_idx: Uleb128(46163),
value: EncodedValue::Boolean(true)
}],
}
.serialize_to_vec()
.unwrap()
.as_slice()
);
assert_eq!(
ENCODED_ANNOTATION_RAW,
EncodedAnnotation {
type_idx: Uleb128(7102),
elements: vec![AnnotationElement {
name_idx: Uleb128(53160),
value: EncodedValue::Annotation(EncodedAnnotation {
type_idx: Uleb128(6646),
elements: vec![AnnotationElement {
name_idx: Uleb128(46163),
value: EncodedValue::Boolean(true)
}]
})
}],
}
.serialize_to_vec()
.unwrap()
.as_slice()
);
}
#[test]
fn deserialize_annotation_element() {
assert_eq!(
AnnotationElement::deserialize_from_slice(ANNOTATION_ELEMENT_RAW).unwrap(),
AnnotationElement {
name_idx: Uleb128(53160),
value: EncodedValue::deserialize_from_slice(ENCODED_VALUE_RAW).unwrap(),
}
);
}
#[test]
fn serialize_annotation_element() {
assert_eq!(
ANNOTATION_ELEMENT_RAW,
AnnotationElement {
name_idx: Uleb128(53160),
value: EncodedValue::deserialize_from_slice(ENCODED_VALUE_RAW).unwrap(),
}
.serialize_to_vec()
.unwrap()
.as_slice(),
);
}
}

View file

@ -233,3 +233,39 @@ pub enum AnnotationVisibility {
#[prefix(0x02)]
System,
}
#[cfg(test)]
mod test {
use super::*;
const ANNOTATION_ITEM: &[u8] = &[
0x02, 0xbe, 0x37, 0x01, 0xa8, 0x9f, 0x03, 0x1d, 0xf6, 0x33, 0x01, 0xd3, 0xe8, 0x02, 0x3f,
];
#[test]
fn deserialize_annotation_item() {
assert_eq!(
AnnotationItem::deserialize_from_slice(ANNOTATION_ITEM).unwrap(),
AnnotationItem {
visibility: AnnotationVisibility::System,
annotation: EncodedAnnotation::deserialize_from_slice(&ANNOTATION_ITEM[1..])
.unwrap(),
}
);
}
#[test]
fn serialize_annotation_item() {
assert_eq!(
ANNOTATION_ITEM,
AnnotationItem {
visibility: AnnotationVisibility::System,
annotation: EncodedAnnotation::deserialize_from_slice(&ANNOTATION_ITEM[1..])
.unwrap(),
}
.serialize_to_vec()
.unwrap()
.as_slice()
);
}
}