mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
parent
1ff3a646c8
commit
7c5b6e5dfa
|
@ -2,6 +2,8 @@
|
|||
|
||||
### v0.1.5
|
||||
|
||||
* New trim_start command #29
|
||||
* New trim_end command #30
|
||||
* New trim command
|
||||
* New is_empty command
|
||||
* New is_defined command
|
||||
|
|
56
docs/sdk.md
56
docs/sdk.md
|
@ -41,6 +41,8 @@
|
|||
* [sdk::string::IsEmpty (is_empty)](#sdk__string__IsEmpty)
|
||||
* [sdk::string::StartsWith (starts_with)](#sdk__string__StartsWith)
|
||||
* [sdk::string::Trim (trim)](#sdk__string__Trim)
|
||||
* [sdk::string::TrimEnd (trim_end)](#sdk__string__TrimEnd)
|
||||
* [sdk::string::TrimStart (trim_start)](#sdk__string__TrimStart)
|
||||
* [sdk::test::Assert (assert)](#sdk__test__Assert)
|
||||
* [sdk::test::AssertEquals (assert_eq)](#sdk__test__AssertEquals)
|
||||
* [sdk::test::AssertFail (assert_fail)](#sdk__test__AssertFail)
|
||||
|
@ -1509,6 +1511,60 @@ trimmed = trim " some text "
|
|||
#### Aliases:
|
||||
trim
|
||||
|
||||
<a name="sdk__string__TrimEnd"></a>
|
||||
## sdk::string::TrimEnd
|
||||
```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 "
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
trim_end
|
||||
|
||||
<a name="sdk__string__TrimStart"></a>
|
||||
## sdk::string::TrimStart
|
||||
```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 "
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
trim_start
|
||||
|
||||
<a name="sdk__test__Assert"></a>
|
||||
## sdk::test::Assert
|
||||
```sh
|
||||
|
|
|
@ -4,6 +4,8 @@ mod equals;
|
|||
mod is_empty;
|
||||
mod starts_with;
|
||||
mod trim;
|
||||
mod trim_end;
|
||||
mod trim_start;
|
||||
|
||||
use crate::utils::pckg;
|
||||
use duckscript::types::command::Commands;
|
||||
|
@ -20,6 +22,8 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
|
|||
commands.set(is_empty::create(&package))?;
|
||||
commands.set(starts_with::create(&package))?;
|
||||
commands.set(trim::create(&package))?;
|
||||
commands.set(trim_start::create(&package))?;
|
||||
commands.set(trim_end::create(&package))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
20
duckscript_sdk/src/sdk/std/string/trim_end/help.md
Normal file
20
duckscript_sdk/src/sdk/std/string/trim_end/help.md
Normal file
|
@ -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 "
|
||||
```
|
39
duckscript_sdk/src/sdk/std/string/trim_end/mod.rs
Executable file
39
duckscript_sdk/src/sdk/std/string/trim_end/mod.rs
Executable file
|
@ -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(),
|
||||
})
|
||||
}
|
22
duckscript_sdk/src/sdk/std/string/trim_end/mod_test.rs
Normal file
22
duckscript_sdk/src/sdk/std/string/trim_end/mod_test.rs
Normal file
|
@ -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()),
|
||||
);
|
||||
}
|
20
duckscript_sdk/src/sdk/std/string/trim_start/help.md
Normal file
20
duckscript_sdk/src/sdk/std/string/trim_start/help.md
Normal file
|
@ -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 "
|
||||
```
|
39
duckscript_sdk/src/sdk/std/string/trim_start/mod.rs
Executable file
39
duckscript_sdk/src/sdk/std/string/trim_start/mod.rs
Executable file
|
@ -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(),
|
||||
})
|
||||
}
|
26
duckscript_sdk/src/sdk/std/string/trim_start/mod_test.rs
Normal file
26
duckscript_sdk/src/sdk/std/string/trim_start/mod_test.rs
Normal file
|
@ -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()),
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue