-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1ff3a64
commit 7c5b6e5
Showing
9 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
```sh | ||
var = trim_end value | ||
``` | ||
|
||
Returns the provided value with trailing whitespace removed. | ||
|
||
#### Parameters | ||
|
||
The value to trim. | ||
|
||
#### Return Value | ||
|
||
The trimmed value. If no input provided, this command will return none. | ||
|
||
#### Examples | ||
|
||
```sh | ||
# trimmed will now hold " some text" | ||
trimmed = trim_end " some text " | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::utils::pckg; | ||
use duckscript::types::command::{Command, CommandResult}; | ||
|
||
#[cfg(test)] | ||
#[path = "./mod_test.rs"] | ||
mod mod_test; | ||
|
||
struct CommandImpl { | ||
package: String, | ||
} | ||
|
||
impl Command for CommandImpl { | ||
fn name(&self) -> String { | ||
pckg::concat(&self.package, "TrimEnd") | ||
} | ||
|
||
fn aliases(&self) -> Vec<String> { | ||
vec!["trim_end".to_string()] | ||
} | ||
|
||
fn help(&self) -> String { | ||
include_str!("help.md").to_string() | ||
} | ||
|
||
fn run(&self, arguments: Vec<String>) -> CommandResult { | ||
if arguments.is_empty() { | ||
CommandResult::Continue(None) | ||
} else { | ||
let result = arguments[0].trim_end(); | ||
CommandResult::Continue(Some(result.to_string())) | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn create(package: &str) -> Box<dyn Command> { | ||
Box::new(CommandImpl { | ||
package: package.to_string(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use super::*; | ||
use crate::test; | ||
use crate::test::CommandValidation; | ||
|
||
#[test] | ||
fn common_functions() { | ||
test::test_common_command_functions(create("")); | ||
} | ||
|
||
#[test] | ||
fn run_no_args() { | ||
test::run_script_and_validate(vec![create("")], "out = trim_end", CommandValidation::None); | ||
} | ||
|
||
#[test] | ||
fn run_with_spaces() { | ||
test::run_script_and_validate( | ||
vec![create("")], | ||
r#"out = trim_end " some text " "#, | ||
CommandValidation::Match("out".to_string(), " some text".to_string()), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
```sh | ||
var = trim_start value | ||
``` | ||
|
||
Returns the provided value with leading whitespace removed. | ||
|
||
#### Parameters | ||
|
||
The value to trim. | ||
|
||
#### Return Value | ||
|
||
The trimmed value. If no input provided, this command will return none. | ||
|
||
#### Examples | ||
|
||
```sh | ||
# trimmed will now hold "some text " | ||
trimmed = trim_start " some text " | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::utils::pckg; | ||
use duckscript::types::command::{Command, CommandResult}; | ||
|
||
#[cfg(test)] | ||
#[path = "./mod_test.rs"] | ||
mod mod_test; | ||
|
||
struct CommandImpl { | ||
package: String, | ||
} | ||
|
||
impl Command for CommandImpl { | ||
fn name(&self) -> String { | ||
pckg::concat(&self.package, "TrimStart") | ||
} | ||
|
||
fn aliases(&self) -> Vec<String> { | ||
vec!["trim_start".to_string()] | ||
} | ||
|
||
fn help(&self) -> String { | ||
include_str!("help.md").to_string() | ||
} | ||
|
||
fn run(&self, arguments: Vec<String>) -> CommandResult { | ||
if arguments.is_empty() { | ||
CommandResult::Continue(None) | ||
} else { | ||
let result = arguments[0].trim_start(); | ||
CommandResult::Continue(Some(result.to_string())) | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn create(package: &str) -> Box<dyn Command> { | ||
Box::new(CommandImpl { | ||
package: package.to_string(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use super::*; | ||
use crate::test; | ||
use crate::test::CommandValidation; | ||
|
||
#[test] | ||
fn common_functions() { | ||
test::test_common_command_functions(create("")); | ||
} | ||
|
||
#[test] | ||
fn run_no_args() { | ||
test::run_script_and_validate( | ||
vec![create("")], | ||
"out = trim_start", | ||
CommandValidation::None, | ||
); | ||
} | ||
|
||
#[test] | ||
fn run_with_spaces() { | ||
test::run_script_and_validate( | ||
vec![create("")], | ||
r#"out = trim_start " some text " "#, | ||
CommandValidation::Match("out".to_string(), "some text ".to_string()), | ||
); | ||
} |