Skip to content

Commit e1bf02a

Browse files
authored
Merge pull request #5 from tindzk/feat/tests
Add test cases for new traits
2 parents 61c01f6 + 6cb2fa8 commit e1bf02a

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

src/errors.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::error::Error;
12
use core::fmt;
23

34
/// Length exceeds string's capacity
@@ -19,7 +20,7 @@ impl fmt::Debug for ExceedsCapacity {
1920
}
2021
}
2122

22-
impl core::fmt::Display for ExceedsCapacity {
23+
impl fmt::Display for ExceedsCapacity {
2324
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2425
f.write_fmt(format_args!(
2526
"String length ({}) exceeds capacity ({})",
@@ -28,4 +29,4 @@ impl core::fmt::Display for ExceedsCapacity {
2829
}
2930
}
3031

31-
impl core::error::Error for ExceedsCapacity {}
32+
impl Error for ExceedsCapacity {}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ pub type StrVec112 = StrVec<u128, 112, Align128>;
164164
#[cfg(test)]
165165
mod tests {
166166
mod bounded_str_tests;
167+
mod error_tests;
167168
mod fixed_str_tests;
168169
mod str_vec_tests;
169170
}

src/tests/bounded_str_tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ fn test_alignment() {
2525
assert_eq!(mem::align_of::<BStr127>(), 128);
2626
}
2727

28+
#[test]
29+
fn test_ord() {
30+
assert!(BStr7::from("a") < BStr7::from("b"));
31+
assert!(BStr15::from("a") < BStr15::from("b"));
32+
assert!(BStr31::from("a") < BStr31::from("b"));
33+
assert!(BStr63::from("a") < BStr63::from("b"));
34+
assert!(BStr127::from("a") < BStr127::from("b"));
35+
}
36+
2837
#[test]
2938
fn test_push_str() {
3039
let mut s = BStr15::new();

src/tests/error_tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#[cfg(feature = "std")]
2+
mod std {
3+
use ::std::boxed::Box;
4+
use core::error::Error;
5+
6+
use crate::ExceedsCapacity;
7+
8+
#[test]
9+
fn test_error() {
10+
let _: Box<dyn Error> = Box::new(ExceedsCapacity {
11+
length: 16,
12+
capacity: 8,
13+
});
14+
}
15+
}

src/tests/fixed_str_tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ fn test_alignment() {
2222
assert_eq!(mem::align_of::<FStr128>(), 128);
2323
}
2424

25+
#[test]
26+
fn test_ord() {
27+
assert!(FStr8::from("a") < FStr8::from("b"));
28+
assert!(FStr16::from("a") < FStr16::from("b"));
29+
assert!(FStr32::from("a") < FStr32::from("b"));
30+
assert!(FStr64::from("a") < FStr64::from("b"));
31+
assert!(FStr128::from("a") < FStr128::from("b"));
32+
}
33+
2534
const fn f() -> FStr24 {
2635
FStr24::const_try_from("abc").unwrap()
2736
}

0 commit comments

Comments
 (0)