Implement lowercase and uppercase

This commit is contained in:
Philip Koperski 2021-07-14 12:00:25 -04:00
parent d4cb10d3eb
commit b5a022a454
10 changed files with 246 additions and 0 deletions

View file

@ -5744,6 +5744,34 @@ len = length "Hello World"
#### Aliases:
length, strlen
<a name="std__string__Length"></a>
## std::string::Length
```sh
var = lowercase text
```
Converts the provided string into lowercase.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = lowercase "Hello World"
assert_eq ${string} "hello world"
```
#### Aliases:
lowercase
<a name="std__string__Replace"></a>
## std::string::Replace
```sh
@ -6045,6 +6073,34 @@ trimmed = trim_start " some text "
#### Aliases:
trim_start
<a name="std__string__Uppercase"></a>
## std::string::Uppercase
```sh
var = uppercase text
```
Converts the provided string into uppercase.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = uppercase "Hello World"
assert_eq ${string} "HELLO WORLD"
```
#### Aliases:
uppercase
<a name="std__test__Assert"></a>
## std::test::Assert
```sh

View file

@ -0,0 +1,20 @@
```sh
var = lowercase text
```
Converts the provided string into lowercase.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = lowercase "Hello World"
assert_eq ${string} "hello world"
```

View file

@ -0,0 +1,44 @@
use crate::utils::pckg;
use duckscript::types::command::{Command, CommandResult};
#[cfg(test)]
#[path = "./mod_test.rs"]
mod mod_test;
#[derive(Clone)]
pub(crate) struct CommandImpl {
package: String,
}
impl Command for CommandImpl {
fn name(&self) -> String {
pckg::concat(&self.package, "Lowercase")
}
fn aliases(&self) -> Vec<String> {
vec!["lowercase".to_string()]
}
fn help(&self) -> String {
include_str!("help.md").to_string()
}
fn clone_and_box(&self) -> Box<dyn Command> {
Box::new((*self).clone())
}
fn run(&self, arguments: Vec<String>) -> CommandResult {
if arguments.is_empty() {
CommandResult::Error("No arguments provided.".to_string())
} else {
let lowercase = arguments[0].to_lowercase();
CommandResult::Continue(Some(lowercase))
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View file

@ -0,0 +1,23 @@
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_error(vec![create("")], "out = lowercase", "out");
}
#[test]
fn run_single_argument() {
test::run_script_and_validate(
vec![create("")],
r#"out = lowercase "Hello World""#,
CommandValidation::Match("out".to_string(), "hello world".to_string()),
);
}

View file

@ -11,6 +11,7 @@ mod indexof;
mod is_empty;
mod last_indexof;
mod length;
mod lowercase;
mod replace;
mod snake_case;
mod split;
@ -20,6 +21,7 @@ mod substring;
mod trim;
mod trim_end;
mod trim_start;
mod uppercase;
use crate::utils::pckg;
use duckscript::types::command::Commands;
@ -43,6 +45,7 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
commands.set(is_empty::create(&package))?;
commands.set(last_indexof::create(&package))?;
commands.set(length::create(&package))?;
commands.set(lowercase::create(&package))?;
commands.set(replace::create(&package))?;
commands.set(snake_case::create(&package))?;
commands.set(split::create(&package))?;
@ -52,6 +55,7 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
commands.set(trim::create(&package))?;
commands.set(trim_start::create(&package))?;
commands.set(trim_end::create(&package))?;
commands.set(uppercase::create(&package))?;
Ok(())
}

View file

@ -0,0 +1,20 @@
```sh
var = uppercase text
```
Converts the provided string into uppercase.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = uppercase "Hello World"
assert_eq ${string} "HELLO WORLD"
```

View file

@ -0,0 +1,44 @@
use crate::utils::pckg;
use duckscript::types::command::{Command, CommandResult};
#[cfg(test)]
#[path = "./mod_test.rs"]
mod mod_test;
#[derive(Clone)]
pub(crate) struct CommandImpl {
package: String,
}
impl Command for CommandImpl {
fn name(&self) -> String {
pckg::concat(&self.package, "Uppercase")
}
fn aliases(&self) -> Vec<String> {
vec!["uppercase".to_string()]
}
fn help(&self) -> String {
include_str!("help.md").to_string()
}
fn clone_and_box(&self) -> Box<dyn Command> {
Box::new((*self).clone())
}
fn run(&self, arguments: Vec<String>) -> CommandResult {
if arguments.is_empty() {
CommandResult::Error("No arguments provided.".to_string())
} else {
let uppercase = arguments[0].to_uppercase();
CommandResult::Continue(Some(uppercase))
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View file

@ -0,0 +1,23 @@
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_error(vec![create("")], "out = uppercase", "out");
}
#[test]
fn run_single_argument() {
test::run_script_and_validate(
vec![create("")],
r#"out = uppercase "hello world""#,
CommandValidation::Match("out".to_string(), "HELLO WORLD".to_string()),
);
}

View file

@ -0,0 +1,6 @@
fn test_conversion
output = lowercase "Hello World"
assert_eq ${output} "hello world"
end

View file

@ -0,0 +1,6 @@
fn test_conversion
output = uppercase "Hello World"
assert_eq ${output} "HELLO WORLD"
end