use super::*;
#[test]
fn test_source_address() {
let can_id = CanId(0xFAE225D1);
assert_eq!(can_id.source_address(), 0xD1);
}
#[test]
fn test_priority() {
let can_id = CanId(0xFAE225D1);
assert_eq!(can_id.priority(), 0b110)
}
#[test]
fn test_pgn() {
let can_id = CanId(0xFAE225D1);
assert_eq!(can_id.pgn(), 0x2E200)
}
#[test]
fn test_builder() {
let position_id = CanId::builder(129029, 35) .with_priority(3)
.build();
assert!(position_id.is_ok());
let request_id = CanId::builder(59904, 35) .with_priority(6)
.to_destination(80) .build();
assert!(request_id.is_ok());
let invalid_id = CanId::builder(129029, 35) .to_destination(80) .build();
assert!(invalid_id.is_err());
}
#[test]
fn test_priority_masks_extra_bits() {
let can_id = CanId::builder(129029, 35)
.priority(0b1111_0000)
.build()
.expect("CanId must build");
assert_eq!(can_id.0 & (1 << 29), 0, "Reserved bit 29 must remain clear");
assert_eq!(can_id.priority(), 0);
}