Skip to content

Commit

Permalink
Added tests for message
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhouse committed Mar 30, 2024
1 parent 8ada150 commit f6456aa
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/message/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,24 @@ mod tests {
assert!(message.is_err());
}

#[test]
fn test_message_with_string_4() {
let message = Message::<3>::new()
.with_command(0b0000000000000010)
.with_string("TES")
.build()
.unwrap();

// The character will be interpreted as
// zero because it wasn't given.
assert!(message.is_full());
assert_eq!(message.length(), 3);
assert_eq!(message.count(), 2);
assert_eq!(message.size(), 3);
assert!(message.is_command());
assert!(!message.is_status());
}

#[test]
fn test_message_with_bytes_0() {
let message = Message::<3>::new()
Expand All @@ -694,7 +712,7 @@ mod tests {
.with_bytes(&[1, 2, 3, 4])
.build();

// error because the string was too long
// error because too many bytes
// for the given Message
assert!(message.is_err());
}
Expand All @@ -706,7 +724,7 @@ mod tests {
.with_bytes(&[1, 2, 3, 4])
.build();

// error because the string was too long
// error because too many bytes
// for the command data word count
assert!(message.is_err());
}
Expand All @@ -718,11 +736,29 @@ mod tests {
.with_bytes(&[1, 2, 3, 4])
.build();

// error because the string was too long
// error because too many bytes
// for the given Message
assert!(message.is_err());
}

#[test]
fn test_message_with_bytes_4() {
let message = Message::<3>::new()
.with_command(0b0000000000000010)
.with_bytes(&[1, 2, 3])
.build()
.unwrap();

// The last byte of the second word will be
// zero because it wasn't given.
assert!(message.is_full());
assert_eq!(message.length(), 3);
assert_eq!(message.count(), 2);
assert_eq!(message.size(), 3);
assert!(message.is_command());
assert!(!message.is_status());
}

#[test]
fn test_message_set_string_command_0() {
let mut message = Message::<2>::new().with_command(0b0000000000000001);
Expand Down Expand Up @@ -1047,6 +1083,7 @@ mod tests {
assert_eq!(message.length(), 2);
assert_eq!(message.count(), 1);
assert_eq!(message.size(), 2);
assert_eq!(message.limit(), 1);
assert!(message.is_command());
assert!(!message.is_status());
}
Expand Down Expand Up @@ -1100,6 +1137,7 @@ mod tests {
assert_eq!(message.length(), 2);
assert_eq!(message.count(), 1);
assert_eq!(message.size(), 2);
assert_eq!(message.limit(), 1);
assert!(message.is_status());
assert!(!message.is_command());
}
Expand Down

0 comments on commit f6456aa

Please sign in to comment.