in uniffi_bindgen/src/interface/mod.rs [1227:1317]
fn test_duplicate_type_names_are_an_error() {
const UDL: &str = r#"
namespace test{};
interface Testing {
constructor();
};
dictionary Testing {
u32 field;
};
"#;
let err = ComponentInterface::from_webidl(UDL, "crate_name").unwrap_err();
assert_eq!(
err.to_string(),
"Conflicting type definition for `Testing`! \
existing definition: Object { module_path: \"crate_name\", name: \"Testing\", imp: Struct }, \
new definition: Record { module_path: \"crate_name\", name: \"Testing\" }"
);
const UDL2: &str = r#"
namespace test{};
enum Testing {
"one", "two"
};
[Error]
enum Testing { "three", "four" };
"#;
let err = ComponentInterface::from_webidl(UDL2, "crate_name").unwrap_err();
assert_eq!(
err.to_string(),
"Mismatching definition for enum `Testing`!
existing definition: Enum {
name: \"Testing\",
module_path: \"crate_name\",
remote: false,
discr_type: None,
variants: [
Variant {
name: \"one\",
discr: None,
fields: [],
docstring: None,
},
Variant {
name: \"two\",
discr: None,
fields: [],
docstring: None,
},
],
shape: Enum,
non_exhaustive: false,
docstring: None,
},
new definition: Enum {
name: \"Testing\",
module_path: \"crate_name\",
remote: false,
discr_type: None,
variants: [
Variant {
name: \"three\",
discr: None,
fields: [],
docstring: None,
},
Variant {
name: \"four\",
discr: None,
fields: [],
docstring: None,
},
],
shape: Error {
flat: true,
},
non_exhaustive: false,
docstring: None,
}",
);
const UDL3: &str = r#"
namespace test{
u32 Testing();
};
enum Testing {
"one", "two"
};
"#;
let err = ComponentInterface::from_webidl(UDL3, "crate_name").unwrap_err();
assert!(format!("{err:#}").contains("Conflicting type definition for \"Testing\""));
}