use crate::metis::{Anchor, Locus, Rhapsody};
use super::super::d;
use super::rank;
use crate::metis::dot::RawDot;
#[test]
fn test_rhapsody_to_bytes_layout() {
let mut rhapsody = Rhapsody::new();
assert!(rhapsody.weave(
d(1, 1),
Locus {
anchor: Anchor::Origin,
rank: rank(7)
}
));
assert!(rhapsody.weave(
d(1, 2),
Locus {
anchor: Anchor::After(RawDot {
station: 1,
counter: 1
}),
rank: rank(9),
}
));
let frame = rhapsody.to_bytes();
assert_eq!(
frame,
[
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, ]
);
assert_eq!(Rhapsody::from_bytes(&frame), Ok(rhapsody));
}
#[test]
fn test_rhapsody_before_anchor_round_trips() {
let mut rhapsody = Rhapsody::new();
assert!(rhapsody.weave(
d(1, 1),
Locus {
anchor: Anchor::Origin,
rank: rank(7)
}
));
assert!(rhapsody.weave(
d(1, 2),
Locus {
anchor: Anchor::Before(RawDot {
station: 1,
counter: 1
}),
rank: rank(9),
}
));
let frame = rhapsody.to_bytes();
assert_eq!(
frame[47], 0x02,
"the before-anchored locus carries tag 0x02"
);
assert_eq!(rhapsody.order(), [d(1, 2), d(1, 1)]);
let decoded = Rhapsody::from_bytes(&frame).expect("a before-anchored frame decodes");
assert_eq!(decoded, rhapsody);
assert_eq!(decoded.to_bytes(), frame);
}