-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for List of Array examples. #177
Changes from 4 commits
35d30c1
bc4cccf
26f7409
7740726
ef764cc
b91c6ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,6 +410,14 @@ pub enum Examples { | |
Bools(Vec<bool>), | ||
/// A array of strings example. | ||
Strings(Vec<String>), | ||
/// List of arrays of integers example. | ||
ListOfInts(Vec<Vec<i64>>), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test to ensure this is working? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added tests... feels like I'm just testing serde_yaml though ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, and agreed. I had intended for those tests to be on full resolution ensuring these are preserved through the resolution process, but what you have is fine for now. |
||
/// List of arrays of doubles example. | ||
ListOfDoubles(Vec<Vec<OrderedFloat<f64>>>), | ||
/// List of arrays of bools example. | ||
ListOfBools(Vec<Vec<bool>>), | ||
/// List of arrays of strings example. | ||
ListOfStrings(Vec<Vec<String>>), | ||
} | ||
|
||
/// The different requirement level specifications. | ||
|
@@ -772,6 +780,154 @@ mod tests { | |
assert_eq!(attr.tag(), Some("tag".to_owned())); | ||
assert!(attr.is_required()); | ||
} | ||
|
||
#[test] | ||
fn test_examples_bool() { | ||
let yaml = "---\ntrue"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::Bool(true)); | ||
} | ||
|
||
#[test] | ||
fn test_examples_int() { | ||
let yaml = "---\n42"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::Int(42)); | ||
} | ||
|
||
#[test] | ||
fn test_examples_double() { | ||
let yaml = "---\n3.15"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::Double(OrderedFloat(3.15))); | ||
} | ||
|
||
#[test] | ||
fn test_examples_string() { | ||
let yaml = "---\n\"foo\""; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::String("foo".to_owned())); | ||
} | ||
|
||
#[test] | ||
fn test_examples_strings() { | ||
let yaml = "---\n- \"foo\"\n- \"bar\""; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::Strings(vec!["foo".to_owned(), "bar".to_owned()]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_ints() { | ||
let yaml = "---\n- 42\n- 43"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::Ints(vec![42, 43])); | ||
} | ||
|
||
#[test] | ||
fn test_examples_doubles() { | ||
let yaml = "---\n- 3.15\n- 2.71"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::Doubles(vec![OrderedFloat(3.15), OrderedFloat(2.71)]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_bools() { | ||
let yaml = "---\n- true\n- false"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::Bools(vec![true, false])); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_ints() { | ||
let yaml = "---\n- [42, 43]\n- [44, 45]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::ListOfInts(vec![vec![42, 43], vec![44, 45]])); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_doubles() { | ||
let yaml = "---\n- [3.15, 2.71]\n- [1.41, 1.61]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::ListOfDoubles(vec![ | ||
vec![OrderedFloat(3.15), OrderedFloat(2.71)], | ||
vec![OrderedFloat(1.41), OrderedFloat(1.61)] | ||
]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_bools() { | ||
let yaml = "---\n- [true, false]\n- [false, true]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::ListOfBools(vec![vec![true, false], vec![false, true]]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_strings() { | ||
let yaml = "---\n- [\"foo\", \"bar\"]\n- [\"baz\", \"qux\"]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::ListOfStrings(vec![ | ||
vec!["foo".to_owned(), "bar".to_owned()], | ||
vec!["baz".to_owned(), "qux".to_owned()] | ||
]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_ints_array_style() { | ||
let yaml = "[ [42, 43], [44, 45] ]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!(ex, Examples::ListOfInts(vec![vec![42, 43], vec![44, 45]])); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_doubles_array_style() { | ||
let yaml = "[ [3.15, 2.71], [1.41, 1.61] ]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::ListOfDoubles(vec![ | ||
vec![OrderedFloat(3.15), OrderedFloat(2.71)], | ||
vec![OrderedFloat(1.41), OrderedFloat(1.61)] | ||
]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_bools_array_style() { | ||
let yaml = "[ [true, false], [false, true] ]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::ListOfBools(vec![vec![true, false], vec![false, true]]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_examples_list_of_strings_array_style() { | ||
let yaml = "[ [\"foo\", \"bar\"], [\"baz\", \"qux\"] ]"; | ||
let ex: Examples = serde_yaml::from_str(yaml).unwrap(); | ||
assert_eq!( | ||
ex, | ||
Examples::ListOfStrings(vec![ | ||
vec!["foo".to_owned(), "bar".to_owned()], | ||
vec!["baz".to_owned(), "qux".to_owned()] | ||
]) | ||
); | ||
} | ||
} | ||
|
||
/// An attribute definition with its provenance (path or URL). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These [!NOTE] are valid GitHub Markdown Extensions, see the following blog post.
https://docs.github.com/fr/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts