Skip to content

Commit a56307c

Browse files
committed
Implement Ord and PartialOrd for ShortFileName.
1 parent c3aef4a commit a56307c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/filesystem/filename.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ToShortFileName for ShortFileName {
3333

3434
impl ToShortFileName for &ShortFileName {
3535
fn to_short_filename(self) -> Result<ShortFileName, FilenameError> {
36-
Ok(self.clone())
36+
Ok(*self)
3737
}
3838
}
3939

@@ -48,7 +48,7 @@ impl ToShortFileName for &str {
4848
/// ISO-8859-1 encoding is assumed. All lower-case is converted to upper-case by
4949
/// default.
5050
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
51-
#[derive(PartialEq, Eq, Clone)]
51+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
5252
pub struct ShortFileName {
5353
pub(crate) contents: [u8; Self::TOTAL_LEN],
5454
}
@@ -431,6 +431,17 @@ mod test {
431431
assert_eq!(sfn, ShortFileName::create_from_str("1.C").unwrap());
432432
}
433433

434+
#[test]
435+
fn filename_ordering() {
436+
assert!(ShortFileName::create_from_str("1.C").unwrap() < ShortFileName::create_from_str("2.C").unwrap());
437+
assert!(ShortFileName::create_from_str("1.C").unwrap() < ShortFileName::create_from_str("1.D").unwrap());
438+
assert!(ShortFileName::create_from_str("12.C").unwrap() < ShortFileName::create_from_str("3.C").unwrap());
439+
assert!(ShortFileName::create_from_str("1.D").unwrap() < ShortFileName::create_from_str("12.C").unwrap());
440+
assert_eq!(ShortFileName::create_from_str("1.D").unwrap().cmp(&ShortFileName::create_from_str("1.D").unwrap()), core::cmp::Ordering::Equal);
441+
assert!(ShortFileName::create_from_str("1").unwrap() < ShortFileName::create_from_str("1.C").unwrap());
442+
assert!(ShortFileName::create_from_str("1.C").unwrap() < ShortFileName::create_from_str("2").unwrap());
443+
}
444+
434445
#[test]
435446
fn filename_empty() {
436447
assert_eq!(

0 commit comments

Comments
 (0)