forked from extern/nushell
Avoid taking unnecessary ownership of intermediates (#12740)
# Description Judiciously try to avoid allocations/clone by changing the signature of functions - **Don't pass str by value unnecessarily if only read** - **Don't require a vec in `Sandbox::with_files`** - **Remove unnecessary string clone** - **Fixup unnecessary borrow** - **Use `&str` in shape color instead** - **Vec -> Slice** - **Elide string clone** - **Elide `Path` clone** - **Take &str to elide clone in tests** # User-Facing Changes None # Tests + Formatting This touches many tests purely in changing from owned to borrowed/static data
This commit is contained in:
committed by
GitHub
parent
e6f473695c
commit
406df7f208
@ -5,7 +5,7 @@ use nu_test_support::playground::Playground;
|
||||
#[test]
|
||||
fn checks_if_existing_file_exists() {
|
||||
Playground::setup("path_exists_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
|
@ -7,9 +7,7 @@ use std::path::PathBuf;
|
||||
#[test]
|
||||
fn expands_path_with_dot() {
|
||||
Playground::setup("path_expand_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
@ -28,9 +26,7 @@ fn expands_path_with_dot() {
|
||||
#[test]
|
||||
fn expands_path_without_follow_symlink() {
|
||||
Playground::setup("path_expand_3", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
@ -49,9 +45,7 @@ fn expands_path_without_follow_symlink() {
|
||||
#[test]
|
||||
fn expands_path_with_double_dot() {
|
||||
Playground::setup("path_expand_2", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
@ -69,9 +63,7 @@ fn expands_path_with_double_dot() {
|
||||
#[test]
|
||||
fn const_path_expand() {
|
||||
Playground::setup("const_path_expand", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
@ -121,9 +113,7 @@ mod windows {
|
||||
#[test]
|
||||
fn expands_path_without_follow_symlink() {
|
||||
Playground::setup("path_expand_3", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let cwd = dirs.test();
|
||||
std::os::windows::fs::symlink_file(
|
||||
|
@ -18,9 +18,7 @@ fn returns_type_of_missing_file() {
|
||||
#[test]
|
||||
fn returns_type_of_existing_file() {
|
||||
Playground::setup("path_expand_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
@ -37,9 +35,7 @@ fn returns_type_of_existing_file() {
|
||||
#[test]
|
||||
fn returns_type_of_existing_directory() {
|
||||
Playground::setup("path_expand_1", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
@ -65,9 +61,7 @@ fn returns_type_of_existing_directory() {
|
||||
#[test]
|
||||
fn returns_type_of_existing_file_const() {
|
||||
Playground::setup("path_type_const", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
sandbox.within("menu").with_files(&[EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
|
Reference in New Issue
Block a user