about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2014-11-17 20:11:54 +0000
committerSimon Sapin <simon.sapin@exyr.org>2014-11-20 14:05:28 +0000
commitdff48a99d6bf9d2c4828f187bfa2c9ba382fe791 (patch)
tree72b81065048982415c7bb93747b89dbaed292f04 /src/libcoretest
parent1d81776209cfa2b5cb1825bdbf3965a7a7f0440a (diff)
downloadrust-dff48a99d6bf9d2c4828f187bfa2c9ba382fe791.tar.gz
rust-dff48a99d6bf9d2c4828f187bfa2c9ba382fe791.zip
Add Utf16Encoder. Generalize Utf16CodeUnits for any Iterator<char>.
This allows encoding to UTF-16 something that is not in UTF-8, e.g. a
`[char]` UTF-32 string.

This might help with https://github.com/servo/servo/issues/4023
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/str.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libcoretest/str.rs b/src/libcoretest/str.rs
index 5f44fd807cc..9574aeb3762 100644
--- a/src/libcoretest/str.rs
+++ b/src/libcoretest/str.rs
@@ -114,3 +114,10 @@ fn test_rev_split_char_iterator_no_trailing() {
     split.reverse();
     assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb"]);
 }
+
+#[test]
+fn test_utf16_code_units() {
+    use core::str::Utf16Encoder;
+    assert_eq!(Utf16Encoder::new(vec!['é', '\U0001F4A9'].into_iter()).collect::<Vec<u16>>(),
+               vec![0xE9, 0xD83D, 0xDCA9])
+}