From 983902fca8f1b78358a8fd5918d95ffaabebb324 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sat, 15 Mar 2025 23:00:55 +0100 Subject: [PATCH] add extra regression test from stdlib. Signed-off-by: KtorZ --- crates/aiken-lang/src/tests/check.rs | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index c8e67fda..1e4afa1b 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -2267,6 +2267,42 @@ fn allow_expect_into_opaque_type_constructor_without_typecasting_in_module() { assert!(check(parse(source_code)).is_ok()); } +#[test] +fn use_imported_type_as_namespace_for_patterns() { + let dependency = r#" + pub type Credential { + VerificationKey(ByteArray) + Script(ByteArray) + } + "#; + + let source_code = r#" + use cardano/address.{Credential, Script, VerificationKey} + + pub fn compare(left: Credential, right: Credential) -> Ordering { + when left is { + Script(left) -> + when right is { + Script(right) -> Equal + _ -> Less + } + VerificationKey(left) -> + when right is { + Script(_) -> Greater + VerificationKey(right) -> Equal + } + } + } + "#; + + let result = check_with_deps( + dbg!(parse(source_code)), + vec![(parse_as(dependency, "cardano/address"))], + ); + + assert!(matches!(result, Ok(..)), "{result:#?}"); +} + #[test] fn use_type_as_namespace_for_patterns() { let dependency = r#"