/
02-basic.t
208 lines (173 loc) · 6.06 KB
/
02-basic.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use v6;
use Test;
use GTK::Simple::App;
use GTK::Scintilla;
use GTK::Scintilla::Editor;
# Test data
my @lines = [ "Line #0\n", "Line #1\n", "Line #2" ];
plan 50 + @lines.elems * 2;
# Test version method
my $version = GTK::Scintilla.version;
say $version;
ok( $version<major> == 3, "Major version match" );
ok( $version<minor> == 7, "Minor version match" );
ok( $version<patch> == 2, "Patch version match" );
ok( $version<string> eq "3.7.2", "Version string match" );
# Create GTK application
my $app = GTK::Simple::App.new(title => "Hello GTK + Scintilla!");
# Create editor widget
my $editor = GTK::Scintilla::Editor.new;
$editor.size-request(500, 300);
$app.set-content($editor);
# Test text, text and text-length equality
my $text = @lines.join("");
$editor.text($text);
ok( $editor.text eq $text, "get and set text works" );
ok( $editor.text-length eq $text.chars, "text-length works");
# Test append-text
{
constant TEXT = "XYZ\n";
$editor.text($text);
$editor.append-text(TEXT);
ok( $editor.text.ends-with(TEXT), ".append-text works" );
}
# Test add-text
{
constant TEXT = "ABC\n";
$editor.text($text);
$editor.add-text(TEXT);
$editor.add-text("\n");
ok( $editor.text eq (TEXT ~ "\n" ~ $text), ".add-text works" );
}
# Test delete-range
$editor.text($text);
$editor.delete-range(1, 5);
my $text-after-delete = $text.substr(0, 1) ~ $text.substr(6);
ok( $editor.text eq $text-after-delete, ".delete-range works");
# Test char-at
$editor.text($text);
ok( $editor.char-at(0) eq $text.comb[0], "char-at(0) works");
ok( $editor.char-at(5) eq $text.comb[5], "char-at(5) works");
ok( $editor.char-at(-1) eq "", "invalid position returns empty string");
# Test line-length and line return values
$editor.text($text);
my $num-lines = @lines.elems;
for 0..@lines.elems - 1 -> $i {
my $line = @lines[$i];
ok( $editor.line-length($i) == $line.chars, "line-length($i) works");
ok( $editor.line($i) eq $line, "line($i) works");
}
# Test length
$editor.text("");
ok( $editor.length == 0, ".length works");
$editor.text($text);
ok( $editor.length >= $text.chars, ".length works");
# Test line-count
ok($editor.line-count == $num-lines, "line-count works");
# Test out-of-range indices for line-length and line
ok($editor.line-length(-1) eq 0, "line(-1) must return zero");
ok($editor.line(-1) eq "", "line(-1) must return empty string");
ok($editor.line-length($num-lines) eq 0, "line($num-lines) must return also zero");
ok($editor.line($num-lines) eq "", "line($num-lines) must return also empty string");
# Test save-point and modified
{
$editor.text($text);
ok( $editor.modified, ".modified is true after a replace text operation" );
$editor.save-point;
ok( not $editor.modified, ".modified is false after a save point" );
$editor.text($text);
ok( $editor.modified, ".modified is true again after a replace text operation" );
}
# Test current-pos
{
$editor.text($text);
ok( $editor.current-pos == 0, "By default current caret position is zero");
$editor.current-pos(5);
ok( $editor.current-pos == 5, "current-pos setter/getter works");
}
$editor.clear-all;
ok($editor.text-length == 0, "clear-all & text-length works");
ok($editor.text eq "", "clear-all & text works");
ok($editor.line-count == 1, "clear-all & line-count works");
# Test set/get bold style
$editor.style-bold(0, True);
ok( $editor.style-bold(0), "set, get bold works");
# Before an undo
ok( $editor.can-undo, "can-undo is True");
ok( not $editor.can-redo, "can-redo is False");
# After an undo
$editor.undo;
ok( $editor.can-undo, "can-undo is False");
ok( $editor.can-redo, "can-redo is True");
ok( $editor.text eq $text, "undo works" );
# After a redo
$editor.redo;
ok( $editor.text eq "", "redo works" );
# After an empty-undo-buffer
$editor.empty-undo-buffer;
ok( !$editor.can-undo, "empty-undo-buffer works");
# Test begin and undo action (aka transaction)
$editor.clear-all;
$editor.begin-undo-action;
$editor.text("ABC\n");
$editor.append-text("DEF\n");
$editor.end-undo-action;
$editor.undo;
ok( $editor.text eq "", "begin and end undo action work");
# Test selection
{
constant SELECTION-START = 1;
constant SELECTION-END = 5;
$editor.text($text);
$editor.selection-start(SELECTION-START);
$editor.selection-end(SELECTION-END);
ok( $editor.selection-start == SELECTION-START &&
$editor.selection-end == SELECTION-END,
"set/get selection start/end works");
$editor.select-all;
ok( $editor.selection-start == 0 &&
$editor.selection-end == $text.chars, "select-all works");
$editor.empty-selection(SELECTION-END);
ok( $editor.selection-start == SELECTION-END &&
$editor.selection-end == SELECTION-END, "empty-selection works");
}
# Test set/get read only
{
ok( !$editor.read-only, "By default the document is not read-only");
$editor.read-only(True);
ok( $editor.read-only, "set/get read-only works");
$editor.read-only(False);
}
# Test cut, copy, clear and paste
{
constant TEXT = "Hello world";
$editor.clear-all;
$editor.copy-text(TEXT);
$editor.paste;
ok( $editor.text, TEXT);
ok( $editor.can-paste, "can-paste is True on a non-readonly document");
$editor.read-only(True);
ok( !$editor.can-paste, "can-paste is False on a readonly document");
$editor.read-only(False);
}
# Test get/set cursor
{
ok( $editor.cursor == Normal, "By default, cursor is normal" );
$editor.cursor(Wait);
ok( $editor.cursor == Wait, "set/get cursor works" );
$editor.cursor(Normal);
}
# Test edge-mode
{
ok( $editor.edge-mode == None, "By default edge mode is None" );
$editor.edge-mode(Line);
ok( $editor.edge-mode == Line, "edge mode getter, setter works" );
$editor.edge-mode(None);
}
# Test edge-column
{
constant EDGE_COLUMN = 78;
ok( $editor.edge-column == 0, "By default edge column is zero" );
$editor.edge-column(EDGE_COLUMN);
ok( $editor.edge-column == EDGE_COLUMN, "edge column getter, setter works" );
}