forked from WyliodrinEmbeddedIoT/tockloader-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknown_boards.rs
More file actions
61 lines (54 loc) · 1.68 KB
/
Copy pathknown_boards.rs
File metadata and controls
61 lines (54 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#[derive(Debug, PartialEq)]
pub enum KnownBoardNames {
NucleoF4,
MicrobitV2,
Nrf52840dk,
NucleoU545ReQ,
}
impl KnownBoardNames {
pub fn from_str(name: &str) -> Option<Self> {
match name {
"nucleo-f4" => Some(Self::NucleoF4),
"microbit-v2" => Some(Self::MicrobitV2),
"nrf52840dk" => Some(Self::Nrf52840dk),
"nucleo-u545re-q" => Some(Self::NucleoU545ReQ),
_ => None,
}
}
pub fn to_str(&self) -> &'static str {
match &self {
KnownBoardNames::NucleoF4 => "nucleo-f4",
KnownBoardNames::MicrobitV2 => "microbit-v2",
KnownBoardNames::Nrf52840dk => "nrf52840dk",
KnownBoardNames::NucleoU545ReQ => "nucleo-u545re-q",
}
}
}
pub fn list_known_board_names() -> Vec<KnownBoardNames> {
vec![
KnownBoardNames::NucleoF4,
KnownBoardNames::MicrobitV2,
KnownBoardNames::Nrf52840dk,
KnownBoardNames::NucleoU545ReQ,
]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn from_str_and_to_str_consistent() {
for board in list_known_board_names() {
assert_eq!(KnownBoardNames::from_str(board.to_str()).unwrap(), board);
}
}
#[test]
fn list_known_boards_updated() {
let backup_list = vec![
KnownBoardNames::NucleoF4,
KnownBoardNames::MicrobitV2,
KnownBoardNames::Nrf52840dk,
KnownBoardNames::NucleoU545ReQ,
];
assert_eq!(list_known_board_names(), backup_list, "If this fails it means that you likely forgot to update `list_known_boards`, and subsequently the `list_known_boards_updated` test");
}
}