From 91b85584f04227a140b63a81dc2e0446e1895ede Mon Sep 17 00:00:00 2001 From: Nathan Johnson Date: Thu, 13 Jul 2023 20:42:08 -0400 Subject: [PATCH] Fix bug with single attribute not terminating --- src/parser/attributes.gleam | 2 +- test/parser_test.gleam | 64 +++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/parser/attributes.gleam b/src/parser/attributes.gleam index 3ffe6e8..526bf85 100644 --- a/src/parser/attributes.gleam +++ b/src/parser/attributes.gleam @@ -49,7 +49,7 @@ pub fn attribute() -> nibble.Parser(Attribute, a) { one_of([ succeed(curry2(Attribute)) |> drop(whitespace()) - |> keep(take_while(fn(c) { c != "=" })) + |> keep(take_while(fn(c) { c != "=" && c != ">" })) |> drop(string("=\"")) |> keep(take_while(fn(c) { c != "\"" })) |> drop(string("\"")) diff --git a/test/parser_test.gleam b/test/parser_test.gleam index 2fbcac1..0df3849 100644 --- a/test/parser_test.gleam +++ b/test/parser_test.gleam @@ -1,7 +1,67 @@ import gleeunit - -// import parser.{ghp} +import gleeunit/should +import parser +import parser/grammar.{Block, GHP, HtmlElement, Text} +import parser/attributes.{Attribute} pub fn main() { gleeunit.main() } + +pub fn full_example_with_single_attr_test() { + let input = + "import templates/notes/list as note +import schema/notes.{Note} + +pub type Params { + Params(notes: List(Note)) +} + +pub fn render(params: Params) { + >-> +
+ + + +
+ <-< +}" + + let result = parser.parse(input) + should.equal( + result, + Ok(Block( + gleam: "import templates/notes/list as note +import schema/notes.{Note} + +pub type Params { + Params(notes: List(Note)) +} + +pub fn render(params: Params) { + ", + children: [ + GHP(children: [ + HtmlElement( + tag_name: "form", + attributes: [], + children: [ + HtmlElement( + tag_name: "textarea", + attributes: [Attribute(name: "required", value: "")], + children: [], + ), + HtmlElement( + tag_name: "button", + attributes: [Attribute(name: "type", value: "submit")], + children: [], + ), + ], + ), + ]), + Text("}"), + ], + )), + ) +}