2016-07-31 21:34:46 +12:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(maud_macros)]
|
|
|
|
|
|
|
|
extern crate maud;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn literals() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!("du\tcks" "-23" "3.14\n" "geese").into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "du\tcks-233.14\ngeese");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn escaping() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!("<flim&flam>").into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "<flim&flam>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn semicolons() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html! {
|
2016-07-31 21:34:46 +12:00
|
|
|
"one";
|
|
|
|
"two";
|
|
|
|
"three";
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
"four";
|
2016-09-23 19:22:22 +12:00
|
|
|
}.into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "onetwothreefour");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn blocks() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html! {
|
2016-07-31 21:34:46 +12:00
|
|
|
"hello"
|
|
|
|
{
|
|
|
|
" ducks" " geese"
|
|
|
|
}
|
|
|
|
" swans"
|
2016-09-23 19:22:22 +12:00
|
|
|
}.into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "hello ducks geese swans");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_elements() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p { b { "pickle" } "barrel" i { "kumquat" } }).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "<p><b>pickle</b>barrel<i>kumquat</i></p>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nesting_elements() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(html body div p sup "butts").into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "<html><body><div><p><sup>butts</sup></p></div></body></html>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_elements() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!("pinkie" br/ "pie").into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "pinkie<br>pie");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_attributes() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html! {
|
2016-07-31 21:34:46 +12:00
|
|
|
link rel="stylesheet" href="styles.css"/
|
|
|
|
section id="midriff" {
|
|
|
|
p class="hotpink" "Hello!"
|
|
|
|
}
|
2016-09-23 19:22:22 +12:00
|
|
|
}.into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, concat!(
|
|
|
|
r#"<link rel="stylesheet" href="styles.css">"#,
|
|
|
|
r#"<section id="midriff"><p class="hotpink">Hello!</p></section>"#));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_attributes() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(div readonly? input type="checkbox" checked? /).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, r#"<div readonly><input type="checkbox" checked></div>"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn colons_in_names() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(pon-pon:controls-alpha a on:click="yay()" "Yay!").into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, concat!(
|
|
|
|
r#"<pon-pon:controls-alpha>"#,
|
|
|
|
r#"<a on:click="yay()">Yay!</a>"#,
|
|
|
|
r#"</pon-pon:controls-alpha>"#));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hyphens_in_element_names() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(custom-element {}).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "<custom-element></custom-element>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hyphens_in_attribute_names() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(this sentence-is="false" of-course? {}).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, r#"<this sentence-is="false" of-course></this>"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn class_shorthand() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p { "Hi, " span.name { "Lyra" } "!" }).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, r#"<p>Hi, <span class="name">Lyra</span>!</p>"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn class_shorthand_with_space() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p { "Hi, " span .name { "Lyra" } "!" }).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, r#"<p>Hi, <span class="name">Lyra</span>!</p>"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn classes_shorthand() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p { "Hi, " span.name.here { "Lyra" } "!" }).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, r#"<p>Hi, <span class="name here">Lyra</span>!</p>"#);
|
|
|
|
}
|
|
|
|
|
2016-08-07 20:39:31 +12:00
|
|
|
#[test]
|
|
|
|
fn hyphens_in_class_names() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p.rocks-these.are--my--rocks "yes").into_string();
|
2016-08-07 20:39:31 +12:00
|
|
|
assert_eq!(s, r#"<p class="rocks-these are--my--rocks">yes</p>"#);
|
|
|
|
}
|
|
|
|
|
2016-07-31 21:34:46 +12:00
|
|
|
#[test]
|
|
|
|
fn ids_shorthand() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p { "Hi, " span#thing { "Lyra" } "!" }).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, r#"<p>Hi, <span id="thing">Lyra</span>!</p>"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn classes_attrs_ids_mixed_up() {
|
2016-09-23 19:22:22 +12:00
|
|
|
let s = html!(p { "Hi, " span.name.here lang="en" #thing { "Lyra" } "!" }).into_string();
|
2016-07-31 21:34:46 +12:00
|
|
|
assert_eq!(s, "<p>Hi, <span lang=\"en\" class=\"name here\" id=\"thing\">Lyra</span>!</p>");
|
|
|
|
}
|