|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
mod tapemachine;
|
|
|
|
|
pub mod tapemachine;
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
@ -10,7 +10,7 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn it_returns_the_next_char() {
|
|
|
|
|
let mut ctm = CharTapeMachine::new(TEST_STRING.chars().collect());
|
|
|
|
|
let mut test_chars: Vec<char> = TEST_STRING.chars().collect();
|
|
|
|
|
let test_chars: Vec<char> = TEST_STRING.chars().collect();
|
|
|
|
|
|
|
|
|
|
let mut next = ctm.next_char().unwrap();
|
|
|
|
|
assert_eq!(next, *test_chars.get(1).unwrap());
|
|
|
|
@ -18,9 +18,9 @@ mod tests {
|
|
|
|
|
next = ctm.next_char().unwrap();
|
|
|
|
|
assert_eq!(next, *test_chars.get(2).unwrap());
|
|
|
|
|
|
|
|
|
|
next = ctm.next_char().unwrap();
|
|
|
|
|
next = ctm.next_char().unwrap();
|
|
|
|
|
next = ctm.next_char().unwrap();
|
|
|
|
|
let _ = ctm.next_char().unwrap();
|
|
|
|
|
let _ = ctm.next_char().unwrap();
|
|
|
|
|
let _ = ctm.next_char().unwrap();
|
|
|
|
|
next = ctm.next_char().unwrap();
|
|
|
|
|
assert_eq!(next, *test_chars.get(6).unwrap());
|
|
|
|
|
}
|
|
|
|
@ -28,7 +28,7 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn it_rewinds() {
|
|
|
|
|
let mut ctm = CharTapeMachine::new(TEST_STRING.chars().collect());
|
|
|
|
|
let mut test_chars: Vec<char> = TEST_STRING.chars().collect();
|
|
|
|
|
let test_chars: Vec<char> = TEST_STRING.chars().collect();
|
|
|
|
|
|
|
|
|
|
ctm.next_char().unwrap();
|
|
|
|
|
ctm.next_char().unwrap();
|
|
|
|
@ -41,7 +41,7 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn it_seeks() {
|
|
|
|
|
let mut ctm = CharTapeMachine::new(TEST_STRING.chars().collect());
|
|
|
|
|
let mut test_chars: Vec<char> = TEST_STRING.chars().collect();
|
|
|
|
|
let test_chars: Vec<char> = TEST_STRING.chars().collect();
|
|
|
|
|
|
|
|
|
|
assert_eq!(ctm.next_char(), Some(*test_chars.get(1).unwrap()));
|
|
|
|
|
ctm.seek_one().unwrap();
|
|
|
|
@ -55,11 +55,11 @@ mod tests {
|
|
|
|
|
fn it_asserts_chars() -> TapeResult<()> {
|
|
|
|
|
let mut ctm = CharTapeMachine::new(TEST_STRING.chars().collect());
|
|
|
|
|
ctm.assert_any(&['A', 'B', 'T'], None)?;
|
|
|
|
|
ctm.seek_one();
|
|
|
|
|
ctm.seek_one().unwrap();
|
|
|
|
|
ctm.assert_char(&'E', None)?;
|
|
|
|
|
ctm.seek_one();
|
|
|
|
|
ctm.seek_one().unwrap();
|
|
|
|
|
ctm.assert_sequence(&['S', 'T', ' '], None)?;
|
|
|
|
|
ctm.seek_one();
|
|
|
|
|
ctm.seek_one().unwrap();
|
|
|
|
|
ctm.assert_any_sequence(&[&['C'], &['A'], &['A', 'B'], &['S', 'T', 'R']], None)?;
|
|
|
|
|
|
|
|
|
|
if let Ok(_) = ctm.assert_any_sequence(&[&['C'], &['A'], &['A', 'B'], &['S', 'T', 'R']], None) {
|
|
|
|
|