mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-23 02:52:34 +03:00
Fix missing line in HTML output
This commit is contained in:
parent
c69ebea464
commit
2653401819
19
integration/tests_failed/assert_newline.html
Normal file
19
integration/tests_failed/assert_newline.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># Testing trailing whitespace</span>
|
||||||
|
<span class="line"></span><span class="comment"># Response '<p>Hello</p>\n\n'</span>
|
||||||
|
<span class="line"></span>
|
||||||
|
<span class="line"></span><span class="comment"># Testing with a raw string</span>
|
||||||
|
<span class="line"></span><span class="comment"># check exactly the whitespace</span>
|
||||||
|
<span class="line"></span><span class="comment"># It should produce an assert error</span>
|
||||||
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/error-assert-newline</span></span>
|
||||||
|
</span><span class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
|
||||||
|
<span class="raw"><span class="line">```<p>Hello</p></span>
|
||||||
|
<span class="line">```</span></span>
|
||||||
|
</span></span><span class="line"></span>
|
||||||
|
<span class="line"></span><span class="comment"># TODO</span>
|
||||||
|
<span class="line"></span><span class="comment"># Testing with XML</span>
|
||||||
|
<span class="line"></span><span class="comment"># Ignore trailing whitespace (semantic comparison)</span>
|
||||||
|
<span class="line"></span><span class="comment"># It should not produce an error</span>
|
||||||
|
<span class="line"></span><span class="comment"># GET http://localhost:8000/error-assert-newline</span>
|
||||||
|
<span class="line"></span><span class="comment"># HTTP/1.0 200</span>
|
||||||
|
<span class="line"></span><span class="comment"># <p>Hello</p></span>
|
||||||
|
</code></pre>
|
@ -861,40 +861,11 @@ impl Htmlable for RawString {
|
|||||||
fn to_html(&self) -> String {
|
fn to_html(&self) -> String {
|
||||||
let mut buffer = "".to_string();
|
let mut buffer = "".to_string();
|
||||||
buffer.push_str("<span class=\"raw\">");
|
buffer.push_str("<span class=\"raw\">");
|
||||||
buffer.push_str("<span class=\"line\">```");
|
let mut s = "```".to_string();
|
||||||
|
s.push_str(self.newline.value.as_str());
|
||||||
if !self.newline.value.as_str().is_empty() {
|
s.push_str(self.value.to_string().as_str());
|
||||||
buffer.push_str(
|
s.push_str("```");
|
||||||
format!(
|
buffer.push_str(multilines(s).as_str());
|
||||||
"</span>{}<span class=\"line\">",
|
|
||||||
self.newline.value.as_str()
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut lines: Vec<String> = regex::Regex::new(r"\n|\r\n")
|
|
||||||
.unwrap()
|
|
||||||
.split(self.value.to_string().trim())
|
|
||||||
.map(|l| xml_escape(l.to_string()))
|
|
||||||
.filter(|l| !l.is_empty())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if lines.is_empty() {
|
|
||||||
buffer.push_str("```</span>");
|
|
||||||
} else if lines.len() == 1 {
|
|
||||||
buffer.push_str(encode_html(lines.get(0).unwrap().to_string()).as_str());
|
|
||||||
buffer.push_str("```</span>");
|
|
||||||
} else {
|
|
||||||
buffer.push_str(encode_html(lines.remove(0)).as_str());
|
|
||||||
buffer.push_str("</span>\n");
|
|
||||||
for line in lines {
|
|
||||||
buffer.push_str("<span class=\"line\">");
|
|
||||||
buffer.push_str(encode_html(line).as_str());
|
|
||||||
buffer.push_str("</span>\n");
|
|
||||||
}
|
|
||||||
buffer.push_str("<span class=\"line\">```</span>");
|
|
||||||
}
|
|
||||||
buffer.push_str("</span>");
|
buffer.push_str("</span>");
|
||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
@ -1167,6 +1138,27 @@ mod tests {
|
|||||||
raw_string.to_html(),
|
raw_string.to_html(),
|
||||||
"<span class=\"raw\"><span class=\"line\">```</span>\n<span class=\"line\">line1</span>\n<span class=\"line\">line2</span>\n<span class=\"line\">```</span></span>".to_string()
|
"<span class=\"raw\"><span class=\"line\">```</span>\n<span class=\"line\">line1</span>\n<span class=\"line\">line2</span>\n<span class=\"line\">```</span></span>".to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ```Hello
|
||||||
|
// ```
|
||||||
|
let raw_string = RawString {
|
||||||
|
newline: Whitespace {
|
||||||
|
value: "".to_string(),
|
||||||
|
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||||
|
},
|
||||||
|
value: Template {
|
||||||
|
quotes: false,
|
||||||
|
elements: vec![TemplateElement::String {
|
||||||
|
value: "Hello\n".to_string(),
|
||||||
|
encoded: "unused".to_string(),
|
||||||
|
}],
|
||||||
|
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
raw_string.to_html(),
|
||||||
|
"<span class=\"raw\"><span class=\"line\">```Hello</span>\n<span class=\"line\">```</span></span>".to_string()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1179,6 +1171,11 @@ mod tests {
|
|||||||
multilines("<?xml version=\"1.0\"?>\n<drink>café</drink>".to_string()),
|
multilines("<?xml version=\"1.0\"?>\n<drink>café</drink>".to_string()),
|
||||||
"<span class=\"line\"><?xml version=\"1.0\"?></span>\n<span class=\"line\"><drink>café</drink></span>"
|
"<span class=\"line\"><?xml version=\"1.0\"?></span>\n<span class=\"line\"><drink>café</drink></span>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
multilines("Hello\n".to_string()),
|
||||||
|
"<span class=\"line\">Hello</span>\n<span class=\"line\"></span>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user