Skip to content

Commit 22bb130

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 150763 b: refs/heads/try2 c: 58fc85d h: refs/heads/master i: 150761: 6367d18 150759: 7492551 v: v3
1 parent 05769e0 commit 22bb130

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e011939b1af554d2a29947feb66f01e27a2a1524
8+
refs/heads/try2: 58fc85db93bf6c73c4da957db8c6b8b025826e93
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/char.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use unicode::{derived_property, property, general_category, decompose, conversio
3232

3333
#[cfg(test)] use str::Str;
3434
#[cfg(test)] use strbuf::StrBuf;
35+
#[cfg(test)] use slice::ImmutableVector;
3536

3637
#[cfg(not(test))] use cmp::{Eq, Ord};
3738
#[cfg(not(test))] use default::Default;
@@ -814,3 +815,31 @@ fn test_to_str() {
814815
let s = 't'.to_str();
815816
assert_eq!(s, ~"t");
816817
}
818+
819+
#[test]
820+
fn test_encode_utf8() {
821+
fn check(input: char, expect: &[u8]) {
822+
let mut buf = [0u8, ..4];
823+
let n = input.encode_utf8(buf /* as mut slice! */);
824+
assert_eq!(buf.slice_to(n), expect);
825+
}
826+
827+
check('x', [0x78]);
828+
check('\u00e9', [0xc3, 0xa9]);
829+
check('\ua66e', [0xea, 0x99, 0xae]);
830+
check('\U0001f4a9', [0xf0, 0x9f, 0x92, 0xa9]);
831+
}
832+
833+
#[test]
834+
fn test_encode_utf16() {
835+
fn check(input: char, expect: &[u16]) {
836+
let mut buf = [0u16, ..2];
837+
let n = input.encode_utf16(buf /* as mut slice! */);
838+
assert_eq!(buf.slice_to(n), expect);
839+
}
840+
841+
check('x', [0x0078]);
842+
check('\u00e9', [0x00e9]);
843+
check('\ua66e', [0xa66e]);
844+
check('\U0001f4a9', [0xd83d, 0xdca9]);
845+
}

0 commit comments

Comments
 (0)