This repository was archived by the owner on Dec 16, 2022. It is now read-only.
forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlineedit.jl
152 lines (130 loc) · 3.8 KB
/
lineedit.jl
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
using Base.LineEdit
a_foo = 0
const foo_keymap = {
'a' => :( global a_foo; a_foo += 1)
}
b_foo = 0
const foo2_keymap = {
'b' => :( global b_foo; b_foo += 1)
}
a_bar = 0
b_bar = 0
const bar_keymap = {
'a' => :( global a_bar; a_bar += 1),
'b' => :( global b_bar; b_bar += 1)
}
test1_func = @eval @LineEdit.keymap $foo_keymap
function run_test(f,buf)
global a_foo, a_bar, b_bar
a_foo = a_bar = b_bar = 0
while !eof(buf)
f(buf,nothing)
end
end
run_test(test1_func,IOBuffer("aa"))
@test a_foo == 2
test2_func = @eval @LineEdit.keymap $([foo2_keymap, foo_keymap])
run_test(test2_func,IOBuffer("aaabb"))
@test a_foo == 3
@test b_foo == 2
test3_func = @eval @LineEdit.keymap $([bar_keymap, foo_keymap])
run_test(test3_func,IOBuffer("aab"))
@test a_bar == 2
@test b_bar == 1
## edit_move_{up,down} ##
buf = IOBuffer("type X\n a::Int\nend")
for i = 0:6
seek(buf,i)
@test !LineEdit.edit_move_up(buf)
@test position(buf) == i
seek(buf,i)
@test LineEdit.edit_move_down(buf)
@test position(buf) == i+7
end
for i = 7:17
seek(buf,i)
@test LineEdit.edit_move_up(buf)
@test position(buf) == min(i-7,6)
seek(buf,i)
@test LineEdit.edit_move_down(buf)
@test position(buf) == min(i+11,21)
end
for i = 18:21
seek(buf,i)
@test LineEdit.edit_move_up(buf)
@test position(buf) == i-11
seek(buf,i)
@test !LineEdit.edit_move_down(buf)
@test position(buf) == i
end
buf = IOBuffer("type X\n\n")
seekend(buf)
@test LineEdit.edit_move_up(buf)
@test position(buf) == 7
@test LineEdit.edit_move_up(buf)
@test position(buf) == 0
@test !LineEdit.edit_move_up(buf)
@test position(buf) == 0
seek(buf,0)
@test LineEdit.edit_move_down(buf)
@test position(buf) == 7
@test LineEdit.edit_move_down(buf)
@test position(buf) == 8
@test !LineEdit.edit_move_down(buf)
@test position(buf) == 8
## edit_delete_prev_word ##
buf = IOBuffer("type X\n ")
seekend(buf)
@test LineEdit.edit_delete_prev_word(buf)
@test position(buf) == 5
@test buf.size == 5
@test bytestring(buf.data[1:buf.size]) == "type "
buf = IOBuffer("4 +aaa+ x")
seek(buf,8)
@test LineEdit.edit_delete_prev_word(buf)
@test position(buf) == 3
@test buf.size == 4
@test bytestring(buf.data[1:buf.size]) == "4 +x"
buf = IOBuffer("x = func(arg1,arg2 , arg3)")
seekend(buf)
LineEdit.char_move_word_left(buf)
@test position(buf) == 21
@test LineEdit.edit_delete_prev_word(buf)
@test bytestring(buf.data[1:buf.size]) == "x = func(arg1,arg3)"
@test LineEdit.edit_delete_prev_word(buf)
@test bytestring(buf.data[1:buf.size]) == "x = func(arg3)"
@test LineEdit.edit_delete_prev_word(buf)
@test bytestring(buf.data[1:buf.size]) == "x = arg3)"
## edit_transpose ##
let buf = IOBuffer()
LineEdit.edit_insert(buf, "abcde")
seek(buf,0)
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "abcde"
LineEdit.char_move_right(buf)
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "bacde"
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "bcade"
seekend(buf)
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "bcaed"
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "bcade"
seek(buf, 0)
LineEdit.edit_clear(buf)
LineEdit.edit_insert(buf, "αβγδε")
seek(buf,0)
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "αβγδε"
LineEdit.char_move_right(buf)
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "βαγδε"
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "βγαδε"
seekend(buf)
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "βγαεδ"
LineEdit.edit_transpose(buf)
@test bytestring(buf.data[1:buf.size]) == "βγαδε"
end