Files
.azure
.cargo
.circleci
.github
.theia
crates
nu-ansi-term
nu-cli
nu-command
nu-completion
nu-data
nu-engine
src
tests
evaluate
mod.rs
operator.rs
subexpression.rs
variables.rs
main.rs
Cargo.toml
README.md
nu-errors
nu-json
nu-parser
nu-path
nu-plugin
nu-pretty-hex
nu-protocol
nu-serde
nu-source
nu-stream
nu-table
nu-test-support
nu-value-ext
nu_plugin_binaryview
nu_plugin_chart
nu_plugin_fetch
nu_plugin_from_bson
nu_plugin_from_mp4
nu_plugin_from_sqlite
nu_plugin_inc
nu_plugin_match
nu_plugin_post
nu_plugin_ps
nu_plugin_query_json
nu_plugin_s3
nu_plugin_selector
nu_plugin_start
nu_plugin_sys
nu_plugin_textview
nu_plugin_to_bson
nu_plugin_to_sqlite
nu_plugin_tree
nu_plugin_xpath
README.md
debian
docker
docs
images
pkg_mgrs
samples
src
tests
wix
.dockerignore
.editorconfig
.gitignore
.gitpod.Dockerfile
.gitpod.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
LICENSE
Makefile.toml
README.build.txt
README.md
extra_features_cargo_install.sh
rustfmt.toml
nushell/crates/nu-engine/tests/evaluate/variables.rs
JT d9d956e54f Fix issue in external subexpression paths ()
* Fix issue in external subexpression paths

* new clippy dropped

* clippy
2021-06-18 07:59:58 +12:00

89 lines
2.4 KiB
Rust

use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::fs::{AbsolutePath, DisplayPath};
use nu_test_support::playground::{says, Playground};
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
#[test]
fn config_path_variable_present() {
Playground::setup("nu_variable_test_1", |_, nu| {
assert_that!(
nu.pipeline("echo $nu.config-path"),
says().stdout(nu.get_config())
);
})
}
#[test]
fn custom_config_path_variable_present() {
Playground::setup("nu_variable_test_2", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
"skip_welcome_message = true",
)]);
assert_that!(
nu.pipeline("echo $nu.config-path"),
says().stdout(&file.display_path())
);
})
}
#[test]
fn scope_variable_with_alias_present() {
Playground::setup("scope_variable_alias_test_1", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
"skip_welcome_message = true",
)]);
assert_that!(
nu.pipeline("alias t = time; echo $scope.aliases | get t"),
says().stdout("time")
);
})
}
#[test]
fn scope_variable_with_correct_number_of_aliases_present() {
Playground::setup("scope_variable_alias_test_2", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
"skip_welcome_message = true",
)]);
assert_that!(
nu.pipeline("alias v = version; alias t = time; echo $scope.aliases | length -c"),
says().stdout("2")
);
})
}
#[test]
fn scope_variable_with_command_present() {
Playground::setup("scope_commands_test_1", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
"skip_welcome_message = true",
)]);
assert_that!(
nu.pipeline("def meaning-of-life [--number: int] { echo $number }; echo $scope.commands | get meaning-of-life"),
says().stdout("--number")
);
})
}