diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b0658a..1f1855a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,10 +79,10 @@ jobs: uses: actions/checkout@v2 - name: Install OTP and Gleam - uses: erlef/setup-beam@v1.16.0 + uses: erlef/setup-beam@v1 with: - otp-version: "25.1" - gleam-version: "0.32.4" + otp-version: "27.1" + gleam-version: "1.6.1" - name: Install Rust toolchain uses: actions-rs/toolchain@v1 @@ -107,7 +107,7 @@ jobs: run: gleam test - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: matcha-${{ matrix.target }} path: target/debug/matcha diff --git a/.gitignore b/.gitignore index 443a73c..843c92e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/build /target /test/templates/*.gleam diff --git a/README.md b/README.md index 2ce6bf9..2294694 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ text. Matcha generates well typed code that avoids issues that some more dynamic That said, if you're planning to generate structured output, it is sensible to use a better suited approach. For data formats, this should be serialization and deserialization libraries. For formats like HTML, you would likely be better -using a library like [lustre](https://hexdocs.pm/lustre/lustre/element.html#to_string_builder) or -[nakai](https://github.com/nakaixo/nakai). +using a library like [lustre](https://hexdocs.pm/lustre/lustre/element.html#to_string_tree) or +[nakai](https://hexdocs.pm/nakai/nakai.html#to_string_tree). ## Installation @@ -45,7 +45,7 @@ files it finds. Template files should have a `.matcha` extension. Templates are compiled into `.gleam` files that can be imported like any other regular module. The modules expose a `render` function, that returns a -`String`, and `render_builder` function that returns a `StringBuilder`. +`String`, and `render_tree` function that returns a `StringTree`. Some errors, mostly syntax, will be picked up by the Rust code but it is possible to generate invalid modules and so the Gleam compiler will pick up further errors. @@ -77,16 +77,16 @@ You can use `{{ name }}` syntax to insert the value of `name` into the rendered Hello {{ name }} ``` -### String Builder Value +### StringTree Value -You can use `{[ name ]}` syntax to insert a string builder value into the rendered template. This +You can use `{[ name ]}` syntax to insert a `StringTree` value into the rendered template. This has the advantage of using -[string_builder.append_builder](https://hexdocs.pm/gleam_stdlib/gleam/string_builder.html#append_builder) +[string_tree.append_tree](https://hexdocs.pm/gleam_stdlib/gleam/string_tree.html#append_tree) in the rendered template and so it more efficient for inserting content that is already in a -`StringBuilder`. This can be used to insert content from another template. +`StringTree`. This can be used to insert content from another template. ```jinja -{> with name as StringBuilder +{> with name as StringTree {[ name ]} ``` @@ -146,7 +146,7 @@ Lucy {{ second_name }} {> endfn ``` -The function always returns a `StringBuilder` value so you must use `{[ ... ]}` syntax to insert +The function always returns a `StringTree` value so you must use `{[ ... ]}` syntax to insert them into templates. The function body has its last new line trimmed, so the above function called as `full_name("Gleam")` would result in `Lucy Gleam` and not `\nLucy Gleam\n` or any other variation. If you want a trailing new line in the output then add an extra blank line before the `{> endfn`. @@ -178,7 +178,7 @@ able to import it from gleam module compiled from the template. ``` If a template only includes function declarations and no meaningful template content then matcha -will not add the `render` and `render_builder`. Instead the module will act as a library of +will not add the `render` and `render_tree`. Instead the module will act as a library of functions where each function body is a template. ## Output @@ -194,37 +194,35 @@ Hello{% if user_obj.is_admin %} Admin{% endif %} is compiled to a Gleam module: ```gleam -import gleam/string_builder.{StringBuilder} +import gleam/string_tree.{StringTree} import gleam/list import my_user.{User} -pub fn render_builder(user_obj user_obj: User) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello") - let builder = case user_obj.is_admin { +pub fn render_tree(user_obj user_obj: User) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello") + let tree = case user_obj.is_admin { True -> { - let builder = string_builder.append(builder, " Admin") - builder + let tree = string_tree.append(tree, " Admin") + tree } - False -> builder + False -> tree } - let builder = string_builder.append(builder, " + let tree = string_tree.append(tree, " ") - builder + tree } pub fn render(user_obj user_obj: User) -> String { - string_builder.to_string(render_builder(user_obj: user_obj)) + string_tree.to_string(render_tree(user_obj: user_obj)) } ``` -Which you can import and call `render` or `render_builder` on with the appropriate arguments. +Which you can import and call `render` or `render_tree` on with the appropriate arguments. ## Tests Rust tests can be run with `cargo test`. They use [insta](http://insta.rs/) for snapshots. Gleam tests can be run with `cargo run && gleam test`. - - diff --git a/manifest.toml b/manifest.toml index 370b5e4..d1a6b62 100644 --- a/manifest.toml +++ b/manifest.toml @@ -2,10 +2,10 @@ # You typically do not need to edit this file packages = [ - { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, + { name = "gleam_stdlib", version = "0.43.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "69EF22E78FDCA9097CBE7DF91C05B2A8B5436826D9F66680D879182C0860A747" }, { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, ] [requirements] gleam_stdlib = { version = ">= 0.38.0 and < 1.0.0" } -gleeunit = { version = ">= 1.2.0 and < 2.0.0"} +gleeunit = { version = ">= 1.2.0 and < 2.0.0" } diff --git a/src/error.rs b/src/error.rs index 6047b52..e2d0aa1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -53,7 +53,7 @@ pub fn write(writer: &mut W, error: Error) { }, Error::Parse(error, source) => match error { ParserError::UnexpectedToken(token, range, expected) => match token { - Token::IdentifierOrGleamToken(name) => explain_with_source( + Token::GleamTokenOrIdentifier(name) => explain_with_source( writer, &format!("Unexpected token: {}", name), source, diff --git a/src/parser.rs b/src/parser.rs index a16bfc7..c854aa6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -230,11 +230,11 @@ fn parse_for_statement(tokens: &mut TokenIter) -> Result { fn extract_identifier(tokens: &mut TokenIter) -> Result<(String, Range), ParserError> { log::trace!("extract_identifier"); match tokens.next() { - Some((Token::IdentifierOrGleamToken(name), range)) => Ok((name.clone(), range.clone())), + Some((Token::GleamTokenOrIdentifier(name), range)) => Ok((name.clone(), range.clone())), Some((token, range)) => Err(ParserError::UnexpectedToken( token.clone(), range.clone(), - vec![Token::IdentifierOrGleamToken("".to_string())], + vec![Token::GleamTokenOrIdentifier("".to_string())], )), None => Err(ParserError::UnexpectedEnd), } @@ -247,7 +247,7 @@ fn extract_code(tokens: &mut TokenIter) -> Result<(String, Range), ParserError> loop { match tokens.peek() { - Some((Token::IdentifierOrGleamToken(name), token_range)) => { + Some((Token::GleamTokenOrIdentifier(name), token_range)) => { // Create range and expand it to include all the tokens // that we're adding to this string range = range @@ -274,7 +274,7 @@ fn extract_code(tokens: &mut TokenIter) -> Result<(String, Range), ParserError> return Err(ParserError::UnexpectedToken( token.clone(), range.clone(), - vec![Token::IdentifierOrGleamToken("".to_string())], + vec![Token::GleamTokenOrIdentifier("".to_string())], )); } else { break; @@ -366,7 +366,10 @@ mod test { use super::*; + // Our only use of this is the Debug output but the compiler's dead code analysis ignores + // Debug usage so we have to allow dead_code here #[derive(Debug)] + #[expect(dead_code)] pub enum Error { Scan(ScanError), Parse(ParserError), @@ -481,13 +484,13 @@ mod test { } #[test] - fn test_parse_builder_block() { + fn test_parse_tree_block() { assert_parse!("Hello {[ name ]}, good to meet you"); } #[test] - fn test_parse_builder_expression() { - assert_parse!("Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you"); + fn test_parse_tree_expression() { + assert_parse!("Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you"); } #[test] diff --git a/src/renderer.rs b/src/renderer.rs index e4fe3b2..e558070 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -10,7 +10,7 @@ pub enum RenderError { #[derive(Debug)] struct Context { - pub builder_lines: String, + pub tree_lines: String, pub imports: Vec, pub functions: Vec, pub typed_params: Vec<(String, String)>, @@ -61,18 +61,18 @@ pub fn render( let render_functions = if context.has_template_content { format!( r#" -pub fn render_builder({params_string}) -> StringBuilder {{ - let builder = string_builder.from_string("") -{builder_lines} - builder +pub fn render_tree({params_string}) -> StringTree {{ + let tree = string_tree.from_string("") +{tree_lines} + tree }} pub fn render({params_string}) -> String {{ - string_builder.to_string(render_builder({args_string})) + string_tree.to_string(render_tree({args_string})) }} "#, params_string = params_string, - builder_lines = context.builder_lines, + tree_lines = context.tree_lines, args_string = args_string ) } else { @@ -82,7 +82,7 @@ pub fn render({params_string}) -> String {{ let output = format!( r#"// DO NOT EDIT: Code generated by {prog_name} from {source_file} -import gleam/string_builder.{{type StringBuilder}} +import gleam/string_tree.{{type StringTree}} {list_import} {import_lines}{functions} {render_functions} @@ -98,7 +98,7 @@ import gleam/string_builder.{{type StringBuilder}} } fn render_lines(iter: &mut NodeIter) -> Result { - let mut builder_lines = String::new(); + let mut tree_lines = String::new(); let mut imports = vec![]; let mut functions = vec![]; @@ -113,8 +113,8 @@ fn render_lines(iter: &mut NodeIter) -> Result { match iter.peek() { Some(Node::Text(text)) => { iter.next(); - builder_lines.push_str(&format!( - " let builder = string_builder.append(builder, \"{}\")\n", + tree_lines.push_str(&format!( + " let tree = string_tree.append(tree, \"{}\")\n", text.replace('\"', "\\\"") )); @@ -124,16 +124,16 @@ fn render_lines(iter: &mut NodeIter) -> Result { } Some(Node::Identifier(name)) => { iter.next(); - builder_lines.push_str(&format!( - " let builder = string_builder.append(builder, {})\n", + tree_lines.push_str(&format!( + " let tree = string_tree.append(tree, {})\n", name )); has_template_content = true; } Some(Node::Builder(name)) => { iter.next(); - builder_lines.push_str(&format!( - " let builder = string_builder.append_builder(builder, {})\n", + tree_lines.push_str(&format!( + " let tree = string_tree.append_tree(tree, {})\n", name )); has_template_content = true; @@ -159,19 +159,19 @@ fn render_lines(iter: &mut NodeIter) -> Result { iter.next(); let if_context = render_lines(&mut if_nodes.iter().peekable())?; let else_context = render_lines(&mut else_nodes.iter().peekable())?; - builder_lines.push_str(&format!( - r#" let builder = case {} {{ + tree_lines.push_str(&format!( + r#" let tree = case {} {{ True -> {{ {} - builder + tree }} False -> {{ {} - builder + tree }} }} "#, - identifier_name, if_context.builder_lines, else_context.builder_lines + identifier_name, if_context.tree_lines, else_context.tree_lines )); includes_for_loop = includes_for_loop || if_context.includes_for_loop @@ -187,13 +187,13 @@ fn render_lines(iter: &mut NodeIter) -> Result { .unwrap_or_else(|| "".to_string()); let loop_context = render_lines(&mut loop_nodes.iter().peekable())?; - builder_lines.push_str(&format!( - r#" let builder = list.fold({}, builder, fn(builder, {}{}) {{ + tree_lines.push_str(&format!( + r#" let tree = list.fold({}, tree, fn(tree, {}{}) {{ {} - builder + tree }}) "#, - list_identifier, entry_identifier, entry_type, loop_context.builder_lines + list_identifier, entry_identifier, entry_type, loop_context.tree_lines )); includes_for_loop = true; @@ -206,12 +206,12 @@ fn render_lines(iter: &mut NodeIter) -> Result { Visibility::Public => "pub ", }; let body_context = render_lines(&mut body_nodes.iter().peekable())?; - let body = body_context.builder_lines; + let body = body_context.tree_lines; functions.push(format!( - r#"{visibility_text}fn {head} -> StringBuilder {{ - let builder = string_builder.from_string("") + r#"{visibility_text}fn {head} -> StringTree {{ + let tree = string_tree.from_string("") {body} - builder + tree }}"#, )); @@ -222,7 +222,7 @@ fn render_lines(iter: &mut NodeIter) -> Result { } Ok(Context { - builder_lines, + tree_lines, imports, functions, typed_params, @@ -238,7 +238,10 @@ mod test { use crate::parser::{self, ParserError}; use crate::scanner::{self, ScanError}; + // Our only use of this is the Debug output but the compiler's dead code analysis ignores + // Debug usage so we have to allow dead_code here #[derive(Debug)] + #[expect(dead_code)] pub enum Error { Scan(ScanError), Parse(ParserError), @@ -414,16 +417,16 @@ Hello{% if user.is_admin %} Admin{% endif %}" } #[test] - fn test_render_builder_block() { + fn test_render_tree_block() { assert_render!( - "{> with name as StringBuilder + "{> with name as StringTree Hello {[ name ]}, good to meet you" ); } #[test] - fn test_render_builder_expression() { - assert_render!("Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you"); + fn test_render_tree_expression() { + assert_render!("Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you"); } #[test] diff --git a/src/scanner.rs b/src/scanner.rs index bc849d1..975814e 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -14,7 +14,7 @@ pub enum Token { CloseValue, OpenBuilder, CloseBuilder, - IdentifierOrGleamToken(String), + GleamTokenOrIdentifier(String), Import, ImportDetails(String), With, @@ -44,7 +44,7 @@ impl std::fmt::Display for Token { Token::CloseBuilder => "]}", Token::OpenStmt => "{%", Token::CloseStmt => "%}", - Token::IdentifierOrGleamToken(name) => name, + Token::GleamTokenOrIdentifier(name) => name, Token::Import => "import", Token::ImportDetails(_) => "import-details", Token::With => "with", @@ -342,7 +342,7 @@ fn to_token(identifier: &str) -> Token { "fn" => Token::Fn, "endfn" => Token::EndFn, "pub" => Token::Pub, - other => Token::IdentifierOrGleamToken(other.to_string()), + other => Token::GleamTokenOrIdentifier(other.to_string()), } } @@ -528,13 +528,13 @@ mod test { } #[test] - fn test_scan_builder_block() { - assert_scan!("Hello {[ builder ]}, good to meet you"); + fn test_scan_tree_block() { + assert_scan!("Hello {[ tree ]}, good to meet you"); } #[test] - fn test_scan_builder_expression() { - assert_scan!("Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you"); + fn test_scan_tree_expression() { + assert_scan!("Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you"); } #[test] diff --git a/src/snapshots/matcha__parser__test__parse_builder_expression.snap b/src/snapshots/matcha__parser__test__parse_builder_expression.snap deleted file mode 100644 index efba6c7..0000000 --- a/src/snapshots/matcha__parser__test__parse_builder_expression.snap +++ /dev/null @@ -1,15 +0,0 @@ ---- -source: src/parser.rs -expression: "Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" ---- -[ - Text( - "Hello ", - ), - Builder( - "string_builder.from_strings([\"Anna\", \" and \", \"Bob\"])", - ), - Text( - ", good to meet you", - ), -] diff --git a/src/snapshots/matcha__parser__test__parse_builder_block.snap b/src/snapshots/matcha__parser__test__parse_tree_block.snap similarity index 90% rename from src/snapshots/matcha__parser__test__parse_builder_block.snap rename to src/snapshots/matcha__parser__test__parse_tree_block.snap index 0ae4196..153819f 100644 --- a/src/snapshots/matcha__parser__test__parse_builder_block.snap +++ b/src/snapshots/matcha__parser__test__parse_tree_block.snap @@ -1,6 +1,7 @@ --- source: src/parser.rs expression: "Hello {[ name ]}, good to meet you" +snapshot_kind: text --- [ Text( diff --git a/src/snapshots/matcha__parser__test__parse_tree_expression.snap b/src/snapshots/matcha__parser__test__parse_tree_expression.snap new file mode 100644 index 0000000..53a4440 --- /dev/null +++ b/src/snapshots/matcha__parser__test__parse_tree_expression.snap @@ -0,0 +1,16 @@ +--- +source: src/parser.rs +expression: "Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" +snapshot_kind: text +--- +[ + Text( + "Hello ", + ), + Builder( + "string_tree.from_strings([\"Anna\", \" and \", \"Bob\"])", + ), + Text( + ", good to meet you", + ), +] diff --git a/src/snapshots/matcha__renderer__test__render_builder_block.snap b/src/snapshots/matcha__renderer__test__render_builder_block.snap deleted file mode 100644 index f77a796..0000000 --- a/src/snapshots/matcha__renderer__test__render_builder_block.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -source: src/renderer.rs -expression: "{> with name as StringBuilder\nHello {[ name ]}, good to meet you" ---- -// DO NOT EDIT: Code generated by matcha from -test- - -import gleam/string_builder.{type StringBuilder} - - - -pub fn render_builder(name name: StringBuilder) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append_builder(builder, name) - let builder = string_builder.append(builder, ", good to meet you") - - builder -} - -pub fn render(name name: StringBuilder) -> String { - string_builder.to_string(render_builder(name: name)) -} - - diff --git a/src/snapshots/matcha__renderer__test__render_builder_expression.snap b/src/snapshots/matcha__renderer__test__render_builder_expression.snap deleted file mode 100644 index 9e8dcbc..0000000 --- a/src/snapshots/matcha__renderer__test__render_builder_expression.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -source: src/renderer.rs -expression: "Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" ---- -// DO NOT EDIT: Code generated by matcha from -test- - -import gleam/string_builder.{type StringBuilder} - - - -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append_builder(builder, string_builder.from_strings(["Anna", " and ", "Bob"])) - let builder = string_builder.append(builder, ", good to meet you") - - builder -} - -pub fn render() -> String { - string_builder.to_string(render_builder()) -} - - diff --git a/src/snapshots/matcha__renderer__test__render_dot_access.snap b/src/snapshots/matcha__renderer__test__render_dot_access.snap index b4e599a..93e11ba 100644 --- a/src/snapshots/matcha__renderer__test__render_dot_access.snap +++ b/src/snapshots/matcha__renderer__test__render_dot_access.snap @@ -1,33 +1,32 @@ --- source: src/renderer.rs expression: "{> with user as MyUser\nHello{% if user.is_admin %} Admin{% endif %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(user user: MyUser) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello") - let builder = case user.is_admin { +pub fn render_tree(user user: MyUser) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello") + let tree = case user.is_admin { True -> { - let builder = string_builder.append(builder, " Admin") + let tree = string_tree.append(tree, " Admin") - builder + tree } False -> { - builder + tree } } - builder + tree } pub fn render(user user: MyUser) -> String { - string_builder.to_string(render_builder(user: user)) + string_tree.to_string(render_tree(user: user)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_empty_if_statement.snap b/src/snapshots/matcha__renderer__test__render_empty_if_statement.snap index e264916..463426d 100644 --- a/src/snapshots/matcha__renderer__test__render_empty_if_statement.snap +++ b/src/snapshots/matcha__renderer__test__render_empty_if_statement.snap @@ -1,32 +1,31 @@ --- source: src/renderer.rs expression: "{> with is_user as Bool\nHello {% if is_user %}{% endif %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(is_user is_user: Bool) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = case is_user { +pub fn render_tree(is_user is_user: Bool) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = case is_user { True -> { - builder + tree } False -> { - builder + tree } } - builder + tree } pub fn render(is_user is_user: Bool) -> String { - string_builder.to_string(render_builder(is_user: is_user)) + string_tree.to_string(render_tree(is_user: is_user)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_for_as_loop.snap b/src/snapshots/matcha__renderer__test__render_for_as_loop.snap index 9e628d1..2641f10 100644 --- a/src/snapshots/matcha__renderer__test__render_for_as_loop.snap +++ b/src/snapshots/matcha__renderer__test__render_for_as_loop.snap @@ -1,31 +1,30 @@ --- source: src/renderer.rs expression: "{> with list as List(Item)\nHello,{% for item as Item in list %} to {{ item }} and {% endfor %} everyone else" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import gleam/list -pub fn render_builder(list list: List(Item)) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello,") - let builder = list.fold(list, builder, fn(builder, item: Item) { - let builder = string_builder.append(builder, " to ") - let builder = string_builder.append(builder, item) - let builder = string_builder.append(builder, " and ") +pub fn render_tree(list list: List(Item)) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello,") + let tree = list.fold(list, tree, fn(tree, item: Item) { + let tree = string_tree.append(tree, " to ") + let tree = string_tree.append(tree, item) + let tree = string_tree.append(tree, " and ") - builder + tree }) - let builder = string_builder.append(builder, " everyone else") + let tree = string_tree.append(tree, " everyone else") - builder + tree } pub fn render(list list: List(Item)) -> String { - string_builder.to_string(render_builder(list: list)) + string_tree.to_string(render_tree(list: list)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_for_from_expression.snap b/src/snapshots/matcha__renderer__test__render_for_from_expression.snap index 89b7103..482cfa3 100644 --- a/src/snapshots/matcha__renderer__test__render_for_from_expression.snap +++ b/src/snapshots/matcha__renderer__test__render_for_from_expression.snap @@ -1,28 +1,27 @@ --- source: src/renderer.rs expression: "Hello {% for item as Item in list.take(list, 2) %}{{ item }}{% endfor %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import gleam/list -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = list.fold(list.take(list, 2), builder, fn(builder, item: Item) { - let builder = string_builder.append(builder, item) +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = list.fold(list.take(list, 2), tree, fn(tree, item: Item) { + let tree = string_tree.append(tree, item) - builder + tree }) - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_for_loop.snap b/src/snapshots/matcha__renderer__test__render_for_loop.snap index 2410f81..21ab1bb 100644 --- a/src/snapshots/matcha__renderer__test__render_for_loop.snap +++ b/src/snapshots/matcha__renderer__test__render_for_loop.snap @@ -1,31 +1,30 @@ --- source: src/renderer.rs expression: "{> with list as List(String)\nHello,{% for item in list %} to {{ item }} and {% endfor %} everyone else" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import gleam/list -pub fn render_builder(list list: List(String)) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello,") - let builder = list.fold(list, builder, fn(builder, item) { - let builder = string_builder.append(builder, " to ") - let builder = string_builder.append(builder, item) - let builder = string_builder.append(builder, " and ") +pub fn render_tree(list list: List(String)) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello,") + let tree = list.fold(list, tree, fn(tree, item) { + let tree = string_tree.append(tree, " to ") + let tree = string_tree.append(tree, item) + let tree = string_tree.append(tree, " and ") - builder + tree }) - let builder = string_builder.append(builder, " everyone else") + let tree = string_tree.append(tree, " everyone else") - builder + tree } pub fn render(list list: List(String)) -> String { - string_builder.to_string(render_builder(list: list)) + string_tree.to_string(render_tree(list: list)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_function.snap b/src/snapshots/matcha__renderer__test__render_function.snap index df05cc6..96d63ba 100644 --- a/src/snapshots/matcha__renderer__test__render_function.snap +++ b/src/snapshots/matcha__renderer__test__render_function.snap @@ -1,27 +1,26 @@ --- source: src/renderer.rs expression: "{> fn classes()\na b c d\n{> endfn\nHello world" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -fn classes() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "a b c d") +fn classes() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "a b c d") - builder + tree } -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello world") +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello world") - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_function_and_usage.snap b/src/snapshots/matcha__renderer__test__render_function_and_usage.snap index 90d577c..4224995 100644 --- a/src/snapshots/matcha__renderer__test__render_function_and_usage.snap +++ b/src/snapshots/matcha__renderer__test__render_function_and_usage.snap @@ -1,28 +1,27 @@ --- source: src/renderer.rs expression: "{> fn name()\nLucy\n{> endfn\nHello {[ name() ]}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -fn name() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Lucy") +fn name() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Lucy") - builder + tree } -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append_builder(builder, name()) +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append_tree(tree, name()) - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_function_with_arg_and_usage.snap b/src/snapshots/matcha__renderer__test__render_function_with_arg_and_usage.snap index dd52d55..b802461 100644 --- a/src/snapshots/matcha__renderer__test__render_function_with_arg_and_usage.snap +++ b/src/snapshots/matcha__renderer__test__render_function_with_arg_and_usage.snap @@ -1,29 +1,28 @@ --- source: src/renderer.rs expression: "{> fn full_name(second_name: String)\nLucy {{ second_name }}\n{> endfn\nHello {[ full_name(\"Gleam\") ]}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -fn full_name(second_name: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Lucy ") - let builder = string_builder.append(builder, second_name) +fn full_name(second_name: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Lucy ") + let tree = string_tree.append(tree, second_name) - builder + tree } -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append_builder(builder, full_name("Gleam")) +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append_tree(tree, full_name("Gleam")) - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_function_with_for_loop.snap b/src/snapshots/matcha__renderer__test__render_function_with_for_loop.snap index de722a1..6efa506 100644 --- a/src/snapshots/matcha__renderer__test__render_function_with_for_loop.snap +++ b/src/snapshots/matcha__renderer__test__render_function_with_for_loop.snap @@ -1,35 +1,34 @@ --- source: src/renderer.rs expression: "{> fn full_name(names: List(String))\n{% for name in names %}{{ name }},{% endfor %}\"\n{> endfn\nHello {[ names(\"Gleam\") ]}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import gleam/list -fn full_name(names: List(String)) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = list.fold(names, builder, fn(builder, name) { - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, ",") +fn full_name(names: List(String)) -> StringTree { + let tree = string_tree.from_string("") + let tree = list.fold(names, tree, fn(tree, name) { + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, ",") - builder + tree }) - let builder = string_builder.append(builder, "\"") + let tree = string_tree.append(tree, "\"") - builder + tree } -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append_builder(builder, names("Gleam")) +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append_tree(tree, names("Gleam")) - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_gleam_expression.snap b/src/snapshots/matcha__renderer__test__render_gleam_expression.snap index f2b3db9..978d906 100644 --- a/src/snapshots/matcha__renderer__test__render_gleam_expression.snap +++ b/src/snapshots/matcha__renderer__test__render_gleam_expression.snap @@ -1,24 +1,23 @@ --- source: src/renderer.rs expression: "{> import gleam/string\nHello {{ string.uppercase(name) }}, good to meet you" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import gleam/string -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append(builder, string.uppercase(name)) - let builder = string_builder.append(builder, ", good to meet you") +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append(tree, string.uppercase(name)) + let tree = string_tree.append(tree, ", good to meet you") - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_identifier.snap b/src/snapshots/matcha__renderer__test__render_identifier.snap index 59442c4..4385899 100644 --- a/src/snapshots/matcha__renderer__test__render_identifier.snap +++ b/src/snapshots/matcha__renderer__test__render_identifier.snap @@ -1,24 +1,23 @@ --- source: src/renderer.rs expression: "{> with name as String\nHello {{ name }}, good to meet you" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(name name: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, ", good to meet you") +pub fn render_tree(name name: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, ", good to meet you") - builder + tree } pub fn render(name name: String) -> String { - string_builder.to_string(render_builder(name: name)) + string_tree.to_string(render_tree(name: name)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_if_comparison.snap b/src/snapshots/matcha__renderer__test__render_if_comparison.snap index 7b1cf71..6094916 100644 --- a/src/snapshots/matcha__renderer__test__render_if_comparison.snap +++ b/src/snapshots/matcha__renderer__test__render_if_comparison.snap @@ -1,33 +1,32 @@ --- source: src/renderer.rs expression: "Hello {% if items != [] %}Some items{% endif %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = case items != [] { +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = case items != [] { True -> { - let builder = string_builder.append(builder, "Some items") + let tree = string_tree.append(tree, "Some items") - builder + tree } False -> { - builder + tree } } - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_if_else_statement.snap b/src/snapshots/matcha__renderer__test__render_if_else_statement.snap index d9838a4..f820be6 100644 --- a/src/snapshots/matcha__renderer__test__render_if_else_statement.snap +++ b/src/snapshots/matcha__renderer__test__render_if_else_statement.snap @@ -1,34 +1,33 @@ --- source: src/renderer.rs expression: "{> with is_user as Bool\nHello {% if is_user %}User{% else %}Unknown{% endif %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(is_user is_user: Bool) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = case is_user { +pub fn render_tree(is_user is_user: Bool) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = case is_user { True -> { - let builder = string_builder.append(builder, "User") + let tree = string_tree.append(tree, "User") - builder + tree } False -> { - let builder = string_builder.append(builder, "Unknown") + let tree = string_tree.append(tree, "Unknown") - builder + tree } } - builder + tree } pub fn render(is_user is_user: Bool) -> String { - string_builder.to_string(render_builder(is_user: is_user)) + string_tree.to_string(render_tree(is_user: is_user)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_if_statement.snap b/src/snapshots/matcha__renderer__test__render_if_statement.snap index ceb4ca7..5e691a3 100644 --- a/src/snapshots/matcha__renderer__test__render_if_statement.snap +++ b/src/snapshots/matcha__renderer__test__render_if_statement.snap @@ -1,33 +1,32 @@ --- source: src/renderer.rs expression: "{> with is_user as Bool\nHello {% if is_user %}User{% endif %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(is_user is_user: Bool) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = case is_user { +pub fn render_tree(is_user is_user: Bool) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = case is_user { True -> { - let builder = string_builder.append(builder, "User") + let tree = string_tree.append(tree, "User") - builder + tree } False -> { - builder + tree } } - builder + tree } pub fn render(is_user is_user: Bool) -> String { - string_builder.to_string(render_builder(is_user: is_user)) + string_tree.to_string(render_tree(is_user: is_user)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_import.snap b/src/snapshots/matcha__renderer__test__render_import.snap index 7cf2879..1bcb04c 100644 --- a/src/snapshots/matcha__renderer__test__render_import.snap +++ b/src/snapshots/matcha__renderer__test__render_import.snap @@ -1,22 +1,21 @@ --- source: src/renderer.rs expression: "{> import user.{User}\n{> with name as String\n{{ name }}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import user.{User} -pub fn render_builder(name name: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, name) +pub fn render_tree(name name: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, name) - builder + tree } pub fn render(name name: String) -> String { - string_builder.to_string(render_builder(name: name)) + string_tree.to_string(render_tree(name: name)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_import_and_with.snap b/src/snapshots/matcha__renderer__test__render_import_and_with.snap index 24803d2..2b7b443 100644 --- a/src/snapshots/matcha__renderer__test__render_import_and_with.snap +++ b/src/snapshots/matcha__renderer__test__render_import_and_with.snap @@ -1,22 +1,21 @@ --- source: src/renderer.rs expression: "{> import user.{User}\n{> with user as User\n{{ user }}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import user.{User} -pub fn render_builder(user user: User) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, user) +pub fn render_tree(user user: User) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, user) - builder + tree } pub fn render(user user: User) -> String { - string_builder.to_string(render_builder(user: user)) + string_tree.to_string(render_tree(user: user)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_multiline.snap b/src/snapshots/matcha__renderer__test__render_multiline.snap index 8c0ae5a..0a19b7c 100644 --- a/src/snapshots/matcha__renderer__test__render_multiline.snap +++ b/src/snapshots/matcha__renderer__test__render_multiline.snap @@ -1,35 +1,34 @@ --- source: src/renderer.rs expression: "{> with my_list as List(String)\n
    \n{% for entry in my_list %}\n
  • {{ entry }}
  • \n{% endfor %}\n
" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} import gleam/list -pub fn render_builder(my_list my_list: List(String)) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "
    +pub fn render_tree(my_list my_list: List(String)) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "
      ") - let builder = list.fold(my_list, builder, fn(builder, entry) { - let builder = string_builder.append(builder, " + let tree = list.fold(my_list, tree, fn(tree, entry) { + let tree = string_tree.append(tree, "
    • ") - let builder = string_builder.append(builder, entry) - let builder = string_builder.append(builder, "
    • + let tree = string_tree.append(tree, entry) + let tree = string_tree.append(tree, " ") - builder + tree }) - let builder = string_builder.append(builder, " + let tree = string_tree.append(tree, "
    ") - builder + tree } pub fn render(my_list my_list: List(String)) -> String { - string_builder.to_string(render_builder(my_list: my_list)) + string_tree.to_string(render_tree(my_list: my_list)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_nested_if_statements.snap b/src/snapshots/matcha__renderer__test__render_nested_if_statements.snap index 0019fdd..faee1cf 100644 --- a/src/snapshots/matcha__renderer__test__render_nested_if_statements.snap +++ b/src/snapshots/matcha__renderer__test__render_nested_if_statements.snap @@ -1,44 +1,43 @@ --- source: src/renderer.rs expression: "{> with is_user as Bool\n{> with is_admin as Bool\nHello {% if is_user %}{% if is_admin %}Admin{% else %}User{% endif %}{% endif %}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(is_user is_user: Bool, is_admin is_admin: Bool) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = case is_user { +pub fn render_tree(is_user is_user: Bool, is_admin is_admin: Bool) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = case is_user { True -> { - let builder = case is_admin { + let tree = case is_admin { True -> { - let builder = string_builder.append(builder, "Admin") + let tree = string_tree.append(tree, "Admin") - builder + tree } False -> { - let builder = string_builder.append(builder, "User") + let tree = string_tree.append(tree, "User") - builder + tree } } - builder + tree } False -> { - builder + tree } } - builder + tree } pub fn render(is_user is_user: Bool, is_admin is_admin: Bool) -> String { - string_builder.to_string(render_builder(is_user: is_user, is_admin: is_admin)) + string_tree.to_string(render_tree(is_user: is_user, is_admin: is_admin)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_only_public_functions.snap b/src/snapshots/matcha__renderer__test__render_only_public_functions.snap index f620c92..8f0a233 100644 --- a/src/snapshots/matcha__renderer__test__render_only_public_functions.snap +++ b/src/snapshots/matcha__renderer__test__render_only_public_functions.snap @@ -1,25 +1,24 @@ --- source: src/renderer.rs expression: "\n{> pub fn classes()\n a b c d\n{> endfn\n\n{> pub fn item(name: String)\n
  • {{ name }}
  • \n{> endfn\n" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn classes() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, " a b c d") +pub fn classes() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, " a b c d") - builder + tree } -pub fn item(name: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "
  • ") - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, "
  • ") +pub fn item(name: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "
  • ") + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, "
  • ") - builder + tree } - - diff --git a/src/snapshots/matcha__renderer__test__render_public_function.snap b/src/snapshots/matcha__renderer__test__render_public_function.snap index 368d45b..6c62046 100644 --- a/src/snapshots/matcha__renderer__test__render_public_function.snap +++ b/src/snapshots/matcha__renderer__test__render_public_function.snap @@ -1,27 +1,26 @@ --- source: src/renderer.rs expression: "{> pub fn classes()\na b c d\n{> endfn\nHello world" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn classes() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "a b c d") +pub fn classes() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "a b c d") - builder + tree } -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello world") +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello world") - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_pure_text.snap b/src/snapshots/matcha__renderer__test__render_pure_text.snap index ff48760..49ffae7 100644 --- a/src/snapshots/matcha__renderer__test__render_pure_text.snap +++ b/src/snapshots/matcha__renderer__test__render_pure_text.snap @@ -1,22 +1,21 @@ --- source: src/renderer.rs expression: "Hello name, good to meet you" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder() -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello name, good to meet you") +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello name, good to meet you") - builder + tree } pub fn render() -> String { - string_builder.to_string(render_builder()) + string_tree.to_string(render_tree()) } - - diff --git a/src/snapshots/matcha__renderer__test__render_quotes.snap b/src/snapshots/matcha__renderer__test__render_quotes.snap index 95578a4..44bbc94 100644 --- a/src/snapshots/matcha__renderer__test__render_quotes.snap +++ b/src/snapshots/matcha__renderer__test__render_quotes.snap @@ -1,24 +1,23 @@ --- source: src/renderer.rs expression: "{> with name as String\n
    {{ name }}
    " +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(name name: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "
    ") - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, "
    ") +pub fn render_tree(name name: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "
    ") + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, "
    ") - builder + tree } pub fn render(name name: String) -> String { - string_builder.to_string(render_builder(name: name)) + string_tree.to_string(render_tree(name: name)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_tree_block.snap b/src/snapshots/matcha__renderer__test__render_tree_block.snap new file mode 100644 index 0000000..8c1a4aa --- /dev/null +++ b/src/snapshots/matcha__renderer__test__render_tree_block.snap @@ -0,0 +1,23 @@ +--- +source: src/renderer.rs +expression: "{> with name as StringTree\nHello {[ name ]}, good to meet you" +snapshot_kind: text +--- +// DO NOT EDIT: Code generated by matcha from -test- + +import gleam/string_tree.{type StringTree} + + + +pub fn render_tree(name name: StringTree) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append_tree(tree, name) + let tree = string_tree.append(tree, ", good to meet you") + + tree +} + +pub fn render(name name: StringTree) -> String { + string_tree.to_string(render_tree(name: name)) +} diff --git a/src/snapshots/matcha__renderer__test__render_tree_expression.snap b/src/snapshots/matcha__renderer__test__render_tree_expression.snap new file mode 100644 index 0000000..b51b753 --- /dev/null +++ b/src/snapshots/matcha__renderer__test__render_tree_expression.snap @@ -0,0 +1,23 @@ +--- +source: src/renderer.rs +expression: "Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" +snapshot_kind: text +--- +// DO NOT EDIT: Code generated by matcha from -test- + +import gleam/string_tree.{type StringTree} + + + +pub fn render_tree() -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append_tree(tree, string_tree.from_strings(["Anna", " and ", "Bob"])) + let tree = string_tree.append(tree, ", good to meet you") + + tree +} + +pub fn render() -> String { + string_tree.to_string(render_tree()) +} diff --git a/src/snapshots/matcha__renderer__test__render_two_identifiers.snap b/src/snapshots/matcha__renderer__test__render_two_identifiers.snap index 00f9c83..2d6b080 100644 --- a/src/snapshots/matcha__renderer__test__render_two_identifiers.snap +++ b/src/snapshots/matcha__renderer__test__render_two_identifiers.snap @@ -1,26 +1,25 @@ --- source: src/renderer.rs expression: "{> with name as String\n{> with adjective as String\nHello {{ name }}, {{ adjective }} to meet you" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(name name: String, adjective adjective: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, "Hello ") - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, ", ") - let builder = string_builder.append(builder, adjective) - let builder = string_builder.append(builder, " to meet you") +pub fn render_tree(name name: String, adjective adjective: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, "Hello ") + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, ", ") + let tree = string_tree.append(tree, adjective) + let tree = string_tree.append(tree, " to meet you") - builder + tree } pub fn render(name name: String, adjective adjective: String) -> String { - string_builder.to_string(render_builder(name: name, adjective: adjective)) + string_tree.to_string(render_tree(name: name, adjective: adjective)) } - - diff --git a/src/snapshots/matcha__renderer__test__render_with.snap b/src/snapshots/matcha__renderer__test__render_with.snap index 3c941fb..2320633 100644 --- a/src/snapshots/matcha__renderer__test__render_with.snap +++ b/src/snapshots/matcha__renderer__test__render_with.snap @@ -1,22 +1,21 @@ --- source: src/renderer.rs expression: "{> with user as User\n{{ user }}" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(user user: User) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, user) +pub fn render_tree(user user: User) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, user) - builder + tree } pub fn render(user user: User) -> String { - string_builder.to_string(render_builder(user: user)) + string_tree.to_string(render_tree(user: user)) } - - diff --git a/src/snapshots/matcha__renderer__test__repeated_identifier_usage.snap b/src/snapshots/matcha__renderer__test__repeated_identifier_usage.snap index d0a407e..875925d 100644 --- a/src/snapshots/matcha__renderer__test__repeated_identifier_usage.snap +++ b/src/snapshots/matcha__renderer__test__repeated_identifier_usage.snap @@ -1,25 +1,24 @@ --- source: src/renderer.rs expression: "{> with name as String\n{{ name }} usage, {{ name }} usage" +snapshot_kind: text --- // DO NOT EDIT: Code generated by matcha from -test- -import gleam/string_builder.{type StringBuilder} +import gleam/string_tree.{type StringTree} -pub fn render_builder(name name: String) -> StringBuilder { - let builder = string_builder.from_string("") - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, " usage, ") - let builder = string_builder.append(builder, name) - let builder = string_builder.append(builder, " usage") +pub fn render_tree(name name: String) -> StringTree { + let tree = string_tree.from_string("") + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, " usage, ") + let tree = string_tree.append(tree, name) + let tree = string_tree.append(tree, " usage") - builder + tree } pub fn render(name name: String) -> String { - string_builder.to_string(render_builder(name: name)) + string_tree.to_string(render_tree(name: name)) } - - diff --git a/src/snapshots/matcha__scanner__test__scan_builder_expression.snap b/src/snapshots/matcha__scanner__test__scan_builder_expression.snap index e56bae1..e1fa090 100644 --- a/src/snapshots/matcha__scanner__test__scan_builder_expression.snap +++ b/src/snapshots/matcha__scanner__test__scan_builder_expression.snap @@ -1,6 +1,7 @@ --- source: src/scanner.rs -expression: "Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" +expression: "Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" +snapshot_kind: text --- [ ( @@ -15,42 +16,42 @@ expression: "Hello {[ string_builder.from_strings([\"Anna\", \" and \", \"Bob\"] ), ( IdentifierOrGleamToken( - "string_builder.from_strings([\"Anna\",", + "string_tree.from_strings([\"Anna\",", ), - 9..45, + 9..42, ), ( IdentifierOrGleamToken( "\"", ), - 46..47, + 43..44, ), ( IdentifierOrGleamToken( "and", ), - 48..51, + 45..48, ), ( IdentifierOrGleamToken( "\",", ), - 52..54, + 49..51, ), ( IdentifierOrGleamToken( "\"Bob\"])", ), - 55..62, + 52..59, ), ( CloseBuilder, - 63..64, + 60..61, ), ( Text( ", good to meet you", ), - 65..82, + 62..79, ), ] diff --git a/src/snapshots/matcha__scanner__test__scan_dot_access.snap b/src/snapshots/matcha__scanner__test__scan_dot_access.snap index 9e25b77..1a78eb2 100644 --- a/src/snapshots/matcha__scanner__test__scan_dot_access.snap +++ b/src/snapshots/matcha__scanner__test__scan_dot_access.snap @@ -18,7 +18,7 @@ expression: "Hello{% if user.is_admin %} Admin{% endif %}" 8..10, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "user.is_admin", ), 11..24, diff --git a/src/snapshots/matcha__scanner__test__scan_for_as_loop.snap b/src/snapshots/matcha__scanner__test__scan_for_as_loop.snap index e79c4fa..f3cf629 100644 --- a/src/snapshots/matcha__scanner__test__scan_for_as_loop.snap +++ b/src/snapshots/matcha__scanner__test__scan_for_as_loop.snap @@ -18,7 +18,7 @@ expression: "Hello {% for item as Item in list %}{{ item }}{% endfor %}" 9..12, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "item", ), 13..17, @@ -28,7 +28,7 @@ expression: "Hello {% for item as Item in list %}{{ item }}{% endfor %}" 18..20, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "Item", ), 21..25, @@ -38,7 +38,7 @@ expression: "Hello {% for item as Item in list %}{{ item }}{% endfor %}" 26..28, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "list", ), 29..33, @@ -52,7 +52,7 @@ expression: "Hello {% for item as Item in list %}{{ item }}{% endfor %}" 36..37, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "item", ), 39..43, diff --git a/src/snapshots/matcha__scanner__test__scan_for_from_expression.snap b/src/snapshots/matcha__scanner__test__scan_for_from_expression.snap index 8b40c39..0149a3d 100644 --- a/src/snapshots/matcha__scanner__test__scan_for_from_expression.snap +++ b/src/snapshots/matcha__scanner__test__scan_for_from_expression.snap @@ -18,7 +18,7 @@ expression: "Hello {% for item as Item in list.take(list, 2) %}{{ item }}{% endf 9..12, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "item", ), 13..17, @@ -28,7 +28,7 @@ expression: "Hello {% for item as Item in list.take(list, 2) %}{{ item }}{% endf 18..20, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "Item", ), 21..25, @@ -38,13 +38,13 @@ expression: "Hello {% for item as Item in list.take(list, 2) %}{{ item }}{% endf 26..28, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "list.take(list,", ), 29..44, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "2)", ), 45..47, @@ -58,7 +58,7 @@ expression: "Hello {% for item as Item in list.take(list, 2) %}{{ item }}{% endf 50..51, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "item", ), 53..57, diff --git a/src/snapshots/matcha__scanner__test__scan_for_loop.snap b/src/snapshots/matcha__scanner__test__scan_for_loop.snap index a51ca9a..54d1e7b 100644 --- a/src/snapshots/matcha__scanner__test__scan_for_loop.snap +++ b/src/snapshots/matcha__scanner__test__scan_for_loop.snap @@ -18,7 +18,7 @@ expression: "Hello {% for item in list %}{{ item }}{% endfor %}" 9..12, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "item", ), 13..17, @@ -28,7 +28,7 @@ expression: "Hello {% for item in list %}{{ item }}{% endfor %}" 18..20, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "list", ), 21..25, @@ -42,7 +42,7 @@ expression: "Hello {% for item in list %}{{ item }}{% endfor %}" 28..29, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "item", ), 31..35, diff --git a/src/snapshots/matcha__scanner__test__scan_function_start.snap b/src/snapshots/matcha__scanner__test__scan_function_start.snap index 98b6ab8..3776e02 100644 --- a/src/snapshots/matcha__scanner__test__scan_function_start.snap +++ b/src/snapshots/matcha__scanner__test__scan_function_start.snap @@ -12,37 +12,37 @@ expression: "{> fn concat(x: String, y: String) -> String\n" 3..5, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "concat(x:", ), 6..15, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "String,", ), 16..23, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "y:", ), 24..26, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "String)", ), 27..34, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "->", ), 35..37, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "String", ), 38..44, diff --git a/src/snapshots/matcha__scanner__test__scan_function_whole.snap b/src/snapshots/matcha__scanner__test__scan_function_whole.snap index e2ec018..4a48839 100644 --- a/src/snapshots/matcha__scanner__test__scan_function_whole.snap +++ b/src/snapshots/matcha__scanner__test__scan_function_whole.snap @@ -12,19 +12,19 @@ expression: "{> fn classes() -> String\nx y\n{> endfn\n" 3..5, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "classes()", ), 6..15, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "->", ), 16..18, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "String", ), 19..25, diff --git a/src/snapshots/matcha__scanner__test__scan_gleam_expression.snap b/src/snapshots/matcha__scanner__test__scan_gleam_expression.snap index 7729303..6ec66a9 100644 --- a/src/snapshots/matcha__scanner__test__scan_gleam_expression.snap +++ b/src/snapshots/matcha__scanner__test__scan_gleam_expression.snap @@ -14,7 +14,7 @@ expression: "Hello {{ string.uppercase(name) }}, good to meet you" 6..7, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "string.uppercase(name)", ), 9..31, diff --git a/src/snapshots/matcha__scanner__test__scan_identifier.snap b/src/snapshots/matcha__scanner__test__scan_identifier.snap index b5927d0..0477eaa 100644 --- a/src/snapshots/matcha__scanner__test__scan_identifier.snap +++ b/src/snapshots/matcha__scanner__test__scan_identifier.snap @@ -14,7 +14,7 @@ expression: "Hello {{ name }}, good to meet you" 6..7, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "name", ), 9..13, diff --git a/src/snapshots/matcha__scanner__test__scan_if_comparison.snap b/src/snapshots/matcha__scanner__test__scan_if_comparison.snap index b630799..a97051c 100644 --- a/src/snapshots/matcha__scanner__test__scan_if_comparison.snap +++ b/src/snapshots/matcha__scanner__test__scan_if_comparison.snap @@ -18,19 +18,19 @@ expression: "Hello {% if items != [] %}Some items{% endif %}" 9..11, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "items", ), 12..17, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "!=", ), 18..20, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "[]", ), 21..23, diff --git a/src/snapshots/matcha__scanner__test__scan_if_else_statement.snap b/src/snapshots/matcha__scanner__test__scan_if_else_statement.snap index 1463b93..8012029 100644 --- a/src/snapshots/matcha__scanner__test__scan_if_else_statement.snap +++ b/src/snapshots/matcha__scanner__test__scan_if_else_statement.snap @@ -18,7 +18,7 @@ expression: "Hello {% if is_user %}User{% else %}Unknown{% endif %}" 9..11, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "is_user", ), 12..19, diff --git a/src/snapshots/matcha__scanner__test__scan_if_statement.snap b/src/snapshots/matcha__scanner__test__scan_if_statement.snap index 26da52b..aa466fa 100644 --- a/src/snapshots/matcha__scanner__test__scan_if_statement.snap +++ b/src/snapshots/matcha__scanner__test__scan_if_statement.snap @@ -18,7 +18,7 @@ expression: "Hello {% if is_user %}User{% endif %}" 9..11, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "is_user", ), 12..19, diff --git a/src/snapshots/matcha__scanner__test__scan_import.snap b/src/snapshots/matcha__scanner__test__scan_import.snap index b8a2598..1880998 100644 --- a/src/snapshots/matcha__scanner__test__scan_import.snap +++ b/src/snapshots/matcha__scanner__test__scan_import.snap @@ -26,7 +26,7 @@ expression: "{> import user.{User}\n{{ name }}" 22..23, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "name", ), 25..29, diff --git a/src/snapshots/matcha__scanner__test__scan_nested_if_statements.snap b/src/snapshots/matcha__scanner__test__scan_nested_if_statements.snap index 55c83eb..7069361 100644 --- a/src/snapshots/matcha__scanner__test__scan_nested_if_statements.snap +++ b/src/snapshots/matcha__scanner__test__scan_nested_if_statements.snap @@ -18,7 +18,7 @@ expression: "Hello {% if is_user %}{% if is_admin %}Admin{% else %}User{% endif 9..11, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "is_user", ), 12..19, @@ -36,7 +36,7 @@ expression: "Hello {% if is_user %}{% if is_admin %}Admin{% else %}User{% endif 25..27, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "is_admin", ), 28..36, diff --git a/src/snapshots/matcha__scanner__test__scan_pub_function_whole.snap b/src/snapshots/matcha__scanner__test__scan_pub_function_whole.snap index ad31030..cb5ff0e 100644 --- a/src/snapshots/matcha__scanner__test__scan_pub_function_whole.snap +++ b/src/snapshots/matcha__scanner__test__scan_pub_function_whole.snap @@ -16,19 +16,19 @@ expression: "{> pub fn classes() -> String\nx y\n{> endfn\n" 7..9, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "classes()", ), 10..19, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "->", ), 20..22, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "String", ), 23..29, diff --git a/src/snapshots/matcha__scanner__test__scan_builder_block.snap b/src/snapshots/matcha__scanner__test__scan_tree_block.snap similarity index 65% rename from src/snapshots/matcha__scanner__test__scan_builder_block.snap rename to src/snapshots/matcha__scanner__test__scan_tree_block.snap index 93e8620..c6b0fad 100644 --- a/src/snapshots/matcha__scanner__test__scan_builder_block.snap +++ b/src/snapshots/matcha__scanner__test__scan_tree_block.snap @@ -1,6 +1,6 @@ --- source: src/scanner.rs -expression: "Hello {[ builder ]}, good to meet you" +expression: "Hello {[ tree ]}, good to meet you" --- [ ( @@ -14,19 +14,19 @@ expression: "Hello {[ builder ]}, good to meet you" 6..7, ), ( - IdentifierOrGleamToken( - "builder", + GleamTokenOrIdentifier( + "tree", ), - 9..16, + 9..13, ), ( CloseBuilder, - 17..18, + 14..15, ), ( Text( ", good to meet you", ), - 19..36, + 16..33, ), ] diff --git a/src/snapshots/matcha__scanner__test__scan_tree_expression.snap b/src/snapshots/matcha__scanner__test__scan_tree_expression.snap new file mode 100644 index 0000000..0caa179 --- /dev/null +++ b/src/snapshots/matcha__scanner__test__scan_tree_expression.snap @@ -0,0 +1,56 @@ +--- +source: src/scanner.rs +expression: "Hello {[ string_tree.from_strings([\"Anna\", \" and \", \"Bob\"]) ]}, good to meet you" +--- +[ + ( + Text( + "Hello ", + ), + 0..6, + ), + ( + OpenBuilder, + 6..7, + ), + ( + GleamTokenOrIdentifier( + "string_tree.from_strings([\"Anna\",", + ), + 9..42, + ), + ( + GleamTokenOrIdentifier( + "\"", + ), + 43..44, + ), + ( + GleamTokenOrIdentifier( + "and", + ), + 45..48, + ), + ( + GleamTokenOrIdentifier( + "\",", + ), + 49..51, + ), + ( + GleamTokenOrIdentifier( + "\"Bob\"])", + ), + 52..59, + ), + ( + CloseBuilder, + 60..61, + ), + ( + Text( + ", good to meet you", + ), + 62..79, + ), +] diff --git a/src/snapshots/matcha__scanner__test__scan_two_identifiers.snap b/src/snapshots/matcha__scanner__test__scan_two_identifiers.snap index a0241c0..abff4ac 100644 --- a/src/snapshots/matcha__scanner__test__scan_two_identifiers.snap +++ b/src/snapshots/matcha__scanner__test__scan_two_identifiers.snap @@ -14,7 +14,7 @@ expression: "Hello {{ name }}, {{ adjective }} to meet you" 6..7, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "name", ), 9..13, @@ -34,7 +34,7 @@ expression: "Hello {{ name }}, {{ adjective }} to meet you" 18..19, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "adjective", ), 21..30, diff --git a/src/snapshots/matcha__scanner__test__scan_with.snap b/src/snapshots/matcha__scanner__test__scan_with.snap index 68582bd..efceaf4 100644 --- a/src/snapshots/matcha__scanner__test__scan_with.snap +++ b/src/snapshots/matcha__scanner__test__scan_with.snap @@ -12,7 +12,7 @@ expression: "{> with user as User\n{{ user }}" 3..7, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "user", ), 8..12, @@ -22,7 +22,7 @@ expression: "{> with user as User\n{{ user }}" 13..15, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "User", ), 16..20, @@ -36,7 +36,7 @@ expression: "{> with user as User\n{{ user }}" 21..22, ), ( - IdentifierOrGleamToken( + GleamTokenOrIdentifier( "user", ), 24..28, diff --git a/test/matcha_test.gleam b/test/matcha_test.gleam index 55ff491..d8a794f 100644 --- a/test/matcha_test.gleam +++ b/test/matcha_test.gleam @@ -1,28 +1,28 @@ -import gleam/string_builder +import gleam/string_tree import gleeunit import gleeunit/should -import templates/identifier -import templates/two_identifiers +import my_user.{NamedUser, User} +import templates/dot_access import templates/double_identifier_usage -import templates/if_statement -import templates/if_else_statement -import templates/if_comparison -import templates/nested_if_statement -import templates/for_loop import templates/for_as_loop +import templates/for_loop import templates/for_loop_from_expression -import templates/dot_access +import templates/function_html +import templates/function_with_arg +import templates/identifier +import templates/if_comparison +import templates/if_else_statement +import templates/if_statement import templates/multiline -import templates/value_in_for_loop -import templates/value_in_if_else -import templates/value_expression +import templates/nested_if_statement import templates/quote -import templates/builder -import templates/builder_expression -import templates/function_with_arg -import templates/function_html +import templates/tree +import templates/tree_expression +import templates/two_identifiers import templates/use_pub_function -import my_user.{NamedUser, User} +import templates/value_expression +import templates/value_in_for_loop +import templates/value_in_if_else pub fn main() { gleeunit.main() @@ -54,14 +54,14 @@ pub fn double_identifier_usage_test() { |> should.equal("Double usage, Double usage\n") } -pub fn builder_block_test() { - let name_builder = string_builder.from_strings(["Anna", " ", "Bandana"]) - builder.render(name_builder) +pub fn tree_block_test() { + let name_tree = string_tree.from_strings(["Anna", " ", "Bandana"]) + tree.render(name_tree) |> should.equal("Hello Anna Bandana, good to meet you\n") } -pub fn builder_expression_test() { - builder_expression.render() +pub fn tree_expression_test() { + tree_expression.render() |> should.equal("Hello Anna and Bob, good to meet you\n") } @@ -132,10 +132,9 @@ pub fn for_loop_from_expression_test() { } pub fn value_in_for_loop_test() { - value_in_for_loop.render( - greeting: "Hello", - my_list: ["Anna", "Bill", "Christine"], - ) + value_in_for_loop.render(greeting: "Hello", my_list: [ + "Anna", "Bill", "Christine", + ]) |> should.equal( "

    My List

      diff --git a/test/templates/builder.matcha b/test/templates/builder.matcha deleted file mode 100644 index ff11ef3..0000000 --- a/test/templates/builder.matcha +++ /dev/null @@ -1,2 +0,0 @@ -{> with name_builder as StringBuilder -Hello {[ name_builder ]}, good to meet you diff --git a/test/templates/builder_expression.matcha b/test/templates/builder_expression.matcha deleted file mode 100644 index 86a94ba..0000000 --- a/test/templates/builder_expression.matcha +++ /dev/null @@ -1 +0,0 @@ -Hello {[ string_builder.from_strings(["Anna", " and ", "Bob"]) ]}, good to meet you diff --git a/test/templates/tree.matcha b/test/templates/tree.matcha new file mode 100644 index 0000000..214f366 --- /dev/null +++ b/test/templates/tree.matcha @@ -0,0 +1,2 @@ +{> with name_ as StringTree +Hello {[ name_ ]}, good to meet you diff --git a/test/templates/tree_expression.matcha b/test/templates/tree_expression.matcha new file mode 100644 index 0000000..607cc1d --- /dev/null +++ b/test/templates/tree_expression.matcha @@ -0,0 +1 @@ +Hello {[ string_tree.from_strings(["Anna", " and ", "Bob"]) ]}, good to meet you