aboutsummaryrefslogtreecommitdiff
path: root/src/luax/tests/preprocessor.rs
diff options
context:
space:
mode:
authorStanisław Zagórowski <hasohasacz@gmail.com>2024-01-12 20:28:42 +0100
committerStanisław Zagórowski <hasohasacz@gmail.com>2024-01-12 20:28:42 +0100
commit4a11fd2bd6329af21f8a3c60d70afc973f6518a4 (patch)
tree972cb85bbfe33f8804533673d6e9d6c57e2016e5 /src/luax/tests/preprocessor.rs
parentcae3d331d63916398edc0f3808c1471a78c8fb04 (diff)
enough to run my website
Diffstat (limited to 'src/luax/tests/preprocessor.rs')
-rw-r--r--src/luax/tests/preprocessor.rs79
1 files changed, 78 insertions, 1 deletions
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 <div>{$ hello $}</div>",
+ "return { tag=\"div\", attrs={}, children={ hello,} }",
+ )
+}
+
+#[test]
+fn html_with_code_and_text() -> Result<()> {
+ compare_output(
+ "return <div>hello {$ world $}</div>",
+ "return { tag=\"div\", attrs={}, children={ \"hello \", world,} }",
+ )
+}
+
+#[test]
+fn function_returning_html() -> Result<()> {
+ compare_output(
+ "function hello() return <div></div> end",
+ "function hello ( ) return { tag=\"div\", attrs={}, children={} } end",
+ )
+}
+
+#[test]
+fn function_returning_nested_html() -> Result<()> {
+ compare_output(
+ "function hello() return <div><span></span></div> 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 <div>{$ world $}</div> end",
+ "function hello ( ) return { tag=\"div\", attrs={}, children={ world,} } end",
+ )
+}
+
+#[test]
+fn component() -> Result<()> {
+ compare_output("return <Hello />", "return Hello ({ attrs={}, children={} })")
+}
+
+#[test]
+fn component_with_attrs() -> Result<()> {
+ compare_output(
+ "return <Hello name=\"world\" />",
+ "return Hello ({ attrs={name=\"world\", }, children={} })",
+ )
+}
+
+#[test]
+fn component_with_children() -> Result<()> {
+ compare_output(
+ "return <Hello><span /></Hello>",
+ "return Hello ({ attrs={}, children={ { tag=\"span\", attrs={}, children={} },} })",
+ )
+}
+
+#[test]
+fn html_with_attrs_with_dash() -> Result<()> {
+ compare_output(
+ "return <div data-hello=\"world\"></div>",
+ "return { tag=\"div\", attrs={[\"data-hello\"]=\"world\", }, children={} }",
+ )
+}
+
+#[test]
+fn weird_symbols_in_html() -> Result<()> {
+ compare_output(
+ "return <div>@everyone</div>",
+ "return { tag=\"div\", attrs={}, children={ \"@everyone\",} }",
+ )
+}