Skip to content

Commit 7114177

Browse files
Merge pull request #175 from FrameworkComputer/derive-ord
ccgx: derive Ord for AppVersion and BaseVersion
2 parents 00023c5 + 2d1aaa7 commit 7114177

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

framework_lib/src/ccgx/mod.rs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub enum SiliconId {
110110
Ccg8 = 0x3580,
111111
}
112112

113-
#[derive(Debug, PartialEq, Copy, Clone)]
113+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
114114
pub struct BaseVersion {
115115
/// Major part of the version. X of X.Y.Z.BB
116116
pub major: u8,
@@ -154,15 +154,15 @@ impl From<u32> for BaseVersion {
154154
}
155155
}
156156

157-
#[derive(Debug, PartialEq, Copy, Clone)]
157+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
158158
pub enum Application {
159159
Notebook,
160160
Monitor,
161161
AA,
162162
Invalid,
163163
}
164164

165-
#[derive(Debug, PartialEq, Copy, Clone)]
165+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
166166
pub struct AppVersion {
167167
pub application: Application,
168168
/// Major part of the version. X of X.Y.Z
@@ -309,3 +309,42 @@ fn parse_metadata_cyacd2(buffer: &[u8]) -> Option<(u32, u32)> {
309309
None
310310
}
311311
}
312+
313+
#[cfg(test)]
314+
mod tests {
315+
use super::*;
316+
317+
#[test]
318+
// Make sure deriving does what I expect, properly comparing with multiple fields
319+
fn derive_ord() {
320+
let v0_0_0 = AppVersion {
321+
application: Application::Notebook,
322+
major: 0,
323+
minor: 0,
324+
circuit: 0,
325+
};
326+
let v1_0_1 = AppVersion {
327+
application: Application::Notebook,
328+
major: 1,
329+
minor: 0,
330+
circuit: 1,
331+
};
332+
let v0_1_0 = AppVersion {
333+
application: Application::Notebook,
334+
major: 0,
335+
minor: 1,
336+
circuit: 0,
337+
};
338+
let v1_1_1 = AppVersion {
339+
application: Application::Notebook,
340+
major: 1,
341+
minor: 1,
342+
circuit: 1,
343+
};
344+
assert_eq!(v0_0_0, v0_0_0.clone());
345+
assert!(v0_0_0 < v1_0_1);
346+
assert!(v0_1_0 < v1_0_1);
347+
assert!(v1_0_1 < v1_1_1);
348+
assert!(v1_1_1 > v1_0_1);
349+
}
350+
}

0 commit comments

Comments
 (0)