Skip to content

Commit 4e9bedc

Browse files
committed
Test error type
1 parent f62cfcd commit 4e9bedc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/c_string.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,25 @@ mod tests {
394394
assert_eq!(c_string.to_str(), Ok("hello"));
395395

396396
// Call must fail since `w\0rld` contains an interior nul byte.
397-
assert!(c_string.extend_from_bytes(b"w\0rld").is_err());
397+
assert!(matches!(
398+
c_string.extend_from_bytes(b"w\0rld"),
399+
Err(ExtendError::InteriorNulByte(1))
400+
));
398401

399402
// However, the call above _must not_ have invalidated the state of our CString
400403
assert_eq!(c_string.to_str(), Ok("hello"));
401404

402405
// Call must fail since we can't store "hello world\0" in 11 bytes
403-
assert!(c_string.extend_from_bytes(b" world").is_err());
406+
assert!(matches!(
407+
c_string.extend_from_bytes(b" world"),
408+
Err(ExtendError::Capacity(CapacityError))
409+
));
404410

405411
// Yet again, the call above must not have invalidated the state of our CString
406412
// (as it would e.g. if we pushed the bytes but then failed to push the nul terminator)
407413
assert_eq!(c_string.to_str(), Ok("hello"));
408414

409-
assert!(c_string.extend_from_bytes(b" Bill").is_ok());
415+
c_string.extend_from_bytes(b" Bill").unwrap();
410416

411417
assert_eq!(c_string.to_str(), Ok("hello Bill"));
412418
}

0 commit comments

Comments
 (0)