1
use super::*;
2

            
3
#[test]
4
1
fn emacs_insert_appends_at_cursor() {
5
1
    let mut e = Editor::default();
6
1
    e.insert_char('a');
7
1
    e.insert_char('b');
8
1
    e.insert_char('c');
9
1
    assert_eq!(e.buffer(), "abc");
10
1
    assert_eq!(e.cursor(), 3);
11
1
}
12

            
13
#[test]
14
1
fn emacs_kill_to_end_truncates() {
15
1
    let mut e = Editor::with_buffer("hello world");
16
1
    e.move_home();
17
1
    for _ in 0..5 {
18
5
        e.move_right();
19
    }
20
1
    e.kill_to_end();
21
1
    assert_eq!(e.buffer(), "hello");
22
1
    assert_eq!(e.cursor(), 5);
23
1
}
24

            
25
#[test]
26
1
fn emacs_kill_word_backward_drops_word_and_spaces() {
27
1
    let mut e = Editor::with_buffer("hello world");
28
1
    e.move_end();
29
1
    e.kill_word_backward();
30
1
    assert_eq!(e.buffer(), "hello ");
31
1
}
32

            
33
#[test]
34
1
fn delete_backward_at_start_is_noop() {
35
1
    let mut e = Editor::default();
36
1
    e.delete_backward();
37
1
    assert_eq!(e.buffer(), "");
38
1
    assert_eq!(e.cursor(), 0);
39
1
}
40

            
41
#[test]
42
1
fn move_right_saturates_at_end() {
43
1
    let mut e = Editor::with_buffer("ab");
44
1
    e.move_right();
45
1
    e.move_right();
46
1
    e.move_right();
47
1
    assert_eq!(e.cursor(), 2);
48
1
}
49

            
50
#[test]
51
1
fn word_forward_skips_to_next_token() {
52
1
    let mut e = Editor::with_buffer("hello world foo");
53
1
    e.move_home();
54
1
    e.word_forward();
55
1
    assert_eq!(e.cursor(), 6);
56
1
    e.word_forward();
57
1
    assert_eq!(e.cursor(), 12);
58
1
}
59

            
60
#[test]
61
1
fn word_backward_reverses_word_forward() {
62
1
    let mut e = Editor::with_buffer("hello world foo");
63
1
    e.move_end();
64
1
    e.word_backward();
65
1
    assert_eq!(e.cursor(), 12);
66
1
    e.word_backward();
67
1
    assert_eq!(e.cursor(), 6);
68
1
}
69

            
70
#[test]
71
1
fn delete_word_forward_deletes_the_word_and_its_space() {
72
1
    let mut e = Editor::with_buffer("hello world foo");
73
1
    e.move_home();
74
1
    e.delete_word_forward();
75
1
    assert_eq!(e.buffer(), "world foo");
76
1
}
77

            
78
#[test]
79
1
fn set_cursor_clamps_to_the_text() {
80
1
    let mut editor = Editor::with_buffer("abc");
81
1
    editor.set_cursor(1);
82
1
    assert_eq!(editor.cursor(), 1);
83
1
    editor.set_cursor(99);
84
1
    assert_eq!(editor.cursor(), 3);
85
1
}