forked from extern/nushell
57af9b5040
This commit contains two improvements: - Support for a Range syntax (and a corresponding Range value) - Work towards a signature syntax Implementing the Range syntax resulted in cleaning up how operators in the core syntax works. There are now two kinds of infix operators - tight operators (`.` and `..`) - loose operators Tight operators may not be interspersed (`$it.left..$it.right` is a syntax error). Loose operators require whitespace on both sides of the operator, and can be arbitrarily interspersed. Precedence is left to right in the core syntax. Note that delimited syntax (like `( ... )` or `[ ... ]`) is a single token node in the core syntax. A single token node can be parsed from beginning to end in a context-free manner. The rule for `.` is `<token node>.<member>`. The rule for `..` is `<token node>..<token node>`. Loose operators all have the same syntactic rule: `<token node><space><loose op><space><token node>`. The second aspect of this pull request is the beginning of support for a signature syntax. Before implementing signatures, a necessary prerequisite is for the core syntax to support multi-line programs. That work establishes a few things: - `;` and newlines are handled in the core grammar, and both count as "separators" - line comments begin with `#` and continue until the end of the line In this commit, multi-token productions in the core grammar can use separators interchangably with spaces. However, I think we will ultimately want a different rule preventing separators from occurring before an infix operator, so that the end of a line is always unambiguous. This would avoid gratuitous differences between modules and repl usage. We already effectively have this rule, because otherwise `x<newline> | y` would be a single pipeline, but of course that wouldn't work.
384 lines
9.3 KiB
Rust
384 lines
9.3 KiB
Rust
mod helpers;
|
|
|
|
use helpers::{Playground, Stub::*};
|
|
use std::path::PathBuf;
|
|
|
|
#[test]
|
|
fn filesystem_change_from_current_directory_using_relative_path() {
|
|
Playground::setup("cd_test_1", |dirs, _| {
|
|
let actual = nu!(
|
|
cwd: dirs.root(),
|
|
r#"
|
|
cd cd_test_1
|
|
pwd | echo $it
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), *dirs.test());
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_change_from_current_directory_using_absolute_path() {
|
|
Playground::setup("cd_test_2", |dirs, _| {
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
cd {}
|
|
pwd | echo $it
|
|
"#,
|
|
dirs.formats()
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), dirs.formats());
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_switch_back_to_previous_working_directory() {
|
|
Playground::setup("cd_test_3", |dirs, sandbox| {
|
|
sandbox.mkdir("odin");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test().join("odin"),
|
|
r#"
|
|
cd {}
|
|
cd -
|
|
pwd | echo $it
|
|
"#,
|
|
dirs.test()
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), dirs.test().join("odin"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesytem_change_from_current_directory_using_relative_path_and_dash() {
|
|
Playground::setup("cd_test_4", |dirs, sandbox| {
|
|
sandbox.within("odin").mkdir("-");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
cd odin/-
|
|
pwd | echo $it
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), dirs.test().join("odin").join("-"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_change_current_directory_to_parent_directory() {
|
|
Playground::setup("cd_test_5", |dirs, _| {
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
cd ..
|
|
pwd | echo $it
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), *dirs.root());
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_change_to_home_directory() {
|
|
Playground::setup("cd_test_6", |dirs, _| {
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
cd ~
|
|
pwd | echo $it
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), dirs::home_dir().unwrap());
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_change_to_a_directory_containing_spaces() {
|
|
Playground::setup("cd_test_7", |dirs, sandbox| {
|
|
sandbox.mkdir("robalino turner katz");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
cd "robalino turner katz"
|
|
pwd | echo $it
|
|
"#
|
|
);
|
|
|
|
assert_eq!(
|
|
PathBuf::from(actual),
|
|
dirs.test().join("robalino turner katz")
|
|
);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_not_a_directory() {
|
|
Playground::setup("cd_test_8", |dirs, sandbox| {
|
|
sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]);
|
|
|
|
let actual = nu_error!(
|
|
cwd: dirs.test(),
|
|
"cd ferris_did_it.txt"
|
|
);
|
|
|
|
assert!(actual.contains("ferris_did_it.txt"), "actual={:?}", actual);
|
|
assert!(actual.contains("is not a directory"), "actual={:?}", actual);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn filesystem_directory_not_found() {
|
|
let actual = nu_error!(
|
|
cwd: "tests/fixtures",
|
|
"cd dir_that_does_not_exist"
|
|
);
|
|
|
|
assert!(
|
|
actual.contains("dir_that_does_not_exist"),
|
|
"actual={:?}",
|
|
actual
|
|
);
|
|
assert!(
|
|
actual.contains("directory not found"),
|
|
"actual={:?}",
|
|
actual
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_change_from_current_path_using_relative_path() {
|
|
Playground::setup("cd_test_9", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[[bin]]
|
|
path = "src/plugins/turner.rs"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/robalino.rs"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/katz.rs"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd bin
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/bin"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_change_from_current_path_using_absolute_path() {
|
|
Playground::setup("cd_test_10", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[dependencies]
|
|
turner-ts = "0.1.1"
|
|
robalino-tkd = "0.0.1"
|
|
katz-ember = "0.2.3"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/arepa.rs"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/bbq.rs"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd bin
|
|
cd /dependencies
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/dependencies"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_switch_back_to_previous_working_path() {
|
|
Playground::setup("cd_test_11", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[dependencies]
|
|
turner-ts = "0.1.1"
|
|
robalino-tkd = "0.0.1"
|
|
katz-ember = "0.2.3"
|
|
odin-gf = "0.2.1"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/arepa.rs"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/bbq.rs"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd dependencies
|
|
cd /bin
|
|
cd -
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/dependencies"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
|
Playground::setup("cd_test_12", |dirs, sandbox| {
|
|
sandbox
|
|
.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
- = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
|
|
|
[[bin]]
|
|
path = "src/plugins/arepa.rs"
|
|
|
|
[[bin]]
|
|
path = "src/plugins/bbq.rs"
|
|
"#
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd package/-
|
|
cd /bin
|
|
cd -
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/package/-"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_change_current_path_to_parent_path() {
|
|
Playground::setup("cd_test_13", |dirs, sandbox| {
|
|
sandbox
|
|
.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[package]
|
|
emberenios = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
|
"#
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd package/emberenios
|
|
cd ..
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/package"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_change_to_home_directory() {
|
|
Playground::setup("cd_test_14", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
[paquete]
|
|
el = "pollo loco"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd paquete
|
|
cd ~
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_change_to_a_path_containing_spaces() {
|
|
Playground::setup("cd_test_15", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContent(
|
|
"sample.toml",
|
|
r#"
|
|
["pa que te"]
|
|
el = "pollo loco"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
r#"
|
|
enter sample.toml
|
|
cd "pa que te"
|
|
pwd | echo $it
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert_eq!(PathBuf::from(actual), PathBuf::from("/").join("pa que te"));
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn valuesystem_path_not_found() {
|
|
let actual = nu_error!(
|
|
cwd: "tests/fixtures/formats",
|
|
r#"
|
|
enter cargo_sample.toml
|
|
cd im_a_path_that_does_not_exist
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert!(actual.contains("Can not change to path inside"));
|
|
assert!(actual.contains("No such path exists"));
|
|
}
|