From 4a11fd2bd6329af21f8a3c60d70afc973f6518a4 Mon Sep 17 00:00:00 2001 From: Stanisław Zagórowski Date: Fri, 12 Jan 2024 20:28:42 +0100 Subject: enough to run my website --- src/luax/tests/preprocessor.rs | 79 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'src/luax/tests/preprocessor.rs') diff --git a/src/luax/tests/preprocessor.rs b/src/luax/tests/preprocessor.rs index d5c2f42..6769288 100644 --- a/src/luax/tests/preprocessor.rs +++ b/src/luax/tests/preprocessor.rs @@ -34,7 +34,7 @@ fn compare_output(input: &str, expected: &str) -> Result<()> { .unwrap(); println!( "first mismatch: index {}: {:?} != {:?}", - first_mismatch.0, first_mismatch.1.0, first_mismatch.1.1 + first_mismatch.0, first_mismatch.1 .0, first_mismatch.1 .1 ); println!("expected: {}", expected); println!("output: {}", output); @@ -196,3 +196,80 @@ fn site() -> Result<()> { "#, ) } + +#[test] +fn html_with_code() -> Result<()> { + compare_output( + "return
{$ hello $}
", + "return { tag=\"div\", attrs={}, children={ hello,} }", + ) +} + +#[test] +fn html_with_code_and_text() -> Result<()> { + compare_output( + "return
hello {$ world $}
", + "return { tag=\"div\", attrs={}, children={ \"hello \", world,} }", + ) +} + +#[test] +fn function_returning_html() -> Result<()> { + compare_output( + "function hello() return
end", + "function hello ( ) return { tag=\"div\", attrs={}, children={} } end", + ) +} + +#[test] +fn function_returning_nested_html() -> Result<()> { + compare_output( + "function hello() return
end", + "function hello ( ) return { tag=\"div\", attrs={}, children={ { tag=\"span\", attrs={}, children={} },} } end", + ) +} + +#[test] +fn function_returning_nested_html_with_code() -> Result<()> { + compare_output( + "function hello() return
{$ world $}
end", + "function hello ( ) return { tag=\"div\", attrs={}, children={ world,} } end", + ) +} + +#[test] +fn component() -> Result<()> { + compare_output("return ", "return Hello ({ attrs={}, children={} })") +} + +#[test] +fn component_with_attrs() -> Result<()> { + compare_output( + "return ", + "return Hello ({ attrs={name=\"world\", }, children={} })", + ) +} + +#[test] +fn component_with_children() -> Result<()> { + compare_output( + "return ", + "return Hello ({ attrs={}, children={ { tag=\"span\", attrs={}, children={} },} })", + ) +} + +#[test] +fn html_with_attrs_with_dash() -> Result<()> { + compare_output( + "return
", + "return { tag=\"div\", attrs={[\"data-hello\"]=\"world\", }, children={} }", + ) +} + +#[test] +fn weird_symbols_in_html() -> Result<()> { + compare_output( + "return
@everyone
", + "return { tag=\"div\", attrs={}, children={ \"@everyone\",} }", + ) +} -- cgit v1.3.1