Test Big5 encode from UTF-8.

This commit is contained in:
Henri Sivonen
2016-01-27 22:26:55 +02:00
parent f6a1afede0
commit eb31fe4830
2 changed files with 18 additions and 1 deletions
+17
View File
@@ -371,5 +371,22 @@ mod tests {
// prefer last
encode_big5_from_utf16(&[0x2550u16], b"\xF9\xF9");
// ASCII
encode_big5_from_utf8("\u{0061}\u{0062}", b"\x61\x62");
// Edge cases
encode_big5_from_utf8("\u{9EA6}\u{0061}", b"麦\x61");
encode_big5_from_utf8("\u{2626B}\u{0061}", b"𦉫\x61");
encode_big5_from_utf8("\u{3000}", b"\xA1\x40");
encode_big5_from_utf8("\u{20AC}", b"\xA3\xE1");
encode_big5_from_utf8("\u{4E00}", b"\xA4\x40");
encode_big5_from_utf8("\u{27607}", b"\xC8\xA4");
encode_big5_from_utf8("\u{FFE2}", b"\xC8\xCD");
encode_big5_from_utf8("\u{79D4}", b"\xFE\xFE");
// Not in index
encode_big5_from_utf8("\u{2603}\u{0061}", b"☃\x61");
// duplicate low bits
encode_big5_from_utf8("\u{203B5}", b"\xFD\x6A");
// prefer last
encode_big5_from_utf8("\u{2550}", b"\xF9\xF9");
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ pub fn decode_to_utf8(encoding: &'static Encoding, bytes: &[u8], expect: &str) {
pub fn encode_from_utf8(encoding: &'static Encoding, string: &str, expect: &[u8]) {
let mut encoder = encoding.new_encoder();
let mut dest: Vec<u8> = Vec::with_capacity(10 * string.len()); // 10 is replacement worst case
let mut dest: Vec<u8> = Vec::with_capacity(10 * (string.len() + 1)); // 10 is replacement worst case
let capacity = dest.capacity();
dest.resize(capacity, 0u8);
let (complete, read, written, _) = encoder.encode_from_utf8_with_replacement(string,