Add choose function for generating random strings (#2049)

This commit is contained in:
laniakea64
2024-05-18 19:29:14 -04:00
committed by GitHub
parent 6907847a77
commit 7fa6ed8149
5 changed files with 135 additions and 0 deletions

View File

@@ -661,6 +661,69 @@ fn uuid() {
.run();
}
#[test]
fn choose() {
Test::new()
.justfile(r#"x := choose('10', 'xXyYzZ')"#)
.args(["--evaluate", "x"])
.stdout_regex("^[X-Zx-z]{10}$")
.run();
}
#[test]
fn choose_bad_alphabet_empty() {
Test::new()
.justfile("x := choose('10', '')")
.args(["--evaluate"])
.status(1)
.stderr(
"
error: Call to function `choose` failed: empty alphabet
——▶ justfile:1:6
1 │ x := choose('10', '')
│ ^^^^^^
",
)
.run();
}
#[test]
fn choose_bad_alphabet_repeated() {
Test::new()
.justfile("x := choose('10', 'aa')")
.args(["--evaluate"])
.status(1)
.stderr(
"
error: Call to function `choose` failed: alphabet contains repeated character `a`
——▶ justfile:1:6
1 │ x := choose('10', 'aa')
│ ^^^^^^
",
)
.run();
}
#[test]
fn choose_bad_length() {
Test::new()
.justfile("x := choose('foo', HEX)")
.args(["--evaluate"])
.status(1)
.stderr(
"
error: Call to function `choose` failed: failed to parse `foo` as positive integer: invalid digit found in string
——▶ justfile:1:6
1 │ x := choose('foo', HEX)
│ ^^^^^^
",
)
.run();
}
#[test]
fn sha256() {
Test::new()