Add predefined constants (#2054)
This commit is contained in:
45
tests/constants.rs
Normal file
45
tests/constants.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn constants_are_defined() {
|
||||
assert_eval_eq("HEX", "0123456789abcdef");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constants_are_defined_in_recipe_bodies() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
@foo:
|
||||
echo {{HEX}}
|
||||
",
|
||||
)
|
||||
.stdout("0123456789abcdef\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constants_are_defined_in_recipe_parameters() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
@foo hex=HEX:
|
||||
echo {{hex}}
|
||||
",
|
||||
)
|
||||
.stdout("0123456789abcdef\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constants_can_be_redefined() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
HEX := 'foo'
|
||||
",
|
||||
)
|
||||
.args(["--evaluate", "HEX"])
|
||||
.stdout("foo")
|
||||
.run();
|
||||
}
|
||||
@@ -436,15 +436,6 @@ fn semver_matches() {
|
||||
.run();
|
||||
}
|
||||
|
||||
fn assert_eval_eq(expression: &str, result: &str) {
|
||||
Test::new()
|
||||
.justfile(format!("x := {expression}"))
|
||||
.args(["--evaluate", "x"])
|
||||
.stdout(result)
|
||||
.unindent_stdout(false)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trim_end_matches() {
|
||||
assert_eval_eq("trim_end_matches('foo', 'o')", "f");
|
||||
|
||||
@@ -3,7 +3,7 @@ pub(crate) use {
|
||||
assert_stdout::assert_stdout,
|
||||
assert_success::assert_success,
|
||||
tempdir::tempdir,
|
||||
test::{Output, Test},
|
||||
test::{assert_eval_eq, Output, Test},
|
||||
},
|
||||
cradle::input::Input,
|
||||
executable_path::executable_path,
|
||||
@@ -46,6 +46,7 @@ mod command;
|
||||
mod completions;
|
||||
mod conditional;
|
||||
mod confirm;
|
||||
mod constants;
|
||||
mod delimiters;
|
||||
mod directories;
|
||||
mod dotenv;
|
||||
|
||||
@@ -312,3 +312,12 @@ fn test_round_trip(tmpdir: &Path) {
|
||||
|
||||
assert_eq!(reparsed, dumped, "reparse mismatch");
|
||||
}
|
||||
|
||||
pub fn assert_eval_eq(expression: &str, result: &str) {
|
||||
Test::new()
|
||||
.justfile(format!("x := {expression}"))
|
||||
.args(["--evaluate", "x"])
|
||||
.stdout(result)
|
||||
.unindent_stdout(false)
|
||||
.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user