Skip to content

Commit

Permalink
Complete the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ticki committed Dec 22, 2015
1 parent b2745f3 commit efbd47f
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,21 +588,43 @@ impl Iterator for EscapeDefault {
fn ed_iterator_specializations() {
use super::EscapeDefault;

/// Check counting
// Check counting
assert_eq!('\n'.escape_default().count(), 2);
assert_eq!('c'.escape_default().count(), 1);
assert_eq!(' '.escape_default().count(), 1);
assert_eq!('\\'.escape_default().count(), 2);
assert_eq!('\''.escape_default().count(), 2);

// Check nth

// Check that OoB is handled correctly
assert_eq!('\n'.escape_default().nth(2), None);
assert_eq!('c'.escape_default().nth(1), None);
assert_eq!(' '.escape_default().nth(1), None);
assert_eq!('\\'.escape_default().nth(2), None);
assert_eq!('\''.escape_default().nth(2), None);

// Check the first char
assert_eq!('\n'.escape_default().nth(0), Some('\\'));
assert_eq!('c'.escape_default().nth(0), Some('c'));
assert_eq!(' '.escape_default().nth(0), Some(' '));
assert_eq!('\\'.escape_default().nth(0), Some('\\'));
assert_eq!('\''.escape_default().nth(0), Some('\\'));

// Check the second char
assert_eq!('\n'.escape_default().nth(1), Some('n'));
assert_eq!('\\'.escape_default().nth(1), Some('\\'));
assert_eq!('\''.escape_default().nth(1), Some('\''));
}


impl EscapeDefault {
fn get_offset(&self) -> Option<usize> {
match self.state {
EscapeDefaultState::Backslash(c) => Some(0),
EscapeDefaultState::Char(c) => Some(1),
EscapeDefaultState::Done => None,
EscapeDefaultState::Unicode(ref mut iter) => None,
EscapeDefaultState::Backslash(c) => Some(0),
EscapeDefaultState::Char(c) => Some(1),
EscapeDefaultState::Done => None,
EscapeDefaultState::Unicode(_) => None,
}
}
}

0 comments on commit efbd47f

Please sign in to comment.