Skip to content

Commit

Permalink
Add a test for escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Jan 28, 2024
1 parent ebeb932 commit c56acee
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/node/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ fn escape(value: &str) -> String {

#[cfg(test)]
mod tests {
use super::{Element, Style};
use super::{Element, Rectangle, Style, Title};
use crate::node::{self, element, Node};

#[test]
Expand Down Expand Up @@ -423,11 +423,34 @@ mod tests {
element.append(Element::new("bar"));

assert_eq!(
element.to_string(),
"<foo c=\"green\" s=\"12.5 13\" x=\"-10\" y=\"10px\">\n\
<bar/>\n\
</foo>\
"
element.to_string().lines().collect::<Vec<_>>(),
&[
r#"<foo c="green" s="12.5 13" x="-10" y="10px">"#,
"<bar/>",
"</foo>",
],
);
}

#[test]
fn element_display_angles() {
let element = Rectangle::new()
.set("fill", "#FF780088")
.set("height", 10)
.set("width", 0.3088995)
.set("x", 328.0725)
.set("y", 120)
.add(Title::new().add(node::Text::new("widgets >=3.0.9, <3.1.dev0")));

assert_eq!(
element.to_string().lines().collect::<Vec<_>>(),
&[
r###"<rect fill="#FF780088" height="10" width="0.3088995" x="328.0725" y="120">"###,
"<title>",
"widgets &gt;=3.0.9, &lt;3.1.dev0",
"</title>",
"</rect>",
],
);
}

Expand All @@ -449,11 +472,8 @@ mod tests {
let element = Style::new("* { font-family: foo; }");

assert_eq!(
element.to_string(),
"<style>\n\
* { font-family: foo; }\n\
</style>\
"
element.to_string().lines().collect::<Vec<_>>(),
&["<style>", "* { font-family: foo; }", "</style>"],
);
}
}

0 comments on commit c56acee

Please sign in to comment.