Constrain and solve import params

No reporting yet
This commit is contained in:
Agus Zubiaga 2024-06-27 18:27:33 -03:00
parent c541dd5747
commit 5ec4b042bb
No known key found for this signature in database
18 changed files with 238 additions and 26 deletions

View file

@ -1564,7 +1564,7 @@ fn cannot_use_original_name_if_imported_with_alias() {
}
#[test]
fn import_module_params_no_warn() {
fn module_params_checks() {
let modules = vec![
(
"Api.roc",
@ -1590,10 +1590,73 @@ fn import_module_params_no_warn() {
),
];
let result = multiple_modules("module_params_typecheck", modules);
let result = multiple_modules("module_params_checks", modules);
assert!(result.is_ok());
}
#[test]
fn module_params_optional() {
let modules = vec![
(
"Api.roc",
indoc!(
r#"
module { key, exp ? "default" } -> [url]
url = "example.com/$(key)?exp=$(exp)"
"#
),
),
(
"Main.roc",
indoc!(
r#"
module [example]
import Api { key: "abcdef" }
example = Api.url
"#
),
),
];
let result = multiple_modules("module_params_optional", modules);
assert!(result.is_ok())
}
#[test]
#[should_panic]
fn module_params_typecheck_fail() {
let modules = vec![
(
"Api.roc",
indoc!(
r#"
module { key } -> [url]
url = "example.com/$(key)"
"#
),
),
(
"Main.roc",
indoc!(
r#"
module [example]
import Api { key: 123 }
example = Api.url
"#
),
),
];
multiple_modules("module_params_typecheck", modules).unwrap_err();
// todo(agus): test reporting
}
#[test]
fn issue_2863_module_type_does_not_exist() {
let modules = vec![