mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Refactor shell switching related code (#6258)
* Refactor shell switching related code Signed-off-by: nibon7 <nibon7@163.com> * add tests Signed-off-by: nibon7 <nibon7@163.com> * fix tests Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
@ -41,9 +41,11 @@ mod math;
|
||||
mod merge;
|
||||
mod mkdir;
|
||||
mod move_;
|
||||
mod n;
|
||||
mod network;
|
||||
mod nu_check;
|
||||
mod open;
|
||||
mod p;
|
||||
mod parse;
|
||||
mod path;
|
||||
mod prepend;
|
||||
|
31
crates/nu-command/tests/commands/n.rs
Normal file
31
crates/nu-command/tests/commands/n.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use nu_test_support::{nu, pipeline, playground::Playground};
|
||||
|
||||
#[test]
|
||||
fn switch_to_next_shell_1() {
|
||||
Playground::setup("switch_to_next_shell_1", |dirs, sandbox| {
|
||||
sandbox.mkdir("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline(
|
||||
r#"enter foo; enter ../bar; n; g | get active.0"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switch_to_next_shell_2() {
|
||||
Playground::setup("switch_to_next_shell_2", |dirs, sandbox| {
|
||||
sandbox.mkdir("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline(
|
||||
r#"enter foo; enter ../bar; n; n; g | get active.1"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
31
crates/nu-command/tests/commands/p.rs
Normal file
31
crates/nu-command/tests/commands/p.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use nu_test_support::{nu, pipeline, playground::Playground};
|
||||
|
||||
#[test]
|
||||
fn switch_to_prev_shell_1() {
|
||||
Playground::setup("switch_to_next_shell_1", |dirs, sandbox| {
|
||||
sandbox.mkdir("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline(
|
||||
r#"enter foo; enter ../bar; p; g | get active.1"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switch_to_prev_shell_2() {
|
||||
Playground::setup("switch_to_next_shell_2", |dirs, sandbox| {
|
||||
sandbox.mkdir("foo").mkdir("bar");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline(
|
||||
r#"enter foo; enter ../bar; p; p; p; g | get active.2"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user