Browse Source

Ensure custom variables override any basic variables

tags/0.1.0^2
Bèr Kessels 2 months ago
parent
commit
f558a06ab8
2 changed files with 19 additions and 2 deletions
  1. 1
    2
      src/main.rs
  2. 18
    0
      tests/cli.rs

+ 1
- 2
src/main.rs View File

@@ -60,12 +60,11 @@ fn main() {
}

fn context(user_pairs: Vec<Vec<String>>) -> Context {
let mut context = Context::new();
let mut context = basics::context();

for pair in user_pairs {
context.insert(pair[0].as_str(), pair[1].as_str());
}

context.extend(basics::context());
context
}

+ 18
- 0
tests/cli.rs View File

@@ -65,3 +65,21 @@ fn with_argument_variables() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[test]
fn with_argument_variable_that_overrides_basic() -> Result<(), Box<dyn std::error::Error>> {
let mut file = NamedTempFile::new()?;
// We need to escape the {{, with two more {{.
writeln!(file, "Invoice date {{{{ date }}}}")?;

let mut cmd = Command::cargo_bin("blek")?;
cmd.arg(file.path());
cmd.arg("--var");
cmd.arg("date=2010");

cmd.assert()
.success()
.stdout(predicate::str::contains("Invoice date 2010"));

Ok(())
}

Loading…
Cancel
Save