|
1 | | -use saphyr::Yaml; |
| 1 | +use saphyr::{LoadableYamlNode, Yaml}; |
2 | 2 |
|
3 | 3 | #[derive(Debug, Clone, Default)] |
4 | 4 | pub struct MetaData { |
@@ -91,24 +91,35 @@ impl MetaData { |
91 | 91 | let Some(yaml) = yamls.first() else { return Self::default() }; |
92 | 92 | Self { |
93 | 93 | // description: yaml["description"].as_str().unwrap_or_default().into(), |
94 | | - esid: yaml["esid"].as_str().map(Into::into), |
| 94 | + esid: yaml |
| 95 | + .as_mapping_get("esid") |
| 96 | + .and_then(|v| v.as_str()) |
| 97 | + .map(|s| s.to_string().into_boxed_str()), |
95 | 98 | // es5id: yaml["es5id"].as_str().map(Into::into), |
96 | 99 | // es6id: yaml["es6id"].as_str().map(Into::into), |
97 | 100 | // info: yaml["info"].as_str().unwrap_or_default().into(), |
98 | | - features: Self::get_vec_of_string(&yaml["features"]), |
99 | | - includes: Self::get_vec_of_string(&yaml["includes"]), |
100 | | - flags: yaml["flags"] |
101 | | - .as_vec() |
102 | | - .map_or_else(Vec::new, |a| { |
103 | | - a.iter() |
| 101 | + features: yaml |
| 102 | + .as_mapping_get("features") |
| 103 | + .map(Self::get_vec_of_string) |
| 104 | + .unwrap_or_default(), |
| 105 | + includes: yaml |
| 106 | + .as_mapping_get("includes") |
| 107 | + .map(Self::get_vec_of_string) |
| 108 | + .unwrap_or_default(), |
| 109 | + flags: yaml |
| 110 | + .as_mapping_get("flags") |
| 111 | + .and_then(|v| v.as_vec()) |
| 112 | + .map(|vec| { |
| 113 | + vec.iter() |
104 | 114 | .map(|v| v.as_str().map(TestFlag::from_str).unwrap()) |
105 | 115 | .collect::<Vec<_>>() |
| 116 | + .into_boxed_slice() |
106 | 117 | }) |
107 | | - .into(), |
108 | | - negative: { |
109 | | - let yaml = &yaml["negative"]; |
110 | | - (!yaml.is_null() && !yaml.is_badvalue()).then(|| Negative::from_yaml(yaml)) |
111 | | - }, |
| 118 | + .unwrap_or_default(), |
| 119 | + negative: yaml |
| 120 | + .as_mapping_get("negative") |
| 121 | + .filter(|yaml| (!yaml.is_null() && !yaml.is_badvalue())) |
| 122 | + .map(|yaml| Negative::from_yaml(yaml)), |
112 | 123 | // locale: Self::get_vec_of_string(&yaml["locale"]), |
113 | 124 | } |
114 | 125 | } |
|
0 commit comments