From dff48a99d6bf9d2c4828f187bfa2c9ba382fe791 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 17 Nov 2014 20:11:54 +0000 Subject: Add Utf16Encoder. Generalize Utf16CodeUnits for any Iterator. 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 --- src/libcoretest/str.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libcoretest') 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![0xE9, 0xD83D, 0xDCA9]) +} -- cgit 1.4.1-3-g733a5