mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Revert readline optimization and add test
This commit is contained in:
parent
3a6849f36b
commit
a72aeef9f7
@ -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生锈的汤匙切肉汤";
|
||||
|
Loading…
Reference in New Issue
Block a user