mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 07:30:13 +01:00
Change import pattern delimiter to ::
This commit is contained in:
parent
e66fd91045
commit
cbda1b1650
@ -513,7 +513,8 @@ pub fn parse_use(
|
||||
.into_iter()
|
||||
.map(|(name, id)| {
|
||||
let mut new_name = import_pattern.head.to_vec();
|
||||
new_name.push(b'.');
|
||||
new_name.push(b':');
|
||||
new_name.push(b':');
|
||||
new_name.extend(&name);
|
||||
(new_name, id)
|
||||
})
|
||||
@ -628,7 +629,8 @@ pub fn parse_hide(
|
||||
.into_iter()
|
||||
.map(|name| {
|
||||
let mut new_name = import_pattern.head.to_vec();
|
||||
new_name.push(b'.');
|
||||
new_name.push(b':');
|
||||
new_name.push(b':');
|
||||
new_name.extend(&name);
|
||||
new_name
|
||||
})
|
||||
@ -639,7 +641,8 @@ pub fn parse_hide(
|
||||
.filter(|n| n == name)
|
||||
.map(|n| {
|
||||
let mut new_name = import_pattern.head.to_vec();
|
||||
new_name.push(b'.');
|
||||
new_name.push(b':');
|
||||
new_name.push(b':');
|
||||
new_name.extend(&n);
|
||||
new_name
|
||||
})
|
||||
@ -660,7 +663,8 @@ pub fn parse_hide(
|
||||
.filter_map(|n| if n == name { Some(n.clone()) } else { None })
|
||||
.map(|n| {
|
||||
let mut new_name = import_pattern.head.to_vec();
|
||||
new_name.push(b'.');
|
||||
new_name.push(b':');
|
||||
new_name.push(b':');
|
||||
new_name.extend(n);
|
||||
new_name
|
||||
})
|
||||
|
@ -1698,7 +1698,7 @@ pub fn parse_import_pattern(
|
||||
let source = working_set.get_span_contents(span);
|
||||
let mut error = None;
|
||||
|
||||
let (tokens, err) = lex(source, span.start, &[], &[b'.']);
|
||||
let (tokens, err) = lex(source, span.start, &[], &[b':']);
|
||||
error = error.or(err);
|
||||
|
||||
if tokens.is_empty() {
|
||||
@ -1713,7 +1713,7 @@ pub fn parse_import_pattern(
|
||||
|
||||
let head = working_set.get_span_contents(tokens[0].span).to_vec();
|
||||
|
||||
if let Some(tail) = tokens.get(2) {
|
||||
if let Some(tail) = tokens.get(3) {
|
||||
// FIXME: expand this to handle deeper imports once we support module imports
|
||||
let tail_span = tail.span;
|
||||
let tail = working_set.get_span_contents(tail.span);
|
||||
|
26
src/tests.rs
26
src/tests.rs
@ -389,7 +389,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 +397,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 +405,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 +413,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 +421,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 +429,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 +491,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 +499,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 +507,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 +515,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 +523,7 @@ 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(),
|
||||
)
|
||||
}
|
||||
@ -539,7 +539,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 +547,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",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user