use super::super::{GenerateOptions, generate};
use super::remove_comments;
const CASES: [(&str, &str); 2] = [
(
"# optional: x\nitems:\n - one\n - two\n",
"optional: x\n\nitems:\n - one\n - two\n",
),
("plain: 1\n# not yaml\n", "plain: 1\n# not yaml\n"),
];
#[test]
fn lines_after_a_commented_block_keep_their_order() {
for (input, expected) in CASES {
assert_eq!(remove_comments(input), expected, "{input}");
}
}
const KEPT_AS_COMMENTS: [(&str, &[&str]); 4] = [
("# optional:\n# enabled: true\n", &["optional"]),
("# a: 1\n# b: 2\n# c: 3\n", &["a"]),
(
"# optional:\n# enabled: true\n# name: x\n# other:\n# x: 1\nx: 1\n",
&["optional", "x"],
),
("# foo:\n# - a\n# - b\nx: 1\n", &["foo", "x"]),
];
#[test]
fn only_the_first_line_of_a_commented_block_becomes_yaml() {
let options = GenerateOptions {
uncomment: true,
..GenerateOptions::default()
};
for (input, expected) in KEPT_AS_COMMENTS {
let schema = generate(input, &options).expect("generates");
let mut names: Vec<&str> = schema["properties"]
.as_object()
.expect("properties")
.keys()
.map(String::as_str)
.filter(|name| *name != "global")
.collect();
names.sort_unstable();
assert_eq!(names, expected, "{input}");
}
}