| 1 |
use serde::Deserialize; |
| 2 |
use serde::Serialize; |
| 3 |
|
| 4 |
#[derive(Debug, Serialize, Deserialize)] |
| 5 |
pub(crate) struct Recipe { |
| 6 |
pub(crate) name: String, |
| 7 |
pub(crate) description: Option<String>, |
| 8 |
#[serde(default)] |
| 9 |
pub(crate) modules: Vec<Modules>, |
| 10 |
#[serde(default)] |
| 11 |
pub(crate) packages: Vec<Packages>, |
| 12 |
} |
| 13 |
|
| 14 |
#[derive(Debug, Serialize, Deserialize)] |
| 15 |
pub(crate) struct Modules { |
| 16 |
pub(crate) name: String, |
| 17 |
pub(crate) version: Option<String>, |
| 18 |
} |
| 19 |
|
| 20 |
#[derive(Debug, Serialize, Deserialize)] |
| 21 |
pub(crate) struct Packages { |
| 22 |
pub(crate) name: String, |
| 23 |
pub(crate) version: Option<String>, |
| 24 |
} |
| 25 |
|
| 26 |
#[test] |
| 27 |
fn both_ends() { |
| 28 |
let recipe_works = toml::from_str::<Recipe>( |
| 29 |
r#" |
| 30 |
name = "testing" |
| 31 |
description = "example" |
| 32 |
modules = [] |
| 33 |
|
| 34 |
[[packages]] |
| 35 |
name = "base" |
| 36 |
"#, |
| 37 |
) |
| 38 |
.unwrap(); |
| 39 |
toml::to_string(&recipe_works).unwrap(); |
| 40 |
|
| 41 |
let recipe_fails = toml::from_str::<Recipe>( |
| 42 |
r#" |
| 43 |
name = "testing" |
| 44 |
description = "example" |
| 45 |
packages = [] |
| 46 |
|
| 47 |
[[modules]] |
| 48 |
name = "base" |
| 49 |
"#, |
| 50 |
) |
| 51 |
.unwrap(); |
| 52 |
|
| 53 |
let recipe_toml = toml::Table::try_from(recipe_fails).unwrap(); |
| 54 |
recipe_toml.to_string(); |
| 55 |
} |