Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with single attribute not terminating #16

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser/attributes.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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("\""))
Expand Down
64 changes: 62 additions & 2 deletions test/parser_test.gleam
Original file line number Diff line number Diff line change
@@ -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) {
>->
<form>
<textarea required></textarea>

<button type=\"submit\">
</button>
</form>
<-<
}"

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("}"),
],
)),
)
}