Skip to content

Commit

Permalink
given we have an
Browse files Browse the repository at this point in the history
optional arrays its content my not be empty
  • Loading branch information
seakayone committed Jul 19, 2024
1 parent 1fc2620 commit b7892c6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions dsp-meta/tests/json-toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pub struct Project {
pub end_date: Option<Date>,
pub contact_point: Option<String>,
pub how_to_cite: String,
pub publications: Option<Vec<String>>,
pub grants: Option<Vec<String>>,
pub alternative_names: Option<Vec<Text>>,
pub publications: Option<NonEmpty<String>>,
pub grants: Option<NonEmpty<String>>,
pub alternative_names: Option<NonEmpty<Text>>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -266,11 +266,12 @@ pub enum TextOrUrl {

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Untagged {
text_or_url: NonEmpty<TextOrUrl>,
the_enum: NonEmpty<TextOrUrl>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct P {
some_str: Option<String>,
p: Untagged,
}

Expand All @@ -279,15 +280,16 @@ fn untagged_enum() {
let mut val =
NonEmpty::new(
UrlValue(Url {
url: "url".to_string(),
url: "http://example.com".to_string(),
text: Some("text".to_string()),
url_type: UrlType::URL,
}));
val.push(TextValue(Text([("en".to_string(), "English".to_string())].iter().cloned().collect())));
let un = P {
some_str: None,
p: Untagged {
text_or_url: val
}
the_enum: val
},
};
let foo = toml::to_string(&un).expect("To TOML");
println!("{}", foo);
Expand Down

0 comments on commit b7892c6

Please sign in to comment.