-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from lilopkins/develop
0.21.0-rc.6
- Loading branch information
Showing
10 changed files
with
222 additions
and
42 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
[package] | ||
name = "testangel-rand" | ||
authors = ["Lily Hopkins <[email protected]>"] | ||
description = "A randomisation engine plugin for testangel." | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
lazy_static = "1.4.0" | ||
rand = "0.8.5" | ||
rand_regex = "0.17.0" | ||
testangel-engine = { path = "../testangel-engine" } | ||
thiserror = "1.0" |
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,41 @@ | ||
use std::sync::Mutex; | ||
|
||
use lazy_static::lazy_static; | ||
use rand::Rng; | ||
use testangel_engine::*; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum EngineError { | ||
#[error("Couldn't build expression.")] | ||
CouldntBuildExpression(#[from] rand_regex::Error), | ||
} | ||
|
||
lazy_static! { | ||
static ref ENGINE: Mutex<Engine<'static, ()>> = Mutex::new( | ||
Engine::new("Random", "Random", env!("CARGO_PKG_VERSION")).with_instruction( | ||
Instruction::new( | ||
"rand-string", | ||
"StringByRegex", | ||
"Random String by Regex", | ||
"Generate a random string given the regular expression-like format you provide.", | ||
) | ||
.with_parameter("regex", "Regular Expression", ParameterKind::String) | ||
.with_output("result", "Result", ParameterKind::String), | ||
|_state, params, output, _evidence| { | ||
let regex = params["regex"].value_string(); | ||
|
||
let expr = rand_regex::Regex::compile(®ex, 32) | ||
.map_err(EngineError::CouldntBuildExpression)?; | ||
output.insert( | ||
"result".to_string(), | ||
ParameterValue::String(rand::thread_rng().sample(&expr)), | ||
); | ||
|
||
Ok(()) | ||
} | ||
) | ||
); | ||
} | ||
|
||
expose_engine!(ENGINE); |
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,16 @@ | ||
[package] | ||
name = "testangel-time" | ||
authors = ["Lily Hopkins <[email protected]>"] | ||
description = "A time engine plugin for testangel." | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
lazy_static = "1.4.0" | ||
testangel-engine = { path = "../testangel-engine" } | ||
thiserror = "1.0" |
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,35 @@ | ||
use std::{sync::Mutex, thread::sleep, time::Duration}; | ||
|
||
use lazy_static::lazy_static; | ||
use testangel_engine::*; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum EngineError { | ||
#[error("Duration cannot be negative.")] | ||
CantWaitNegative, | ||
} | ||
|
||
lazy_static! { | ||
static ref ENGINE: Mutex<Engine<'static, ()>> = Mutex::new( | ||
Engine::new("Time", "Time", env!("CARGO_PKG_VERSION")).with_instruction( | ||
Instruction::new( | ||
"time-wait", | ||
"Wait", | ||
"Wait", | ||
"Wait for a specified number of milliseconds.", | ||
) | ||
.with_parameter("duration", "Duration (ms)", ParameterKind::Decimal), | ||
|_state, params, _output, _evidence| { | ||
let duration = params["duration"].value_i32(); | ||
if duration < 0 { | ||
return Err(Box::new(EngineError::CantWaitNegative)); | ||
} | ||
sleep(Duration::from_millis(duration as u64)); | ||
Ok(()) | ||
} | ||
) | ||
); | ||
} | ||
|
||
expose_engine!(ENGINE); |
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
Oops, something went wrong.