fix(interface): preserve operation item uniqueness
Disambiguate generated argument types when distinct operation names normalize to the same PascalCase form, and add the requested Number round-trip and collision regression coverage.
This commit is contained in:
@@ -216,3 +216,41 @@ fn typed_dispatch_validates_decodes_invokes_encodes_and_validates() {
|
||||
let unknown = CatalogDefinition::dispatch(&AcceptingCatalog, "missing", vec![]).unwrap_err();
|
||||
assert!(matches!(unknown, DispatchError::UnknownOperation(name) if name == "missing"));
|
||||
}
|
||||
|
||||
/// Operations whose distinct source names normalize to the same PascalCase.
|
||||
#[interface]
|
||||
pub trait DistinctOperations {
|
||||
/// Returns the first item marker.
|
||||
fn item(&self) -> OperationResult<String>;
|
||||
|
||||
/// Returns the underscored item marker.
|
||||
fn item_(&self) -> OperationResult<String>;
|
||||
}
|
||||
|
||||
struct DistinctImplementation;
|
||||
|
||||
impl DistinctOperations for DistinctImplementation {
|
||||
fn item(&self) -> OperationResult<String> {
|
||||
Ok("item".into())
|
||||
}
|
||||
|
||||
fn item_(&self) -> OperationResult<String> {
|
||||
Ok("item_".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distinct_operation_names_always_generate_distinct_public_items() {
|
||||
let descriptor = DistinctOperationsDefinition::descriptor();
|
||||
assert_eq!(descriptor.operations[0].name, "item");
|
||||
assert_eq!(descriptor.operations[1].name, "item_");
|
||||
|
||||
let first = DistinctOperationsDefinition::dispatch(&DistinctImplementation, "item", vec![])
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let second = DistinctOperationsDefinition::dispatch(&DistinctImplementation, "item_", vec![])
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(first, Value::String("item".into()));
|
||||
assert_eq!(second, Value::String("item_".into()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user