Merge pull request #243 from kubouch/module-files

Loading modules from files
This commit is contained in:
JT
2021-11-01 11:08:03 +13:00
committed by GitHub
6 changed files with 330 additions and 232 deletions

View File

@ -247,6 +247,14 @@ fn alias_2() -> TestResult {
)
}
#[test]
fn alias_2_multi_word() -> TestResult {
run_test(
r#"def "foo bar" [$x $y] { $x + $y + 10 }; alias f = foo bar 33; f 100"#,
"143",
)
}
#[test]
fn block_param1() -> TestResult {
run_test("[3] | each { $it + 10 } | get 0", "13")
@ -389,7 +397,7 @@ fn better_block_types() -> TestResult {
#[test]
fn module_imports_1() -> TestResult {
run_test(
r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo; foo.a"#,
r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo; foo a"#,
"1",
)
}
@ -397,7 +405,7 @@ fn module_imports_1() -> TestResult {
#[test]
fn module_imports_2() -> TestResult {
run_test(
r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo.a; a"#,
r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo a; a"#,
"1",
)
}
@ -405,7 +413,7 @@ fn module_imports_2() -> TestResult {
#[test]
fn module_imports_3() -> TestResult {
run_test(
r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo.*; b"#,
r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo *; b"#,
"2",
)
}
@ -413,7 +421,7 @@ fn module_imports_3() -> TestResult {
#[test]
fn module_imports_4() -> TestResult {
fail_test(
r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo.c"#,
r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo c"#,
"not find import",
)
}
@ -421,7 +429,7 @@ fn module_imports_4() -> TestResult {
#[test]
fn module_imports_5() -> TestResult {
run_test(
r#"module foo { export def a [] { 1 }; def b [] { 2 }; export def c [] { 3 } }; use foo.[a, c]; c"#,
r#"module foo { export def a [] { 1 }; def b [] { 2 }; export def c [] { 3 } }; use foo [a, c]; c"#,
"3",
)
}
@ -429,7 +437,7 @@ fn module_imports_5() -> TestResult {
#[test]
fn module_import_uses_internal_command() -> TestResult {
run_test(
r#"module foo { def b [] { 2 }; export def a [] { b } }; use foo; foo.a"#,
r#"module foo { def b [] { 2 }; export def a [] { b } }; use foo; foo a"#,
"2",
)
}
@ -491,7 +499,7 @@ fn hide_twice_not_allowed() -> TestResult {
#[test]
fn hides_import_1() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam.foo; foo"#,
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam foo; foo"#,
not_found_msg(),
)
}
@ -499,7 +507,7 @@ fn hides_import_1() -> TestResult {
#[test]
fn hides_import_2() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam.*; foo"#,
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam *; foo"#,
not_found_msg(),
)
}
@ -507,7 +515,7 @@ fn hides_import_2() -> TestResult {
#[test]
fn hides_import_3() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam.[foo]; foo"#,
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam [foo]; foo"#,
not_found_msg(),
)
}
@ -515,7 +523,7 @@ fn hides_import_3() -> TestResult {
#[test]
fn hides_import_4() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "foo" } }; use spam.foo; hide foo; foo"#,
r#"module spam { export def foo [] { "foo" } }; use spam foo; hide foo; foo"#,
not_found_msg(),
)
}
@ -523,7 +531,15 @@ fn hides_import_4() -> TestResult {
#[test]
fn hides_import_5() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "foo" } }; use spam.*; hide foo; foo"#,
r#"module spam { export def foo [] { "foo" } }; use spam *; hide foo; foo"#,
not_found_msg(),
)
}
#[test]
fn hides_import_6() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "foo" } }; use spam; hide spam; foo"#,
not_found_msg(),
)
}
@ -539,7 +555,7 @@ fn def_twice_should_fail() -> TestResult {
#[test]
fn use_import_after_hide() -> TestResult {
run_test(
r#"module spam { export def foo [] { "foo" } }; use spam.foo; hide foo; use spam.foo; foo"#,
r#"module spam { export def foo [] { "foo" } }; use spam foo; hide foo; use spam foo; foo"#,
"foo",
)
}
@ -547,7 +563,7 @@ fn use_import_after_hide() -> TestResult {
#[test]
fn hide_shadowed_decl() -> TestResult {
run_test(
r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; do { use spam.foo; hide foo; foo }"#,
r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; do { use spam foo; hide foo; foo }"#,
"foo",
)
}
@ -555,7 +571,7 @@ fn hide_shadowed_decl() -> TestResult {
#[test]
fn hides_all_decls_within_scope() -> TestResult {
fail_test(
r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; use spam.foo; hide foo; foo"#,
r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; use spam foo; hide foo; foo"#,
not_found_msg(),
)
}