Merge pull request #183 from asvln/master

Implement string conversion commands
This commit is contained in:
Sagie Gur-Ari 2021-07-23 14:12:24 +03:00 committed by GitHub
commit e7eb2349ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 666 additions and 6 deletions

18
Cargo.lock generated
View file

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "1.0.2"
@ -162,6 +164,7 @@ dependencies = [
"fsio",
"ftp",
"glob",
"heck",
"home",
"ignore",
"java-properties",
@ -346,6 +349,15 @@ dependencies = [
"regex 1.5.4",
]
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -928,6 +940,12 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]]
name = "unicode-xid"
version = "0.2.2"

View file

@ -145,15 +145,18 @@
* [std::string::Base64Decode (base64_decode)](#std__string__Base64Decode)
* [std::string::Base64Encode (base64_encode)](#std__string__Base64Encode)
* [std::string::BytesToString (bytes_to_string)](#std__string__BytesToString)
* [std::string::CamelCase (camelcase)](#std__string__CamelCase)
* [std::string::Concat (concat)](#std__string__Concat)
* [std::string::Contains (contains)](#std__string__Contains)
* [std::string::EndsWith (ends_with)](#std__string__EndsWith)
* [std::string::Equals (equals, eq)](#std__string__Equals)
* [std::string::IndexOf (indexof)](#std__string__IndexOf)
* [std::string::IsEmpty (is_empty)](#std__string__IsEmpty)
* [std::string::KebabCase (kebabcase)](#std__string__KebabCase)
* [std::string::LastIndexOf (last_indexof)](#std__string__LastIndexOf)
* [std::string::Length (length, strlen)](#std__string__Length)
* [std::string::Replace (replace)](#std__string__Replace)
* [std::string::SnakeCase (snakecase)](#std__string__SnakeCase)
* [std::string::Split (split)](#std__string__Split)
* [std::string::StartsWith (starts_with)](#std__string__StartsWith)
* [std::string::StringToBytes (string_to_bytes)](#std__string__StringToBytes)
@ -5455,6 +5458,36 @@ assert_eq ${text} "hello world"
#### Aliases:
bytes_to_string
<a name="std__string__CamelCase"></a>
## std::string::CamelCase
```sh
var = camelcase text
```
Converts the provided string into camel case.
All non-alphanumeric characters are ignored.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = camelcase "hello, world!"
assert_eq ${string} "HelloWorld"
```
#### Aliases:
camelcase
<a name="std__string__Concat"></a>
## std::string::Concat
@ -5686,6 +5719,35 @@ index = last_indexof " some text " some
#### Aliases:
last_indexof
<a name="std__string__KebabCase"></a>
## std::string::KebabCase
```sh
var = kebabcase text
```
Converts the provided string into kebab case.
All non-alphanumeric characters are ignored.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = kebabcase "hello, world!"
assert_eq ${string} "hello-world"
```
#### Aliases:
kebabcase
<a name="std__string__Length"></a>
## std::string::Length
```sh
@ -5712,6 +5774,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
@ -5743,6 +5833,36 @@ assert_eq ${updated} "my large stuff value with lots of stuff"
#### Aliases:
replace
<a name="std__string__SnakeCase"></a>
## std::string::SnakeCase
```sh
var = snakecase text
```
Converts the provided string into snake case.
All non-alphanumeric characters are ignored.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = snakecase "Hello, World!"
assert_eq ${string} "hello_world"
```
#### Aliases:
snakecase
<a name="std__string__Split"></a>
## std::string::Split
```sh
@ -5983,6 +6103,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

@ -59,7 +59,6 @@
order_dependent_trait_objects,
overflowing_literals,
overlapping_range_endpoints,
panic_fmt,
path_statements,
patterns_in_fns_without_body,
pointer_structural_match,
@ -69,7 +68,6 @@
proc_macro_derive_resolution_fallback,
pub_use_of_private_extern_crate,
redundant_semicolons,
safe_packed_borrows,
soft_unstable,
stable_features,
temporary_cstring_as_ptr,

View file

@ -59,7 +59,6 @@
order_dependent_trait_objects,
overflowing_literals,
overlapping_range_endpoints,
panic_fmt,
path_statements,
patterns_in_fns_without_body,
pointer_structural_match,
@ -69,7 +68,6 @@
proc_macro_derive_resolution_fallback,
pub_use_of_private_extern_crate,
redundant_semicolons,
safe_packed_borrows,
soft_unstable,
stable_features,
temporary_cstring_as_ptr,

View file

@ -31,6 +31,7 @@ fs_extra = "^1"
fsio = { version = "^0.2", features = ["temp-path"] }
ftp = "^3"
glob = "^0.3"
heck = "^0.3"
home = "^0.5"
ignore = "^0.4"
java-properties = "^1"

View file

@ -59,7 +59,6 @@
order_dependent_trait_objects,
overflowing_literals,
overlapping_range_endpoints,
panic_fmt,
path_statements,
patterns_in_fns_without_body,
pointer_structural_match,
@ -69,7 +68,6 @@
proc_macro_derive_resolution_fallback,
pub_use_of_private_extern_crate,
redundant_semicolons,
safe_packed_borrows,
soft_unstable,
stable_features,
temporary_cstring_as_ptr,

View file

@ -0,0 +1,22 @@
```sh
var = camelcase text
```
Converts the provided string into camel case.
All non-alphanumeric characters are ignored.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = camelcase "hello, world!"
assert_eq ${string} "HelloWorld"
```

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, "CamelCase")
}
fn aliases(&self) -> Vec<String> {
vec!["camelcase".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 value = heck::CamelCase::to_camel_case(arguments[0].as_str());
CommandResult::Continue(Some(value))
}
}
}
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 = camelcase", "out");
}
#[test]
fn run_single_argument() {
test::run_script_and_validate(
vec![create("")],
r#"out = camelcase "hello, world!""#,
CommandValidation::Match("out".to_string(), "HelloWorld".to_string()),
);
}

View file

@ -0,0 +1,22 @@
```sh
var = kebobcase text
```
Converts the provided string into kebob case.
All non-alphanumeric characters are ignored.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = kebobcase "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, "KebabCase")
}
fn aliases(&self) -> Vec<String> {
vec!["kebabcase".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 value = heck::KebabCase::to_kebab_case(arguments[0].as_str());
CommandResult::Continue(Some(value))
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

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

View file

@ -0,0 +1,21 @@
```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 value = arguments[0].to_lowercase();
CommandResult::Continue(Some(value))
}
}
}
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

@ -2,15 +2,19 @@ mod base64;
mod base64_decode;
mod base64_encode;
pub(crate) mod bytes_to_string;
mod camelcase;
mod concat;
mod contains;
mod ends_with;
pub(crate) mod equals;
mod indexof;
mod is_empty;
mod kebabcase;
mod last_indexof;
mod length;
mod lowercase;
mod replace;
mod snakecase;
mod split;
mod starts_with;
pub(crate) mod string_to_bytes;
@ -18,6 +22,7 @@ mod substring;
mod trim;
mod trim_end;
mod trim_start;
mod uppercase;
use crate::utils::pckg;
use duckscript::types::command::Commands;
@ -32,15 +37,19 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
commands.set(base64_decode::create(&package))?;
commands.set(base64_encode::create(&package))?;
commands.set(bytes_to_string::create(&package))?;
commands.set(camelcase::create(&package))?;
commands.set(concat::create(&package)?)?;
commands.set(contains::create(&package))?;
commands.set(ends_with::create(&package))?;
commands.set(equals::create(&package))?;
commands.set(indexof::create(&package))?;
commands.set(is_empty::create(&package))?;
commands.set(kebabcase::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(snakecase::create(&package))?;
commands.set(split::create(&package))?;
commands.set(starts_with::create(&package))?;
commands.set(string_to_bytes::create(&package))?;
@ -48,6 +57,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,22 @@
```sh
var = snakecase text
```
Converts the provided string into snake case.
All non-alphanumeric characters are ignored.
#### Parameters
The string to convert.
#### Return Value
The converted string.
#### Examples
```sh
string = snakecase "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, "SnakeCase")
}
fn aliases(&self) -> Vec<String> {
vec!["snakecase".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 value = heck::SnakeCase::to_snake_case(arguments[0].as_str());
CommandResult::Continue(Some(value))
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View 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_error(vec![create("")], "out = snakecase", "out");
}
#[test]
fn run_single_argument() {
test::run_script_and_validate(
vec![create("")],
r#"out = snakecase "Hello, World!""#,
CommandValidation::Match("out".to_string(), "hello_world".to_string()),
);
}

View file

@ -0,0 +1,21 @@
```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 value = arguments[0].to_uppercase();
CommandResult::Continue(Some(value))
}
}
}
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,12 @@
fn test_without_symbols
output = camelcase "Hello world 22"
assert_eq ${output} "HelloWorld22"
end
fn test_with_symbols
output = camelcase "Hello!@#$% world^&*()[]{}22"
assert_eq ${output} "HelloWorld22"
end

View file

@ -0,0 +1,12 @@
fn test_without_symbols
output = kebabcase "Hello World 22"
assert_eq ${output} "hello-world-22"
end
fn test_with_symbols
output = kebabcase "hello!@#$% world^&*()[]{}22"
assert_eq ${output} "hello-world-22"
end

View file

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

View file

@ -0,0 +1,12 @@
fn test_without_symbols
output = snakecase "Hello world 22"
assert_eq ${output} "hello_world_22"
end
fn test_with_symbols
output = snakecase "Hello!@#$% world^&*()[]{}22"
assert_eq ${output} "hello_world_22"
end

View file

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