use origami_engine::comp;
#[test]
fn should_work_with_expr() {
let expr = "foo_bar";
let expr = &expr;
comp! {
baz =>
div {
@expr;
}
}
let html = baz!();
assert_eq!(html.0, "
foo_bar
");
}
#[test]
fn should_be_self_closing() {
comp! {
component =>
input;
}
let html = component!();
assert_eq!(html.0, "");
}
#[test]
fn should_order_attributes_correctly() {
comp! {
component =>
div hello="world" abc="def" hello abc="xyz" {}
}
let html = component!();
assert_eq!(html.0, "");
}
#[test]
fn should_order_attributes_correctly_when_using_placeholder() {
comp! {
component(attr) =>
div hello="world" abc="def" @attr; {}
}
let html = component!(attr {
hello abc="xyz"
});
assert_eq!(html.0, "");
}
#[test]
fn should_work_attribute_with_expression() {
comp! {
component(bar) =>
div hello="world" abc="def" foo=@bar; {}
}
let bar = "xyz";
let html = component!(bar {
@bar;
});
assert_eq!(
html.0,
""
);
}
#[test]
fn should_work_with_multiple_nested_components() {
comp! {
foo =>
div {
"foo_component"
}
}
comp! {
bar =>
div {
"bar_component"
call foo {}
call foo {}
}
}
comp! {
baz =>
div {
"baz_component"
call bar {}
}
}
let html = baz!();
assert_eq!(
html.0,
"
baz_component
bar_component
foo_component
foo_component
"
);
}
#[test]
fn should_work_with_conditionals() {
comp! {
foo(foo) =>
div {
if @foo; == "bar"; {
"bar_component"
} else if @foo; == "baz"; {
"baz_component"
} else {
"foo_component"
}
}
}
let html = foo!(foo { "bar" });
let html2 = foo!(foo { "baz" });
let html3 = foo!(foo { "foo" });
assert_eq!(html.0, "
bar_component
");
assert_eq!(html2.0, "
baz_component
");
assert_eq!(html3.0, "
foo_component
");
}
#[test]
fn should_work_with_loops() {
struct Points {
x: i32,
y: i32,
}
let points = [
Points { x: 1, y: 2 },
Points { x: 3, y: 4 },
Points { x: 5, y: 6 },
];
comp! {
foo(points) =>
div {
for point in @points;; {
div {
@point.x.to_string().as_str();
","
@point.y.to_string().as_str();
}
}
}
}
let html = foo!(points { points });
assert_eq!(
html.0,
"
1,2
3,4
5,6
"
);
}
#[test]
fn should_work_with_match_expression() {
comp! {
component(value) =>
div {
match @value;; {
"bar" => {
"bar_component"
},
"baz" => {
"baz_component"
},
_ => {
"foo_component"
},
}
}
}
let html = component!(value { "bar" });
let html2 = component!(value { "baz" });
let html3 = component!(value { "" });
assert_eq!(html.0, "