Remove build-string command (#7144)

This commit is contained in:
Reilly Wood 2022-11-16 09:37:52 -08:00 committed by GitHub
parent 02ad491dea
commit 7098e56ccf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 126 deletions

View file

@ -184,7 +184,6 @@ pub fn create_default_context() -> EngineState {
// Strings
bind_command! {
BuildString,
Char,
Decode,
Encode,

View file

@ -9,8 +9,8 @@ pub fn test_examples(cmd: impl Command + 'static) {
#[cfg(test)]
mod test_examples {
use super::super::{
Ansi, BuildString, Date, Echo, From, If, Into, LetEnv, Math, Path, Random, Split,
SplitColumn, SplitRow, Str, StrJoin, StrLength, StrReplace, Url, Wrap,
Ansi, Date, Echo, From, If, Into, LetEnv, Math, Path, Random, Split, SplitColumn, SplitRow,
Str, StrJoin, StrLength, StrReplace, Url, Wrap,
};
use crate::To;
use itertools::Itertools;
@ -64,7 +64,6 @@ mod test_examples {
working_set.add_decl(Box::new(StrJoin));
working_set.add_decl(Box::new(StrLength));
working_set.add_decl(Box::new(StrReplace));
working_set.add_decl(Box::new(BuildString));
working_set.add_decl(Box::new(From));
working_set.add_decl(Box::new(If));
working_set.add_decl(Box::new(To));

View file

@ -1,86 +0,0 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Type, Value,
};
#[derive(Clone)]
pub struct BuildString;
impl Command for BuildString {
fn name(&self) -> &str {
"build-string"
}
fn usage(&self) -> &str {
"Create a string from the arguments."
}
fn search_terms(&self) -> Vec<&str> {
vec!["concatenate", "join"]
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("build-string")
.rest("rest", SyntaxShape::String, "list of string")
.input_output_types(vec![(Type::Nothing, Type::String)])
.category(Category::Strings)
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
example: "build-string a b c",
description: "Builds a string from letters a b c",
result: Some(Value::String {
val: "abc".to_string(),
span: Span::test_data(),
}),
},
Example {
example: r#"build-string $"(1 + 2)" = one ' ' plus ' ' two"#,
description: "Builds a string from subexpression separating words with spaces",
result: Some(Value::String {
val: "3=one plus two".to_string(),
span: Span::test_data(),
}),
},
]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let config = engine_state.get_config();
let output = call
.positional_iter()
.map(|expr| {
eval_expression(engine_state, stack, expr).map(|val| val.into_string(", ", config))
})
.collect::<Result<Vec<String>, ShellError>>()?;
Ok(Value::String {
val: output.join(""),
span: call.head,
}
.into_pipeline_data())
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(BuildString {})
}
}

View file

@ -1,4 +1,3 @@
mod build_string;
mod char_;
mod detect_columns;
mod encode_decode;
@ -8,7 +7,6 @@ mod size;
mod split;
mod str_;
pub use build_string::BuildString;
pub use char_::Char;
pub use detect_columns::*;
pub use encode_decode::*;

View file

@ -1,39 +1,5 @@
use crate::tests::{fail_test, run_test, TestResult};
#[test]
fn build_string1() -> TestResult {
run_test("build-string 'nu' 'shell'", "nushell")
}
#[test]
fn build_string2() -> TestResult {
run_test("'nu' | each { |it| build-string $it 'shell'}", "nushell")
}
#[test]
fn build_string3() -> TestResult {
run_test(
"build-string 'nu' 'shell' | each { |it| build-string $it ' rocks'}",
"nushell rocks",
)
}
#[test]
fn build_string4() -> TestResult {
run_test(
"['sam','rick','pete'] | each { |it| build-string $it ' is studying'} | get 2",
"pete is studying",
)
}
#[test]
fn build_string5() -> TestResult {
run_test(
"['sam','rick','pete'] | each { |x| build-string $x ' is studying'} | get 1",
"rick is studying",
)
}
#[test]
fn cjk_in_substrings() -> TestResult {
run_test(