Skip to content

Commit

Permalink
fix: EnergyConsumptionUnit JSON serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitgeist committed Sep 17, 2024
1 parent f6a2327 commit 8bb6878
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gen/schemas/hoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"l",
"kg",
"kWh",
"mJ"
"MJ"
]
},
"Feedstock": {
Expand Down
2 changes: 1 addition & 1 deletion gen/schemas/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"l",
"kg",
"kWh",
"mJ"
"MJ"
]
},
"Feedstock": {
Expand Down
1 change: 1 addition & 0 deletions gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ pub enum EnergyConsumptionUnit {
L,
Kg,
KWh,
#[serde(rename = "MJ")]
MJ,
}

Expand Down
15 changes: 15 additions & 0 deletions gen/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,18 @@ fn test_ship_foot_deser() {
let ship_foot: ShipmentFootprint = serde_json::from_str(json).unwrap();
assert_eq!(ship_foot, expected)
}

#[test]
fn test_energyconsumptionunit_deser() {
use EnergyConsumptionUnit::*;
let test_vectors = vec![
("\"l\"", L),
("\"kg\"", Kg),
("\"kWh\"", KWh),
("\"MJ\"", MJ),
];

for (expect, input) in &test_vectors {
assert_eq!(expect, &serde_json::to_string(input).unwrap());
}
}

0 comments on commit 8bb6878

Please sign in to comment.