use indoc::indoc;
use quilt::langs::omni::Omni;
use quilt::prelude::*;
use quilt::term::STerm;
fn expand_py(code: &str) -> Result<String> {
let mut omni = Omni::default();
let q = omni.parse_lang("py", code)?;
Ok(omni.expand_lang("py", &q)?.coparse())
}
#[test]
fn simple() -> Result<()> {
let out = expand_py("x = ↖1 + 2↗")?;
assert_eq!(
out,
r#"x = tb("binary_operator").c(leaf("integer", "1")).w(" ").c(sym("+")).w(" ").c(leaf("integer", "2")).b()"#
);
Ok(())
}
#[test]
fn quote_expr() -> Result<()> {
let out = expand_py("↖1 + 2↗")?;
assert_eq!(
out,
r#"tb("binary_operator").c(leaf("integer", "1")).w(" ").c(sym("+")).w(" ").c(leaf("integer", "2")).b()"#
);
Ok(())
}
#[test]
fn variadic() -> Result<()> {
let out = expand_py(indoc! {r#"
↖def foo():
print("Hello")
print("World")
↗
"#})?;
assert!(
out.contains(r#"tb("block").e(tb("expression_statement")"#),
"variadic block should use a fluent .e() emit chain; got:\n{out}"
);
assert!(
out.ends_with(".b()"),
"expansion should end with a .b() build call; got:\n{out}"
);
Ok(())
}
#[test]
fn unquote() -> Result<()> {
let out = expand_py("↖↖↙1↘↗↗")?;
assert!(
out.contains("unquote("),
"nested unquote should emit an unquote(..) call; got:\n{out}"
);
Ok(())
}
#[test]
fn heterogeneous_lift_into_html() -> Result<()> {
let out = expand_py("t = html↖<p>↙↑(title)↘</p>↗")?;
assert!(
out.contains("qlift_html(title)"),
"lift into an html quote should spell qlift_html; got:\n{out}"
);
Ok(())
}
#[test]
fn homogeneous_lift_is_prefix() -> Result<()> {
let out = expand_py("t = ↖[↙↑(n)↘]↗")?;
assert!(
out.contains("qlift(n)"),
"homogeneous lift should spell the prefix qlift function; got:\n{out}"
);
Ok(())
}
#[test]
fn bare_tuple_quote() -> Result<()> {
let out = expand_py("p = ↖↙a↘, ↙b↘↗")?;
assert!(
out.contains(r#"tb("expression_statement").c(a).c(sym(",")).w(" ").c(b)"#),
"a bare tuple quote should keep the expression_statement whole; got:\n{out}"
);
Ok(())
}