#![allow(missing_docs)]
#![cfg(feature = "cli-compiler")]
use assert_cmd::Command;
const GOLDEN: &[(&str, &str, &str)] = &[
("pk(@0)", "segwitv0", "wsh(pk(@0))"),
("pk(@0)", "tap", "tr(@0)"),
];
#[test]
fn compiler_golden_table() {
for (expr, ctx, expected_prefix) in GOLDEN {
let out = Command::cargo_bin("md")
.unwrap()
.args(["compile", expr, "--context", ctx])
.output()
.unwrap();
let actual = String::from_utf8(out.stdout).unwrap();
let actual_first = actual.lines().next().unwrap();
assert!(
actual_first.starts_with(expected_prefix),
"compile({expr}, {ctx}) → {actual_first}, expected prefix {expected_prefix}"
);
}
}
#[test]
fn threshold_compiles_to_some_template() {
let out = Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"thresh(2,pk(@0),pk(@1),pk(@2))",
"--context",
"segwitv0",
])
.output()
.unwrap();
let s = String::from_utf8(out.stdout).unwrap();
let first = s.lines().next().unwrap();
assert!(first.starts_with("wsh("), "got: {first}");
assert!(
first.contains("@0") && first.contains("@1") && first.contains("@2"),
"expected all three placeholders in {first}"
);
}