Skip to content

Commit 314a691

Browse files
committed
Added and fixed tests for mj-html-attributes, mj-selector, mj-html-attribute.
Signed-off-by: Michael Pivonka <me@coded.ninja>
1 parent 345cbb6 commit 314a691

File tree

7 files changed

+43
-12
lines changed

7 files changed

+43
-12
lines changed

packages/mrml-core/src/mj_html_attribute/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod tests {
2727
);
2828
assert_eq!(
2929
serde_json::to_string(&elt).unwrap(),
30-
r#"{"type":"mj-html-attribute","attributes":{"name":".test"}}"#
30+
r#"{"type":"mj-html-attribute","attributes":{"name":".classname"},"children":"42"}"#
3131
);
3232
}
3333
}

packages/mrml-core/src/mj_html_attribute/parse.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ mod tests {
5858
use crate::mj_html_attribute::MjHtmlAttribute;
5959

6060
crate::should_parse!(
61-
normal,
61+
basic_with_children,
6262
MjHtmlAttribute,
63-
r#"<mj-html-attribute path=".class">42</mj-html-attribute>"#
63+
r#"<mj-html-attribute name="data-id">42</mj-html-attribute>"#
64+
);
65+
66+
crate::should_not_parse!(
67+
missing_attribute,
68+
MjHtmlAttribute,
69+
r#"<mj-html-attribute>42</mj-html-attribute>"#,
70+
r#"MissingAttribute { name: "name", origin: Root, position: Span { start: 1, end: 18 } }"#
6471
);
6572
}

packages/mrml-core/src/mj_html_attribute/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod tests {
2727
fn empty() {
2828
let item = crate::mj_html_attribute::MjHtmlAttribute::default();
2929
assert_eq!(
30-
r#"<mj-html-attribute name=".test"></mj-html-attribute>"#,
30+
r#"<mj-html-attribute name=""></mj-html-attribute>"#,
3131
item.print_dense().unwrap()
3232
)
3333
}

packages/mrml-core/src/mj_html_attributes/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ mod tests {
1616

1717
assert_eq!(
1818
serde_json::to_string(&elt).unwrap(),
19-
r#"{"children":[{}],"mj-selector":{"attributes":{},"name":"","type":""}}"#
19+
r#"{"type":"mj-html-attributes","children":[{"type":"mj-selector","attributes":{"path":".class"}}]}"#
2020
)
2121
}
2222

2323
#[test]
2424
fn deserialize() {
25-
let json = r#"{"type":"mj-html-attributes","children":[{"type":"mj-selector"}, {"type":"mj-html-attribute"}]}"#;
25+
let json = r#"{"type":"mj-html-attributes","children":[{"type":"mj-selector","attributes":{"path":".class"}},{"type":"mj-selector","attributes":{"path":"a[href]"}}]}"#;
2626
let res: MjHtmlAttributes = serde_json::from_str(json).unwrap();
2727
assert_eq!(res.children.len(), 2);
2828
let next = serde_json::to_string(&res).unwrap();

packages/mrml-core/src/mj_selector/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod tests {
3131

3232
assert_eq!(
3333
serde_json::to_string(&elt).unwrap(),
34-
r#"{"type":"mj-selector",attributes:{"name":"classname"}}"#,
34+
r#"{"type":"mj-selector","attributes":{"path":".test"}}"#,
3535
);
3636
}
3737
}

packages/mrml-core/src/mj_selector/parse.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use htmlparser::StrSpan;
22

3-
use super::{MjSelector, MjSelectorAttributes};
3+
#[cfg(feature = "async")]
4+
use super::MjSelector;
5+
use super::MjSelectorAttributes;
46
use crate::mj_html_attribute::MjHtmlAttribute;
57
#[cfg(feature = "async")]
68
use crate::prelude::parser::{AsyncMrmlParser, AsyncParseChildren, AsyncParseElement};
@@ -125,12 +127,13 @@ mod tests {
125127
crate::should_sync_parse!(
126128
parse_complete,
127129
MjSelector,
128-
r#"<mj-selector name="data-id" />"#
130+
r#"<mj-selector path="data-id" />"#
129131
);
132+
130133
crate::should_not_sync_parse!(
131134
should_have_name,
132135
MjSelector,
133136
r#"<mj-selector />"#,
134-
"MissingAttribute { name: \"name\", origin: Root, Position: Span { start: 1, end 9 } }"
137+
r#"MissingAttribute { name: "path", origin: Root, position: Span { start: 1, end: 12 } }"#
135138
);
136139
}

packages/mrml-core/src/mj_selector/print.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,32 @@ impl PrintableAttributes for super::MjSelectorAttributes {
88

99
#[cfg(test)]
1010
mod tests {
11+
use crate::mj_selector::{MjSelector, MjSelectorAttributes};
1112
use crate::prelude::print::Printable;
1213

14+
#[test]
15+
fn normal() {
16+
let item = MjSelector::new(
17+
MjSelectorAttributes {
18+
path: String::from(".cool_class"),
19+
},
20+
Vec::new(),
21+
);
22+
23+
assert_eq!(
24+
"<mj-selector path=\".cool_class\" />",
25+
item.print_dense().unwrap()
26+
);
27+
}
28+
1329
#[test]
1430
fn empty() {
15-
let item = crate::mj_html_attributes::MjHtmlAttributes::default();
16-
assert_eq!("<mj-selector />", item.print_dense().unwrap());
31+
let item = MjSelector::new(
32+
MjSelectorAttributes {
33+
path: String::from(""),
34+
},
35+
Vec::new(),
36+
);
37+
assert_eq!("<mj-selector path=\"\" />", item.print_dense().unwrap());
1738
}
1839
}

0 commit comments

Comments
 (0)