mirror of
https://github.com/MillironX/Kelpie.jl.git
synced 2024-11-14 21:43:10 +00:00
commit
b6a44e33f8
5 changed files with 242 additions and 3 deletions
|
@ -1,3 +1,5 @@
|
||||||
no-inline-html:
|
no-inline-html:
|
||||||
allowed_elements:
|
allowed_elements:
|
||||||
- kbd
|
- kbd
|
||||||
|
no-duplicate-header:
|
||||||
|
allow_different_nesting: true
|
||||||
|
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Way more unit tests ([#4](https://github.com/MillironX/Kelpie.jl/pull/4))
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Arrays of content replaced with argument splatting ([#2](https://github.com/MillironX/Kelpie.jl/pull/2))
|
- Arrays of content replaced with argument splatting ([#2](https://github.com/MillironX/Kelpie.jl/pull/2))
|
||||||
|
|
|
@ -7,13 +7,14 @@ version = "0.1.0"
|
||||||
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
|
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
|
||||||
|
|
||||||
[compat]
|
[compat]
|
||||||
julia = "1.6"
|
|
||||||
EzXML = "1.1"
|
EzXML = "1.1"
|
||||||
|
julia = "1.6"
|
||||||
|
|
||||||
[extras]
|
[extras]
|
||||||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
|
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
|
||||||
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
|
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
|
||||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
|
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
|
||||||
|
|
||||||
[targets]
|
[targets]
|
||||||
test = ["Test", "Documenter", "EzXML"]
|
test = ["Test", "Documenter", "EzXML", "Suppressor"]
|
||||||
|
|
|
@ -103,7 +103,7 @@ specified by `kwargs`.
|
||||||
|
|
||||||
# Example
|
# Example
|
||||||
|
|
||||||
```
|
```jldoctest
|
||||||
julia> import EzXML: prettyprint
|
julia> import EzXML: prettyprint
|
||||||
|
|
||||||
julia> prettyprint(html_element("img"; src="https://millironx.com/images/charolette.jpg"))
|
julia> prettyprint(html_element("img"; src="https://millironx.com/images/charolette.jpg"))
|
||||||
|
|
232
test/runtests.jl
232
test/runtests.jl
|
@ -1,11 +1,243 @@
|
||||||
using Documenter
|
using Documenter
|
||||||
|
using EzXML: AttributeNode, ElementNode, HTMLDocumentNode, TextNode, link!, prettyprint
|
||||||
using Kelpie
|
using Kelpie
|
||||||
|
using Suppressor
|
||||||
using Test
|
using Test
|
||||||
|
|
||||||
|
# Set up doctests
|
||||||
DocMeta.setdocmeta!(Kelpie, :DocTestSetup, :(using Kelpie); recursive=true)
|
DocMeta.setdocmeta!(Kelpie, :DocTestSetup, :(using Kelpie); recursive=true)
|
||||||
|
|
||||||
|
prettystring(xml) = @capture_out prettyprint(xml)
|
||||||
|
|
||||||
|
# Set up the Bootstrap 5.1.3 starter template in EzXML nodes
|
||||||
|
function bootstrap_starter()
|
||||||
|
# Create the nodes
|
||||||
|
doc_node = HTMLDocumentNode("about:legacy-compat", nothing)
|
||||||
|
html_node = ElementNode("html")
|
||||||
|
head_node = ElementNode("head")
|
||||||
|
meta_charset_node = ElementNode("meta")
|
||||||
|
meta_viewport_node = ElementNode("meta")
|
||||||
|
css_link_node = ElementNode("link")
|
||||||
|
title_node = ElementNode("title")
|
||||||
|
body_node = ElementNode("body")
|
||||||
|
h1_node = ElementNode("h1")
|
||||||
|
script_node = ElementNode("script")
|
||||||
|
|
||||||
|
# Add attributes
|
||||||
|
link!(html_node, AttributeNode("lang", "en"))
|
||||||
|
link!(meta_charset_node, AttributeNode("charset", "utf-8"))
|
||||||
|
link!(meta_viewport_node, AttributeNode("name", "viewport"))
|
||||||
|
link!(
|
||||||
|
meta_viewport_node, AttributeNode("content", "width=device-width, initial-scale=1")
|
||||||
|
)
|
||||||
|
link!(
|
||||||
|
css_link_node,
|
||||||
|
AttributeNode(
|
||||||
|
"href",
|
||||||
|
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(css_link_node, AttributeNode("rel", "stylesheet"))
|
||||||
|
link!(
|
||||||
|
css_link_node,
|
||||||
|
AttributeNode(
|
||||||
|
"integrity",
|
||||||
|
"sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(css_link_node, AttributeNode("crossorigin", "anonymous"))
|
||||||
|
link!(
|
||||||
|
script_node,
|
||||||
|
AttributeNode(
|
||||||
|
"src",
|
||||||
|
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(
|
||||||
|
script_node,
|
||||||
|
AttributeNode(
|
||||||
|
"integrity",
|
||||||
|
"sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(script_node, AttributeNode("crossorigin", "anonymous"))
|
||||||
|
|
||||||
|
# Add content
|
||||||
|
link!(title_node, TextNode("Hello, world!"))
|
||||||
|
link!(h1_node, TextNode("Hello, world!"))
|
||||||
|
link!(script_node, TextNode(""))
|
||||||
|
|
||||||
|
# Link the tree together
|
||||||
|
link!(head_node, meta_charset_node)
|
||||||
|
link!(head_node, meta_viewport_node)
|
||||||
|
link!(head_node, css_link_node)
|
||||||
|
link!(head_node, title_node)
|
||||||
|
link!(body_node, h1_node)
|
||||||
|
link!(body_node, script_node)
|
||||||
|
link!(html_node, head_node)
|
||||||
|
link!(html_node, body_node)
|
||||||
|
link!(doc_node, html_node)
|
||||||
|
|
||||||
|
return prettystring(doc_node)
|
||||||
|
end #function
|
||||||
|
|
||||||
|
# Set up the Zurb Foundation 6.7.4 starter template in EzXML nodes
|
||||||
|
function foundation_template()
|
||||||
|
# Create the nodes
|
||||||
|
doc_node = HTMLDocumentNode("about:legacy-compat", nothing)
|
||||||
|
html_node = ElementNode("html")
|
||||||
|
head_node = ElementNode("head")
|
||||||
|
meta_charset_node = ElementNode("meta")
|
||||||
|
meta_http_equiv_node = ElementNode("meta")
|
||||||
|
meta_viewport_node = ElementNode("meta")
|
||||||
|
title_node = ElementNode("title")
|
||||||
|
css_link_node = ElementNode("link")
|
||||||
|
body_node = ElementNode("body")
|
||||||
|
h1_node = ElementNode("h1")
|
||||||
|
script_jquery_node = ElementNode("script")
|
||||||
|
script_whatinput_node = ElementNode("script")
|
||||||
|
script_foundation_node = ElementNode("script")
|
||||||
|
script_launch_node = ElementNode("script")
|
||||||
|
|
||||||
|
# Add attributes
|
||||||
|
link!(html_node, AttributeNode("class", "no-js"))
|
||||||
|
link!(html_node, AttributeNode("lang", "en"))
|
||||||
|
link!(meta_charset_node, AttributeNode("charset", "utf-8"))
|
||||||
|
link!(meta_http_equiv_node, AttributeNode("http-equiv", "x-ua-compatible"))
|
||||||
|
link!(meta_http_equiv_node, AttributeNode("content", "ie=edge"))
|
||||||
|
link!(meta_viewport_node, AttributeNode("name", "viewport"))
|
||||||
|
link!(
|
||||||
|
meta_viewport_node,
|
||||||
|
AttributeNode("content", "width=device-width, initial-scale=1.0"),
|
||||||
|
)
|
||||||
|
link!(css_link_node, AttributeNode("rel", "stylesheet"))
|
||||||
|
link!(
|
||||||
|
css_link_node,
|
||||||
|
AttributeNode(
|
||||||
|
"href",
|
||||||
|
"https://cdn.jsdelivr.net/npm/foundation-sites@6.7.4/dist/css/foundation.min.css",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(css_link_node, AttributeNode("crossorigin", "anonymous"))
|
||||||
|
link!(
|
||||||
|
script_jquery_node,
|
||||||
|
AttributeNode(
|
||||||
|
"src", "https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(script_jquery_node, AttributeNode("crossorigin", "anonymous"))
|
||||||
|
link!(
|
||||||
|
script_whatinput_node,
|
||||||
|
AttributeNode(
|
||||||
|
"src", "https://cdn.jsdelivr.net/npm/what-input@5.2.10/dist/what-input.min.js"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(script_whatinput_node, AttributeNode("crossorigin", "anonymous"))
|
||||||
|
link!(
|
||||||
|
script_foundation_node,
|
||||||
|
AttributeNode(
|
||||||
|
"src",
|
||||||
|
"https://cdn.jsdelivr.net/npm/foundation-sites@6.7.4/dist/js/foundation.min.js",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
link!(script_foundation_node, AttributeNode("crossorigin", "anonymous"))
|
||||||
|
|
||||||
|
# Add content
|
||||||
|
link!(title_node, TextNode("Foundation Starter Template"))
|
||||||
|
link!(h1_node, TextNode("Hello, world!"))
|
||||||
|
link!(script_jquery_node, TextNode(""))
|
||||||
|
link!(script_whatinput_node, TextNode(""))
|
||||||
|
link!(script_foundation_node, TextNode(""))
|
||||||
|
link!(script_launch_node, TextNode("\$(document).foundation();"))
|
||||||
|
|
||||||
|
# Link the tree together
|
||||||
|
link!(head_node, meta_charset_node)
|
||||||
|
link!(head_node, meta_http_equiv_node)
|
||||||
|
link!(head_node, meta_viewport_node)
|
||||||
|
link!(head_node, title_node)
|
||||||
|
link!(head_node, css_link_node)
|
||||||
|
link!(body_node, h1_node)
|
||||||
|
link!(body_node, script_jquery_node)
|
||||||
|
link!(body_node, script_whatinput_node)
|
||||||
|
link!(body_node, script_foundation_node)
|
||||||
|
link!(body_node, script_launch_node)
|
||||||
|
link!(html_node, head_node)
|
||||||
|
link!(html_node, body_node)
|
||||||
|
link!(doc_node, html_node)
|
||||||
|
|
||||||
|
return prettystring(doc_node)
|
||||||
|
end #function
|
||||||
|
|
||||||
@testset "Kelpie.jl" begin
|
@testset "Kelpie.jl" begin
|
||||||
@testset "Doctests" begin
|
@testset "Doctests" begin
|
||||||
doctest(Kelpie)
|
doctest(Kelpie)
|
||||||
end #testset
|
end #testset
|
||||||
|
|
||||||
|
@testset "Frameworks" begin
|
||||||
|
bootstrap_kelpie = html(
|
||||||
|
head(
|
||||||
|
meta(; charset="utf-8"),
|
||||||
|
meta(; name="viewport", content="width=device-width, initial-scale=1"),
|
||||||
|
link(;
|
||||||
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css",
|
||||||
|
rel="stylesheet",
|
||||||
|
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3",
|
||||||
|
crossorigin="anonymous",
|
||||||
|
),
|
||||||
|
title("Hello, world!"),
|
||||||
|
),
|
||||||
|
body(
|
||||||
|
h1("Hello, world!"),
|
||||||
|
script(
|
||||||
|
"";
|
||||||
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js",
|
||||||
|
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p",
|
||||||
|
crossorigin="anonymous",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
lang="en",
|
||||||
|
)
|
||||||
|
foundation_kelpie = html(
|
||||||
|
head(
|
||||||
|
meta(; charset="utf-8"),
|
||||||
|
meta(; http_equiv="x-ua-compatible", content="ie=edge"),
|
||||||
|
meta(; name="viewport", content="width=device-width, initial-scale=1.0"),
|
||||||
|
title("Foundation Starter Template"),
|
||||||
|
link(;
|
||||||
|
rel="stylesheet",
|
||||||
|
href="https://cdn.jsdelivr.net/npm/foundation-sites@6.7.4/dist/css/foundation.min.css",
|
||||||
|
crossorigin="anonymous",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body(
|
||||||
|
h1("Hello, world!"),
|
||||||
|
script(
|
||||||
|
"";
|
||||||
|
src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js",
|
||||||
|
crossorigin="anonymous",
|
||||||
|
),
|
||||||
|
script(
|
||||||
|
"";
|
||||||
|
src="https://cdn.jsdelivr.net/npm/what-input@5.2.10/dist/what-input.min.js",
|
||||||
|
crossorigin="anonymous",
|
||||||
|
),
|
||||||
|
script(
|
||||||
|
"";
|
||||||
|
src="https://cdn.jsdelivr.net/npm/foundation-sites@6.7.4/dist/js/foundation.min.js",
|
||||||
|
crossorigin="anonymous",
|
||||||
|
),
|
||||||
|
script("\$(document).foundation();"),
|
||||||
|
);
|
||||||
|
class="no-js",
|
||||||
|
lang="en",
|
||||||
|
)
|
||||||
|
|
||||||
|
@test prettystring(bootstrap_kelpie) == bootstrap_starter()
|
||||||
|
@test prettystring(foundation_kelpie) == foundation_template()
|
||||||
|
end #testset
|
||||||
|
|
||||||
|
@testset "Behaviors" begin
|
||||||
|
# Test that attributes with underscores become attributes with dashes
|
||||||
|
@test occursin("<i data-tooltip=\"foo\"/>", prettystring(i(; data_tooltip="foo")))
|
||||||
|
end #testset
|
||||||
end #testset
|
end #testset
|
||||||
|
|
Loading…
Reference in a new issue