Skip to content

Commit 17cf1f4

Browse files
committed
properly parse xml with no replacements
added a test too
1 parent 5a9e6fd commit 17cf1f4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cpp-linter/src/clang_tools/clang_format.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use crate::{
1515
common_fs::{get_line_count_from_offset, FileObj},
1616
};
1717

18-
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
18+
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)]
1919
pub struct FormatAdvice {
2020
/// A list of [`Replacement`]s that clang-tidy wants to make.
21-
#[serde(rename(deserialize = "replacement"))]
21+
#[serde(rename(deserialize = "replacement"), default)]
2222
pub replacements: Vec<Replacement>,
2323

2424
pub patched: Option<Vec<u8>>,
@@ -198,6 +198,22 @@ mod tests {
198198
assert!(result.is_err());
199199
}
200200

201+
#[test]
202+
fn parse_xml_no_replacements() {
203+
let xml_raw = r#"<?xml version='1.0'?>
204+
<replacements xml:space='preserve' incomplete_format='false'>
205+
</replacements>"#
206+
.as_bytes()
207+
.to_vec();
208+
let expected = FormatAdvice {
209+
replacements: vec![],
210+
patched: None,
211+
};
212+
let xml = String::from_utf8(xml_raw).unwrap();
213+
let document = quick_xml::de::from_str::<FormatAdvice>(&xml).unwrap();
214+
assert_eq!(expected, document);
215+
}
216+
201217
#[test]
202218
fn parse_xml() {
203219
let xml_raw = r#"<?xml version='1.0'?>

0 commit comments

Comments
 (0)