Yield proper user-facing error when inferring Fuzzer usage

This commit is contained in:
KtorZ
2024-03-02 12:55:56 +01:00
parent cf61387a41
commit bbc9fc5762
4 changed files with 218 additions and 34 deletions

View File

@@ -1202,6 +1202,113 @@ fn pipe_with_wrong_type_and_full_args() {
))
}
#[test]
fn fuzzer_ok_basic() {
let source_code = r#"
fn int() -> Fuzzer<Int> { todo }
test prop(n via int()) { todo }
"#;
assert!(check(parse(source_code)).is_ok());
}
#[test]
fn fuzzer_ok_explicit() {
let source_code = r#"
fn int(prng: PRNG) -> Option<(PRNG, Int)> { todo }
test prop(n via int) { todo }
"#;
assert!(check(parse(source_code)).is_ok());
}
#[test]
fn fuzzer_ok_list() {
let source_code = r#"
fn int() -> Fuzzer<Int> { todo }
fn list(a: Fuzzer<a>) -> Fuzzer<List<a>> { todo }
test prop(xs via list(int())) { todo }
"#;
assert!(check(parse(source_code)).is_ok());
}
#[test]
fn fuzzer_err_unbound() {
let source_code = r#"
fn any() -> Fuzzer<a> { todo }
fn list(a: Fuzzer<a>) -> Fuzzer<List<a>> { todo }
test prop(xs via list(any())) { todo }
"#;
assert!(matches!(
check(parse(source_code)),
Err((_, Error::GenericLeftAtBoundary { .. }))
))
}
#[test]
fn fuzzer_err_unify_1() {
let source_code = r#"
test prop(xs via Void) { todo }
"#;
assert!(matches!(
check(parse(source_code)),
Err((
_,
Error::CouldNotUnify {
situation: None,
..
}
))
))
}
#[test]
fn fuzzer_err_unify_2() {
let source_code = r#"
fn any() -> Fuzzer<a> { todo }
test prop(xs via any) { todo }
"#;
assert!(matches!(
check(parse(source_code)),
Err((
_,
Error::CouldNotUnify {
situation: None,
..
}
))
))
}
#[test]
fn fuzzer_err_unify_3() {
let source_code = r#"
fn list(a: Fuzzer<a>) -> Fuzzer<List<a>> { todo }
fn int() -> Fuzzer<Int> { todo }
test prop(xs: Int via list(int())) { todo }
"#;
assert!(matches!(
check(parse(source_code)),
Err((
_,
Error::CouldNotUnify {
situation: Some(UnifyErrorSituation::FuzzerAnnotationMismatch),
..
}
))
))
}
#[test]
fn utf8_hex_literal_warning() {
let source_code = r#"