|
@@ -90,6 +90,77 @@ fn move_grapheme() { |
|
|
assert_eq!(cursor.grapheme_index(), 2);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn move_grapheme_with_line_ending() {
|
|
|
let line_ids = parse::lines("01\n01").unwrap();
|
|
|
let word_id = arena().read(line_ids[0], &|line| line.first_child().unwrap());
|
|
|
let grapheme_id = arena().read(word_id, &|word| word.first_child());
|
|
|
let mut cursor = Cursor::new(grapheme_id, 0, 0);
|
|
|
|
|
|
cursor.move_grapheme(2);
|
|
|
assert_eq!(cursor.line_index(), 0);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 0);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
|
|
|
cursor.move_grapheme(-1);
|
|
|
assert_eq!(cursor.line_index(), 0);
|
|
|
assert_eq!(cursor.grapheme_index(), 0);
|
|
|
|
|
|
cursor.move_line(1);
|
|
|
assert_eq!(cursor.line_index(), 1);
|
|
|
assert_eq!(cursor.grapheme_index(), 0);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 1);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 1);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn move_grapheme_with_paragraph_ending() {
|
|
|
let paragraph_ids = parse::paragraphs("01\r\n\r\n01").unwrap();
|
|
|
let line_id = arena().read(paragraph_ids[0], &|paragraph| {
|
|
|
paragraph.first_child().unwrap()
|
|
|
});
|
|
|
let word_id = arena().read(line_id, &|line| line.first_child().unwrap());
|
|
|
let grapheme_id = arena().read(word_id, &|word| word.first_child());
|
|
|
let mut cursor = Cursor::new(grapheme_id, 0, 0);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 0);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 0);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
|
|
|
cursor.move_grapheme(-1);
|
|
|
assert_eq!(cursor.line_index(), 0);
|
|
|
assert_eq!(cursor.grapheme_index(), 0);
|
|
|
|
|
|
cursor.move_line(1);
|
|
|
assert_eq!(cursor.line_index(), 1);
|
|
|
assert_eq!(cursor.grapheme_index(), 0);
|
|
|
|
|
|
cursor.move_line(1);
|
|
|
assert_eq!(cursor.line_index(), 2);
|
|
|
assert_eq!(cursor.grapheme_index(), 0);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 2);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
|
|
|
cursor.move_grapheme(1);
|
|
|
assert_eq!(cursor.line_index(), 2);
|
|
|
assert_eq!(cursor.grapheme_index(), 1);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn move_line() {
|
|
|
let line_ids = parse::lines("0\n1\n2").unwrap();
|