Fix windows_gen handling of external features
@@ -124,7 +124,9 @@ impl Gen {
continue;
}
- let feature = &feature[self.root.len() + 1..];
+ let feature = if feature.starts_with(self.root) && feature[self.root.len()..].starts_with('.') { &feature[self.root.len() + 1..] } else { &feature };
+
+ let feature = &feature.strip_prefix(format!("{}.", self.root).as_str()).unwrap_or(feature);
tokens.push_str(&format!("feature = \"{}\", ", feature.replace('.', "_")));
count += 1;
}
@@ -174,4 +176,15 @@ mod tests {
assert_eq!(Gen::relative("Windows.Foundation.Collections").namespace("Windows.Foundation").as_str(), "super::");
}
+
+ #[test]
+ fn test_features() {
+ let mut features = BTreeSet::new();
+ features.insert("Windows.Foundation");
+ assert_eq!(Gen { root: "Microsoft", relative: "" }.gen_cfg(&features).as_str(), r#"#[cfg(feature = "Windows_Foundation")]"#);
+
+ let mut features = BTreeSet::new();
+ features.insert("Microsoft.Foundation");
+ assert_eq!(Gen { root: "Microsoft", relative: "" }.gen_cfg(&features).as_str(), r#"#[cfg(feature = "Foundation")]"#);
+ }
}
