Skip to content

Commit e03bac7

Browse files
Mingundralley
authored andcommitted
Remove unnecessary conversions to owned type in assertions
assert_eq relies on `PartialEq::eq` that returns `true` when compare owned and borrowed data, so no need to create owned versions of strings just to compare
1 parent 9921bfb commit e03bac7

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

src/events/mod.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,35 +360,28 @@ impl<'a> BytesDecl<'a> {
360360
/// # Examples
361361
///
362362
/// ```
363-
/// use std::borrow::Cow;
364363
/// use quick_xml::Error;
365364
/// use quick_xml::events::{BytesDecl, BytesStart};
366365
///
367366
/// // <?xml version='1.1'?>
368367
/// let decl = BytesDecl::from_start(BytesStart::from_content(" version='1.1'", 0));
369-
/// assert_eq!(
370-
/// decl.version().unwrap(),
371-
/// Cow::Borrowed(b"1.1".as_ref())
372-
/// );
368+
/// assert_eq!(decl.version().unwrap(), b"1.1".as_ref());
373369
///
374370
/// // <?xml version='1.0' version='1.1'?>
375371
/// let decl = BytesDecl::from_start(BytesStart::from_content(" version='1.0' version='1.1'", 0));
376-
/// assert_eq!(
377-
/// decl.version().unwrap(),
378-
/// Cow::Borrowed(b"1.0".as_ref())
379-
/// );
372+
/// assert_eq!(decl.version().unwrap(), b"1.0".as_ref());
380373
///
381374
/// // <?xml encoding='utf-8'?>
382375
/// let decl = BytesDecl::from_start(BytesStart::from_content(" encoding='utf-8'", 0));
383376
/// match decl.version() {
384-
/// Err(Error::XmlDeclWithoutVersion(Some(key))) => assert_eq!(key, "encoding".to_string()),
377+
/// Err(Error::XmlDeclWithoutVersion(Some(key))) => assert_eq!(key, "encoding"),
385378
/// _ => assert!(false),
386379
/// }
387380
///
388381
/// // <?xml encoding='utf-8' version='1.1'?>
389382
/// let decl = BytesDecl::from_start(BytesStart::from_content(" encoding='utf-8' version='1.1'", 0));
390383
/// match decl.version() {
391-
/// Err(Error::XmlDeclWithoutVersion(Some(key))) => assert_eq!(key, "encoding".to_string()),
384+
/// Err(Error::XmlDeclWithoutVersion(Some(key))) => assert_eq!(key, "encoding"),
392385
/// _ => assert!(false),
393386
/// }
394387
///

src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod tests {
149149
#[test]
150150
fn write_byte_string0() {
151151
let bytes = ByteBuf(vec![10, 32, 32, 32, 32, 32, 32, 32, 32]);
152-
assert_eq!(format!("{:?}", bytes), "\"0xA \"".to_owned());
152+
assert_eq!(format!("{:?}", bytes), "\"0xA \"");
153153
}
154154

155155
#[test]
@@ -160,7 +160,7 @@ mod tests {
160160
]);
161161
assert_eq!(
162162
format!("{:?}", bytes),
163-
r##""http://www.w3.org/2002/07/owl#""##.to_owned()
163+
r##""http://www.w3.org/2002/07/owl#""##
164164
);
165165
}
166166

@@ -169,6 +169,6 @@ mod tests {
169169
let bytes = ByteBuf(vec![
170170
67, 108, 97, 115, 115, 32, 73, 82, 73, 61, 34, 35, 66, 34,
171171
]);
172-
assert_eq!(format!("{:?}", bytes), r##""Class IRI=\"#B\"""##.to_owned());
172+
assert_eq!(format!("{:?}", bytes), r##""Class IRI=\"#B\"""##);
173173
}
174174
}

tests/unit_tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn test_new_xml_decl_full() {
332332
let result = writer.into_inner();
333333
assert_eq!(
334334
String::from_utf8(result).expect("utf-8 output"),
335-
"<?xml version=\"1.2\" encoding=\"utf-X\" standalone=\"yo\"?>".to_owned(),
335+
"<?xml version=\"1.2\" encoding=\"utf-X\" standalone=\"yo\"?>",
336336
"writer output (LHS)"
337337
);
338338
}
@@ -347,7 +347,7 @@ fn test_new_xml_decl_standalone() {
347347
let result = writer.into_inner();
348348
assert_eq!(
349349
String::from_utf8(result).expect("utf-8 output"),
350-
"<?xml version=\"1.2\" standalone=\"yo\"?>".to_owned(),
350+
"<?xml version=\"1.2\" standalone=\"yo\"?>",
351351
"writer output (LHS)"
352352
);
353353
}
@@ -362,7 +362,7 @@ fn test_new_xml_decl_encoding() {
362362
let result = writer.into_inner();
363363
assert_eq!(
364364
String::from_utf8(result).expect("utf-8 output"),
365-
"<?xml version=\"1.2\" encoding=\"utf-X\"?>".to_owned(),
365+
"<?xml version=\"1.2\" encoding=\"utf-X\"?>",
366366
"writer output (LHS)"
367367
);
368368
}
@@ -377,7 +377,7 @@ fn test_new_xml_decl_version() {
377377
let result = writer.into_inner();
378378
assert_eq!(
379379
String::from_utf8(result).expect("utf-8 output"),
380-
"<?xml version=\"1.2\"?>".to_owned(),
380+
"<?xml version=\"1.2\"?>",
381381
"writer output (LHS)"
382382
);
383383
}
@@ -395,7 +395,7 @@ fn test_new_xml_decl_empty() {
395395
let result = writer.into_inner();
396396
assert_eq!(
397397
String::from_utf8(result).expect("utf-8 output"),
398-
"<?xml version=\"\" encoding=\"\" standalone=\"\"?>".to_owned(),
398+
"<?xml version=\"\" encoding=\"\" standalone=\"\"?>",
399399
"writer output (LHS)"
400400
);
401401
}
@@ -533,7 +533,7 @@ fn test_read_write_roundtrip_results_in_identity() -> Result<()> {
533533
}
534534

535535
let result = writer.into_inner().into_inner();
536-
assert_eq!(result, input.as_bytes());
536+
assert_eq!(String::from_utf8(result).unwrap(), input);
537537
Ok(())
538538
}
539539

@@ -559,7 +559,7 @@ fn test_read_write_roundtrip() -> Result<()> {
559559
}
560560

561561
let result = writer.into_inner().into_inner();
562-
assert_eq!(String::from_utf8(result).unwrap(), input.to_string());
562+
assert_eq!(String::from_utf8(result).unwrap(), input);
563563
Ok(())
564564
}
565565

@@ -589,7 +589,7 @@ fn test_read_write_roundtrip_escape_text() -> Result<()> {
589589
}
590590

591591
let result = writer.into_inner().into_inner();
592-
assert_eq!(String::from_utf8(result).unwrap(), input.to_string());
592+
assert_eq!(String::from_utf8(result).unwrap(), input);
593593
Ok(())
594594
}
595595

0 commit comments

Comments
 (0)