-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c80fd9b
commit 42f8918
Showing
3 changed files
with
355 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import elements | ||
import gleam/list | ||
import gleeunit/should | ||
import html | ||
import render | ||
|
||
fn paragraph(text: String) { | ||
html.p([], [elements.escape_text(text)]) | ||
} | ||
|
||
fn meta() { | ||
html.meta([ | ||
elements.attr("name", "author"), | ||
elements.attr("content", "André da Silva"), | ||
]) | ||
} | ||
|
||
pub fn escape_test() { | ||
let tests = [ | ||
#( | ||
"<script>alert('hello world')</script>", | ||
"<script>alert('hello world')</script>", | ||
), | ||
#("\"hello\"", ""hello""), | ||
#("c://", "c://"), | ||
] | ||
|
||
list.map(tests, fn(t) { | ||
let #(input, expected) = t | ||
should.equal(render.escape(input), expected) | ||
}) | ||
} | ||
|
||
pub fn render_single_paragraph_test() { | ||
let input = paragraph("Hello") | ||
|
||
let expected = "<p>Hello</p>" | ||
|
||
render.element(input) | ||
|> should.equal(expected) | ||
} | ||
|
||
pub fn render_single_meta_test() { | ||
let input = meta() | ||
|
||
let expected = "<meta name=\"author\" content=\"André da Silva\" />" | ||
|
||
render.element(input) | ||
|> should.equal(expected) | ||
} | ||
|
||
pub fn render_multiple_paragraph_test() { | ||
let input = | ||
html.html([elements.attr("lang", "en")], [ | ||
paragraph("Hello"), | ||
paragraph("World"), | ||
]) | ||
|
||
let expected = | ||
"<!DOCTYPE html><html lang=\"en\"><p>Hello</p><p>World</p></html>" | ||
|
||
render.html(input) | ||
|> should.equal(expected) | ||
} | ||
|
||
pub fn render_nested_html_test() { | ||
let input = | ||
html.html([elements.attr("lang", "en")], [ | ||
html.head([], [html.title("Nested")]), | ||
html.body([], [ | ||
html.h1([], [elements.escape_text("Hello")]), | ||
html.div([elements.attr("class", "text-2xl")], [ | ||
html.p([], [elements.escape_text("What a nice library")]), | ||
]), | ||
]), | ||
]) | ||
|
||
let expected = | ||
"<!DOCTYPE html><html lang=\"en\"><head><title>Nested</title></head><body><h1>Hello</h1><div class=\"text-2xl\"><p>What a nice library</p></div></body></html>" | ||
|
||
render.html(input) | ||
|> should.equal(expected) | ||
} |
Oops, something went wrong.