1
use crate::Row;
2

            
3
#[test]
4
2
fn test_row_render() {
5
    // fn render(&self, start: usize, end: usize, line_number: usize, x_offset: usize)
6
1
    assert_eq!(Row::from("Test").render(0, 50, 1, 0), "Test");
7
1
    assert_eq!(Row::from("Test").render(0, 50, 1, 4), "   1 Test");
8
1
    assert_eq!(Row::from("Test").render(0, 50, 11, 4), "  11 Test");
9
1
    assert_eq!(Row::from("Test").render(10, 60, 11, 4), "  11 ");
10
1
    assert_eq!(Row::from("\u{2764}").render(0, 50, 11, 4), "  11 \u{2764}");
11
2
}
12

            
13
#[test]
14
2
fn test_row_graphemes_index() {
15
1
    let row = Row::from("I \u{2764} unicode!");
16
1
    let mut graphemes = row.graphemes();
17
1
    assert_eq!(graphemes.next(), Some("I"));
18
1
    assert_eq!(graphemes.next(), Some(" "));
19
1
    assert_eq!(graphemes.next(), Some("\u{2764}"));
20
1
    assert_eq!(graphemes.next(), Some(" "));
21
1
    assert_eq!(graphemes.next(), Some("u"));
22
2
}
23

            
24
#[test]
25
2
fn test_row_len() {
26
1
    assert_eq!(Row::from("Hello World!").len(), 12);
27
1
    assert_eq!(Row::from("\u{2764}\u{2764}\u{2764}!").len(), 4); // 3 unicode hearts
28
1
    assert_eq!(Row::from("").len(), 0);
29
2
}
30

            
31
#[test]
32
2
fn test_row_is_empty() {
33
1
    assert!(Row::from("").is_empty());
34
2
}
35

            
36
#[test]
37
2
fn test_row_index() {
38
1
    assert_eq!(Row::from("I \u{2764} unicode!").nth_grapheme(2), "\u{2764}");
39
2
}
40

            
41
#[test]
42
2
fn test_row_num_words() {
43
1
    assert_eq!(Row::from("I l\u{f8}ve unicode!").num_words(), 3);
44
1
    assert_eq!(Row::from("I \u{9ec} unicode!").num_words(), 3);
45

            
46
    // "weird cases": turns out a heart isn't alphabetic, so it's not considered
47
    // a word.
48
1
    assert_eq!(Row::from("I \u{2764} unicode!").num_words(), 2);
49
1
    assert_eq!(Row::from("I \u{2764}\u{2764} unicode!").num_words(), 2);
50
2
}
51

            
52
#[test]
53
2
fn test_row_contains() {
54
1
    assert!(Row::from("I \u{2764} unicode!").contains("\u{2764}"));
55

            
56
    // check that the match is done on the unicode char and not the raw text
57
1
    assert!(!Row::from("I \u{2764} unicode!").contains("2764"));
58
1
    assert!(!Row::from("Hello").contains("Plop"));
59
1
    assert!(Row::from("Hello").contains("lo"));
60
1
    assert!(!Row::from("Hello").contains("LO"));
61
2
}
62

            
63
#[test]
64
2
fn test_row_find_all() {
65
1
    assert_eq!(Row::from("Hello hello world!").find_all("ello"), vec![1, 7]);
66
1
    assert!(Row::from("Hello world!").find_all("\u{2764}").is_empty());
67
1
    assert_eq!(
68
1
        Row::from("Hello \u{2764} world!").find_all("\u{2764}"),
69
1
        vec![6]
70
    );
71
2
}
72

            
73
#[test]
74
2
fn test_row_is_whitespace() {
75
    // whitespaces
76
1
    assert!(Row::from(" ").is_whitespace());
77
1
    assert!(Row::from("\t").is_whitespace());
78
1
    assert!(Row::from("\t ").is_whitespace());
79
1
    assert!(!Row::from("a").is_whitespace());
80
1
    assert!(!Row::from("aa").is_whitespace());
81
1
    assert!(!Row::from(" \u{2764}").is_whitespace());
82
2
}
83

            
84
#[test]
85
2
fn test_row_string_chars() {
86
1
    assert_eq!(
87
1
        Row::from(" \u{2764}").string.chars().collect::<Vec<char>>(),
88
        [' ', '\u{2764}']
89
    );
90
2
}
91

            
92
#[test]
93
2
fn test_row_insert() {
94
1
    let mut row = Row::from("Hell");
95
1
    row.insert(4, 'o');
96
1
    assert_eq!(row.string, "Hello");
97
1
    row.insert(8, 'o');
98
1
    assert_eq!(row.string, "Helloo");
99
1
    row.insert(0, '.');
100
1
    assert_eq!(row.string, ".Helloo");
101
2
}
102

            
103
#[test]
104
2
fn test_row_delete() {
105
1
    let mut row = Row::from("Hello!");
106
1
    row.delete(8); // outside the string's boundaries
107
1
    assert_eq!(row.string, "Hello!");
108
1
    row.delete(5);
109
1
    assert_eq!(row.string, "Hello");
110
1
    row.delete(2);
111
1
    assert_eq!(row.string, "Helo");
112
2
}
113

            
114
#[test]
115
2
fn test_row_append() {
116
1
    let mut row1 = Row::from("Hello!");
117
1
    let row2 = Row::from("world!");
118
1
    row1.append(&row2);
119
1
    assert_eq!(row1.string, "Hello!world!");
120
2
}
121

            
122
#[test]
123
2
fn test_row_split() {
124
1
    let mut row1 = Row::from("Hello world!");
125
1
    let row2 = row1.split(5);
126
1
    assert_eq!(row1.string, "Hello");
127
1
    assert_eq!(row2.string, " world!");
128
2
}