Revert readline optimization and add test

This commit is contained in:
Brian Anderson 2013-01-28 19:32:02 -08:00
parent 3a6849f36b
commit a72aeef9f7
1 changed files with 11 additions and 3 deletions

View File

@ -185,13 +185,13 @@ impl<T: Reader> T : ReaderUtil {
}
fn read_line(&self) -> ~str {
let mut line = ~"";
let mut bytes = ~[];
loop {
let ch = self.read_byte();
if ch == -1 || ch == 10 { break; }
str::push_char(&mut line, ch as char);
bytes.push(ch as u8);
}
line
str::from_bytes(bytes)
}
fn read_chars(&self, n: uint) -> ~[char] {
@ -1221,6 +1221,14 @@ mod tests {
}
}
#[test]
fn test_read_line_utf8() {
do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| {
let line = inp.read_line();
assert line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
}
}
#[test]
fn test_readchars_wide() {
let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";