-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start writing some tests for decoding functionality
Fix up descriptions on some decoding functions
- Loading branch information
Showing
4 changed files
with
53 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0"?> | ||
<project name="project-name"> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#[cfg(feature = "encoding")] | ||
mod decode { | ||
use encoding_rs::{UTF_16BE, UTF_16LE, UTF_8}; | ||
use quick_xml::encoding::*; | ||
use std::borrow::Cow; | ||
|
||
static UTF16BE_TEXT_WITH_BOM: &[u8] = include_bytes!("./documents/utf16be.xml"); | ||
static UTF16LE_TEXT_WITH_BOM: &[u8] = include_bytes!("./documents/utf16le.xml"); | ||
static UTF8_TEXT_WITH_BOM: &[u8] = include_bytes!("./documents/utf8.xml"); | ||
|
||
static UTF8_TEXT: &str = r#"<?xml version="1.0"?> | ||
<project name="project-name"> | ||
</project> | ||
"#; | ||
|
||
#[test] | ||
fn test_removes_bom() { | ||
// No BOM | ||
assert_eq!( | ||
decode_with_bom_removal(UTF8_TEXT.as_bytes()).unwrap(), | ||
Cow::Borrowed(UTF8_TEXT) | ||
); | ||
// BOM | ||
assert_eq!( | ||
decode_with_bom_removal(UTF8_TEXT_WITH_BOM).unwrap(), | ||
Cow::Borrowed(UTF8_TEXT) | ||
); | ||
assert_eq!( | ||
decode_with_bom_removal(UTF16BE_TEXT_WITH_BOM).unwrap(), | ||
Cow::Borrowed(UTF8_TEXT).into_owned() | ||
); | ||
assert_eq!( | ||
decode_with_bom_removal(UTF16LE_TEXT_WITH_BOM).unwrap(), | ||
Cow::Borrowed(UTF8_TEXT).into_owned() | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_detect_encoding() { | ||
// No BOM | ||
assert_eq!(detect_encoding(UTF8_TEXT.as_bytes()), Some(UTF_8)); | ||
// BOM | ||
assert_eq!(detect_encoding(UTF8_TEXT_WITH_BOM), Some(UTF_8)); | ||
assert_eq!(detect_encoding(UTF16BE_TEXT_WITH_BOM), Some(UTF_16BE)); | ||
assert_eq!(detect_encoding(UTF16LE_TEXT_WITH_BOM), Some(UTF_16LE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters