Skip to content

Commit

Permalink
test: Add a test of instantiating an extension set
Browse files Browse the repository at this point in the history
  • Loading branch information
croyzor committed Apr 16, 2024
1 parent d69198e commit 266eb41
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hugr/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,34 @@ mod test {
);
Ok(())
}

#[test]
fn instantiate_extension_delta() -> Result<(), Box<dyn std::error::Error>> {
use crate::extension::prelude::{BOOL_T, PRELUDE_REGISTRY};

let mut e = Extension::new(EXT_ID);
let ext_id = e.name().clone();

let es = ExtensionSet::singleton(&ext_id);
let params: Vec<TypeParam> = vec![TypeParam::Extensions];
let args = [TypeArg::Extensions { es: es.clone() }];
let mut db_set = ExtensionSet::new();
db_set.insert_type_var(0);
let fun_ty = FunctionType::new_endo(vec![BOOL_T]).with_extension_delta(db_set);

let exp_fun_ty = FunctionType::new_endo(vec![BOOL_T]).with_extension_delta(es);

let def = e.add_op(
"SimpleOp".into(),
"".into(),
PolyFuncType::new(params.clone(), fun_ty),
)?;
def.validate_args(&args, &PRELUDE_REGISTRY, &params)
.unwrap();
assert_eq!(
def.compute_signature(&args, &PRELUDE_REGISTRY),
Ok(exp_fun_ty)
);
Ok(())
}
}

0 comments on commit 266eb41

Please sign in to comment.