Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed Aug 27, 2023
1 parent 0b5d7f4 commit f10d101
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion clafrica-lib/data/sample.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
x y
2a_ á̠
2aa áá
2af_ ɑ̠́
Expand All @@ -11,4 +12,4 @@
2oo óó
2ua úá
2uaf úɑ́
2uuaf ʉ́ɑ́
2uuaf ʉ́ɑ́
27 changes: 18 additions & 9 deletions clafrica-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub mod utils {
pub fn load_data(file_path: &str) -> Result<Vec<Vec<String>>, io::Error> {
let data = fs::read_to_string(file_path)?;
let data = data
.trim()
.split('\n')
.map(|line| {
line.split_whitespace()
Expand Down Expand Up @@ -285,41 +286,49 @@ mod tests {
.collect(),
);

let mut cursor = text_buffer::Cursor::new(root, 5);
let mut cursor = text_buffer::Cursor::new(root, 8);

assert_eq!(cursor.state(), (None, 0, '\0'));

hit!(cursor '2', 'i', 'a', 'f');
assert_eq!(cursor.to_sequence(), vec!['2', 'i', 'a', 'f']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'i', 'a', 'f']);

assert_eq!(cursor.state(), (Some("íɑ́".to_owned()), 4, 'f'));

undo!(cursor 1);
assert_eq!(cursor.to_sequence(), vec!['2', 'i', 'a']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'i', 'a']);

undo!(cursor 1);
cursor.hit('e');
assert_eq!(cursor.to_sequence(), vec!['2', 'i', 'e']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'i', 'e']);

undo!(cursor 2);
hit!(cursor 'o', 'o');
assert_eq!(cursor.to_sequence(), vec!['2', 'o', 'o']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'o', 'o']);

undo!(cursor 3);
assert_eq!(cursor.to_sequence(), vec![]);
assert_eq!(cursor.to_sequence(), vec!['\0']);

hit!(cursor '2', '2', 'u', 'a');
assert_eq!(cursor.to_sequence(), vec!['2', '\0', '2', 'u', 'a']);
assert_eq!(
cursor.to_sequence(),
vec!['\0', '\0', '2', '\0', '2', 'u', 'a']
);
undo!(cursor 4);
assert_eq!(cursor.to_sequence(), vec!['\0', '\0']);
undo!(cursor 1);
assert_eq!(cursor.to_sequence(), vec![]);

hit!(
cursor
'a', 'a', '2', 'a', 'e', 'a', '2', 'f', 'a',
'2', '2', '2', 'i', 'a', '2', '2', '_', 'f',
'2', '2', 'x', 'x', '2', 'i', 'a', '2', '2', '_', 'f',
'2', 'a', '2', 'a', '_'
);
assert_eq!(cursor.to_sequence(), vec!['a', '\0', '2', 'a', '_']);
assert_eq!(
cursor.to_sequence(),
vec!['f', '\0', '2', 'a', '\0', '2', 'a', '_']
);

cursor.clear();
assert_eq!(cursor.to_sequence(), vec![]);
Expand Down

0 comments on commit f10d101

Please sign in to comment.