vice-editor 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vice.rb +4 -2
- data/lib/vice/blitter.rb +1 -1
- data/lib/vice/buffer.rb +3 -3
- data/lib/vice/constants.rb +45 -0
- data/lib/vice/keypress.rb +146 -0
- data/lib/vice/movement.rb +3 -1
- data/lib/vice/parser.rb +25 -122
- data/lib/vice/version.rb +1 -1
- metadata +4 -7
- data/Rakefile +0 -18
- data/test/vice.rb +0 -37
- data/test/vice/buffer.rb +0 -82
- data/test/vice/movement.rb +0 -41
- data/test/vice/parser.rb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 653e5d0a2a2e7aeb03bb3afe07a67c4396fa948975770a9656b8cd6bf65f0c4c
|
4
|
+
data.tar.gz: 48fa594f664bb81a51e131ac5e4683d5133c819605dabcf7cbbe1e9dc20cca65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f27ffff49999814fb674ae93995ca40c3aad785f74aeaa51a0f8cd104e70933f4e5d174b3e0841c5e5318aff113a569bceaa3c97e59aa5d5b2db90b22fa78758
|
7
|
+
data.tar.gz: 317f800f89486660ed2c7267ddccaaeab4fd77586a991646a0f0534836043d03c58d67c78c3cdb8e78919f080d484c9c6a910313565180dbdc6defc8a6e30ac1
|
data/lib/vice.rb
CHANGED
@@ -32,7 +32,7 @@ module Vice
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def init_config
|
35
|
-
defaults =
|
35
|
+
defaults = DEFAULTS.clone
|
36
36
|
|
37
37
|
configfile = "#{Dir.home}/.vicerc"
|
38
38
|
user_defined = File.open(configfile) { |f| YAML.safe_load(f.read) } if File.file? configfile
|
@@ -79,13 +79,15 @@ module Vice
|
|
79
79
|
|
80
80
|
def prev_buffer
|
81
81
|
@current_buffer -= 1
|
82
|
-
@current_buffer = @buffers.length - 1 if @current_buffer
|
82
|
+
@current_buffer = @buffers.length - 1 if @current_buffer.negative?
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
require_relative 'vice/constants.rb'
|
87
88
|
require_relative 'vice/version'
|
88
89
|
require_relative 'vice/buffer'
|
90
|
+
require_relative 'vice/keypress.rb'
|
89
91
|
require_relative 'vice/cursor'
|
90
92
|
require_relative 'vice/parser'
|
91
93
|
require_relative 'vice/blitter'
|
data/lib/vice/blitter.rb
CHANGED
data/lib/vice/buffer.rb
CHANGED
@@ -38,11 +38,11 @@ class Vice::Buffer
|
|
38
38
|
def cursor_end_of_line
|
39
39
|
# if we're out of bounds, move the cursor to the end of the line
|
40
40
|
@cursor.col = @buffer[@cursor.line].length - 1 if @cursor.col >= @buffer[@cursor.line].length
|
41
|
-
@cursor.col = 0 if @cursor.col
|
41
|
+
@cursor.col = 0 if @cursor.col.negative?
|
42
42
|
end
|
43
43
|
|
44
44
|
def cursor_up
|
45
|
-
@cursor.line -= 1 if @cursor.line
|
45
|
+
@cursor.line -= 1 if @cursor.line.positive?
|
46
46
|
cursor_end_of_line
|
47
47
|
end
|
48
48
|
|
@@ -52,7 +52,7 @@ class Vice::Buffer
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def cursor_left
|
55
|
-
@cursor.col -= 1 if @cursor.col
|
55
|
+
@cursor.col -= 1 if @cursor.col.positive?
|
56
56
|
end
|
57
57
|
|
58
58
|
def cursor_right
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Vice
|
2
|
+
DEFAULTS = {
|
3
|
+
tab_width: 4,
|
4
|
+
keys: {
|
5
|
+
'j' => :down,
|
6
|
+
'k' => :up,
|
7
|
+
'l' => :right,
|
8
|
+
'h' => :left,
|
9
|
+
|
10
|
+
'w' => :word,
|
11
|
+
'W' => :word_large,
|
12
|
+
'b' => :backword,
|
13
|
+
'B' => :backword_large,
|
14
|
+
|
15
|
+
'$' => :endline,
|
16
|
+
'0' => :beginline,
|
17
|
+
|
18
|
+
'i' => :insert_before,
|
19
|
+
'a' => :insert_after,
|
20
|
+
'I' => :insert_begin,
|
21
|
+
'A' => :insert_end,
|
22
|
+
'O' => :insert_before_line,
|
23
|
+
'o' => :insert_after_line,
|
24
|
+
|
25
|
+
'X' => :remove_before,
|
26
|
+
'x' => :remove_after,
|
27
|
+
|
28
|
+
'cw' => :change_word,
|
29
|
+
'cc' => :change_line,
|
30
|
+
'dw' => :delete_word,
|
31
|
+
'dd' => :delete_line,
|
32
|
+
|
33
|
+
'g' => :jump_start,
|
34
|
+
'G' => :jump_end,
|
35
|
+
|
36
|
+
'm' => :mark_set,
|
37
|
+
"'" => :mark_jump,
|
38
|
+
|
39
|
+
't' => :buffer_next,
|
40
|
+
'T' => :buffer_prev,
|
41
|
+
|
42
|
+
';' => :mode_prompt
|
43
|
+
}
|
44
|
+
}.freeze
|
45
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
class Vice::KeyPress
|
2
|
+
def self.down(_vice, buffer)
|
3
|
+
buffer.cursor_down
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.up(_vice, buffer)
|
7
|
+
buffer.cursor_up
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.right(_vice, buffer)
|
11
|
+
buffer.cursor_right
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.left(_vice, buffer)
|
15
|
+
buffer.cursor_left
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.word(_vice, buffer)
|
19
|
+
buffer.cursor.col = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.word_large(_vice, buffer)
|
23
|
+
buffer.cursor.col = Vice::Movement.w_large(buffer.currentline, buffer.cursor.col)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.backword(_vice, buffer)
|
27
|
+
buffer.cursor.col = Vice::Movement.b(buffer.currentline, buffer.cursor.col)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.backword_large(_vice, buffer)
|
31
|
+
buffer.cursor.col = Vice::Movement.b_large(buffer.currentline, buffer.cursor.col)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.endline(_vice, buffer)
|
35
|
+
buffer.cursor.col = Vice::Movement.dollar buffer.currentline
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.beginline(_vice, buffer)
|
39
|
+
buffer.cursor.col = Vice::Movement.zero
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.insert_before(vice, _buffer)
|
43
|
+
vice.mode = :insert
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.insert_after(vice, buffer)
|
47
|
+
buffer.cursor.col += 1 if buffer.cursor.col < buffer.cols
|
48
|
+
vice.mode = :insert
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.insert_begin(vice, buffer)
|
52
|
+
buffer.cursor.col = 0
|
53
|
+
vice.mode = :insert
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.insert_end(vice, buffer)
|
57
|
+
buffer.cursor.col = buffer.cols
|
58
|
+
vice.mode = :insert
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.insert_before_line(vice, buffer)
|
62
|
+
buffer.newline buffer.cursor.line
|
63
|
+
buffer.cursor.col = 0
|
64
|
+
vice.mode = :insert
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.insert_after_line(vice, buffer)
|
68
|
+
buffer.newline buffer.cursor.line + 1
|
69
|
+
buffer.cursor_down
|
70
|
+
vice.mode = :insert
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.remove_before(_vice, _buffer)
|
74
|
+
# TODO
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.remove_after(_vice, buffer)
|
78
|
+
buffer.rmchar
|
79
|
+
buffer.cursor.col -= 1 if buffer.cursor.col.positive?
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.change_word(vice, buffer)
|
83
|
+
delete_word(vice, buffer)
|
84
|
+
vice.mode = :insert
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.change_line(vice, buffer)
|
88
|
+
buffer.setline buffer.cursor.line, ''
|
89
|
+
buffer.cursor.col = 0
|
90
|
+
vice.mode = :insert
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.delete_word(_vice, buffer)
|
94
|
+
line_edited = buffer.currentline
|
95
|
+
slice_start = buffer.cursor.col
|
96
|
+
slice_end = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
|
97
|
+
amount = slice_end - buffer.cursor.col
|
98
|
+
amount += 1 if slice_end == buffer.currentline.length - 1
|
99
|
+
line_edited.slice! slice_start, amount
|
100
|
+
|
101
|
+
buffer.setline buffer.cursor.line, line_edited
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.delete_line(_vice, buffer)
|
105
|
+
if buffer.lines == 1
|
106
|
+
buffer.setline 0, ''
|
107
|
+
else
|
108
|
+
buffer.rmline
|
109
|
+
end
|
110
|
+
buffer.cursor.line -= 1 if buffer.lines <= buffer.cursor.line
|
111
|
+
buffer.cursor.col = 0
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.jump_start(_vice, buffer)
|
115
|
+
buffer.cursor.line = 0
|
116
|
+
buffer.cursor.col = 0
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.jump_end(_vice, buffer)
|
120
|
+
buffer.cursor.line = buffer.lines - 1
|
121
|
+
buffer.cursor.col = 0
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.mark_set(vice, buffer, char)
|
125
|
+
buffer.addmark char
|
126
|
+
vice.alert "added mark '" + char + "'"
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.mark_jump(vice, buffer, char)
|
130
|
+
vice.alert 'mark not set' unless buffer.gotomark char
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.buffer_next(vice, _buffer)
|
134
|
+
vice.next_buffer
|
135
|
+
@trail = []
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.buffer_prev(vice, _buffer)
|
139
|
+
vice.prev_buffer
|
140
|
+
@trail = []
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.mode_prompt(vice, _buffer)
|
144
|
+
vice.mode = :prompt
|
145
|
+
end
|
146
|
+
end
|
data/lib/vice/movement.rb
CHANGED
@@ -31,7 +31,9 @@ class Vice::Movement
|
|
31
31
|
|
32
32
|
def self.b_real(line, start, harsh)
|
33
33
|
# if we're already on the beginning of a word, we jump to the previous one
|
34
|
-
|
34
|
+
if start.positive? && !whitespace(line[start], harsh) && whitespace(line[start - 1], harsh)
|
35
|
+
start -= 1
|
36
|
+
end
|
35
37
|
|
36
38
|
b_internal(line, start, harsh)
|
37
39
|
end
|
data/lib/vice/parser.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
class Vice::Parser
|
2
2
|
def initialize
|
3
|
-
|
4
|
-
end
|
5
|
-
|
6
|
-
def resettrail
|
7
|
-
@trail = []
|
3
|
+
@current_command = ''
|
8
4
|
end
|
9
5
|
|
10
6
|
def parsekeypress(vice, buffer, char)
|
@@ -20,14 +16,18 @@ class Vice::Parser
|
|
20
16
|
end
|
21
17
|
|
22
18
|
def parsechar_prompt(vice, current_buffer, char)
|
19
|
+
raise 'prompt parser called from wrong mode' unless vice.mode == :prompt
|
20
|
+
|
23
21
|
case char
|
24
|
-
when 10
|
22
|
+
when 10 # enter
|
25
23
|
Vice::Prompt.parse vice, vice.prompt, vice.buffers[current_buffer]
|
26
24
|
vice.prompt = ''
|
27
25
|
vice.mode = :command
|
28
|
-
when 27
|
26
|
+
when 27 # escape
|
29
27
|
vice.prompt = ''
|
30
28
|
vice.mode = :command
|
29
|
+
when 127 # backspace
|
30
|
+
vice.prompt = vice.prompt[0..-2]
|
31
31
|
when Integer
|
32
32
|
vice.prompt += char if char >= 0 && char <= 10
|
33
33
|
else
|
@@ -37,132 +37,35 @@ class Vice::Parser
|
|
37
37
|
|
38
38
|
def parsechar_command(vice, current_buffer, char)
|
39
39
|
buffer = vice.buffers[current_buffer]
|
40
|
-
raise '
|
40
|
+
raise 'command parser called from wrong mode' unless vice.mode == :command
|
41
41
|
|
42
|
-
if
|
43
|
-
|
44
|
-
|
45
|
-
@trail = []
|
46
|
-
return
|
47
|
-
elsif @trail == ["'"]
|
48
|
-
vice.alert 'mark not set' unless buffer.gotomark char
|
49
|
-
@trail = []
|
42
|
+
if %i[mark_set mark_jump].include? @current_command
|
43
|
+
Vice::KeyPress.public_send(@current_command, vice, buffer, char)
|
44
|
+
@current_command = ''
|
50
45
|
return
|
51
46
|
end
|
52
47
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
buffer.cursor_up
|
59
|
-
when 'l'
|
60
|
-
buffer.cursor_right
|
61
|
-
when 'h'
|
62
|
-
buffer.cursor_left
|
63
|
-
when 'w'
|
64
|
-
if !@trail.empty?
|
65
|
-
if (@trail[0] == 'd' || @trail[0] == 'c') && buffer.currentline != ''
|
66
|
-
line_edited = buffer.currentline
|
67
|
-
slice_start = buffer.cursor.col
|
68
|
-
slice_end = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
|
69
|
-
amount = slice_end - buffer.cursor.col
|
70
|
-
amount += 1 if slice_end == buffer.currentline.length - 1
|
71
|
-
line_edited.slice! slice_start, amount
|
72
|
-
|
73
|
-
buffer.setline buffer.cursor.line, line_edited
|
74
|
-
end
|
75
|
-
vice.mode = :insert if @trail[0] == 'c'
|
76
|
-
@trail = []
|
48
|
+
@current_command += char
|
49
|
+
if !vice.config[:keys][@current_command].nil?
|
50
|
+
command = vice.config[:keys][@current_command]
|
51
|
+
if %i[mark_set mark_jump].include? command
|
52
|
+
@current_command = command
|
77
53
|
else
|
78
|
-
|
54
|
+
Vice::KeyPress.public_send(command, vice, buffer)
|
55
|
+
@current_command = ''
|
79
56
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
when 'B'
|
85
|
-
buffer.cursor.col = Vice::Movement.B(buffer.currentline, buffer.cursor.col)
|
86
|
-
when '$'
|
87
|
-
buffer.cursor.col = Vice::Movement.dollar buffer.currentline
|
88
|
-
when '0'
|
89
|
-
buffer.cursor.col = Vice::Movement.zero
|
90
|
-
|
91
|
-
# entering insert mode
|
92
|
-
when 'I'
|
93
|
-
buffer.cursor.col = 0
|
94
|
-
vice.mode = :insert
|
95
|
-
when 'i'
|
96
|
-
vice.mode = :insert
|
97
|
-
when 'A'
|
98
|
-
buffer.cursor.col = buffer.cols
|
99
|
-
vice.mode = :insert
|
100
|
-
when 'a'
|
101
|
-
buffer.cursor.col += 1 if buffer.cursor.col < buffer.cols
|
102
|
-
vice.mode = :insert
|
103
|
-
when 'O'
|
104
|
-
buffer.newline buffer.cursor.line
|
105
|
-
buffer.cursor.col = 0
|
106
|
-
vice.mode = :insert
|
107
|
-
when 'o'
|
108
|
-
buffer.newline buffer.cursor.line + 1
|
109
|
-
buffer.cursor_down
|
110
|
-
vice.mode = :insert
|
111
|
-
|
112
|
-
# etc.
|
113
|
-
when 'x'
|
114
|
-
buffer.rmchar
|
115
|
-
buffer.cursor.col -= 1 if buffer.cursor.col > 0
|
116
|
-
when 'c'
|
117
|
-
if !@trail.empty? && @trail[0] == 'c'
|
118
|
-
buffer.setline buffer.cursor.line, ''
|
119
|
-
buffer.cursor.col = 0
|
120
|
-
vice.mode = :insert
|
121
|
-
@trail = []
|
122
|
-
else
|
123
|
-
@trail.push 'c'
|
124
|
-
end
|
125
|
-
when 'd'
|
126
|
-
if !@trail.empty? && @trail[0] == 'd'
|
127
|
-
if buffer.lines == 1
|
128
|
-
buffer.setline 0, ''
|
129
|
-
else
|
130
|
-
buffer.rmline
|
131
|
-
end
|
132
|
-
buffer.cursor.line -= 1 if buffer.lines <= buffer.cursor.line
|
133
|
-
buffer.cursor.col = 0
|
134
|
-
@trail = []
|
135
|
-
else
|
136
|
-
@trail.push 'd'
|
137
|
-
end
|
138
|
-
when 'g'
|
139
|
-
if !@trail.empty? && @trail[0] == 'g'
|
140
|
-
buffer.cursor.line = 0
|
141
|
-
buffer.cursor.col = 0
|
142
|
-
else
|
143
|
-
@trail.push 'g'
|
57
|
+
else
|
58
|
+
keep_current = false
|
59
|
+
vice.config[:keys].each do |k|
|
60
|
+
keep_current = true if k[0].start_with? @current_command
|
144
61
|
end
|
145
|
-
|
146
|
-
buffer.cursor.line = buffer.lines - 1
|
147
|
-
buffer.cursor.col = 0
|
148
|
-
when 'm'
|
149
|
-
@trail.push 'm' if @trail.empty?
|
150
|
-
when 't'
|
151
|
-
vice.next_buffer if !@trail.empty? && @trail[0] == 'g'
|
152
|
-
@trail = []
|
153
|
-
when 'T'
|
154
|
-
vice.prev_buffer if !@trail.empty? && @trail[0] == 'g'
|
155
|
-
@trail = []
|
156
|
-
when ';', ':'
|
157
|
-
vice.mode = :prompt
|
158
|
-
when "'"
|
159
|
-
@trail.push "'" if @trail.empty?
|
62
|
+
@current_command = '' unless keep_current
|
160
63
|
end
|
161
64
|
end
|
162
65
|
|
163
66
|
def parsechar_insert(vice, current_buffer, char)
|
164
67
|
buffer = vice.buffers[current_buffer]
|
165
|
-
raise '
|
68
|
+
raise 'insert parser called from wrong mode' unless vice.mode == :insert
|
166
69
|
case char
|
167
70
|
when 9
|
168
71
|
buffer.insert "\t"
|
@@ -174,7 +77,7 @@ class Vice::Parser
|
|
174
77
|
vice.mode = :command
|
175
78
|
buffer.cursor_end_of_line
|
176
79
|
when 127 # backspace
|
177
|
-
if buffer.cursor.col
|
80
|
+
if buffer.cursor.col.positive?
|
178
81
|
buffer.cursor.col -= 1
|
179
82
|
buffer.rmchar
|
180
83
|
end
|
data/lib/vice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vice-editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- knarka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -33,20 +33,17 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- LICENSE
|
35
35
|
- README.md
|
36
|
-
- Rakefile
|
37
36
|
- bin/vice
|
38
37
|
- lib/vice.rb
|
39
38
|
- lib/vice/blitter.rb
|
40
39
|
- lib/vice/buffer.rb
|
40
|
+
- lib/vice/constants.rb
|
41
41
|
- lib/vice/cursor.rb
|
42
|
+
- lib/vice/keypress.rb
|
42
43
|
- lib/vice/movement.rb
|
43
44
|
- lib/vice/parser.rb
|
44
45
|
- lib/vice/prompt.rb
|
45
46
|
- lib/vice/version.rb
|
46
|
-
- test/vice.rb
|
47
|
-
- test/vice/buffer.rb
|
48
|
-
- test/vice/movement.rb
|
49
|
-
- test/vice/parser.rb
|
50
47
|
homepage: https://github.com/knarka/vice
|
51
48
|
licenses:
|
52
49
|
- GPL-3.0
|
data/Rakefile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
task default: %w[run]
|
2
|
-
|
3
|
-
task :run do
|
4
|
-
require_relative 'lib/vice'
|
5
|
-
Vice::Vice.new(nil).start
|
6
|
-
end
|
7
|
-
|
8
|
-
task :test do
|
9
|
-
Dir.foreach('test/vice') do |test|
|
10
|
-
next if ['.', '..'].include? test
|
11
|
-
ruby 'test/vice/' + test
|
12
|
-
end
|
13
|
-
ruby 'test/vice.rb'
|
14
|
-
end
|
15
|
-
|
16
|
-
task :style do
|
17
|
-
sh 'rubocop -c .rubocop.yml lib/ test/ Gemfile Rakefile'
|
18
|
-
end
|
data/test/vice.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
require_relative '../lib/vice'
|
4
|
-
|
5
|
-
class TestVice < MiniTest::Test
|
6
|
-
def setup
|
7
|
-
@vice = Vice::Vice.new nil
|
8
|
-
@vice.buffers.push Vice::Buffer.new nil
|
9
|
-
@vice.buffers.push Vice::Buffer.new nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_switch_tab_forward
|
13
|
-
assert_equal 0, @vice.current_buffer
|
14
|
-
|
15
|
-
@vice.next_buffer
|
16
|
-
assert_equal 1, @vice.current_buffer
|
17
|
-
|
18
|
-
@vice.next_buffer
|
19
|
-
assert_equal 2, @vice.current_buffer
|
20
|
-
|
21
|
-
@vice.next_buffer
|
22
|
-
assert_equal 0, @vice.current_buffer
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_switch_tab_backward
|
26
|
-
assert_equal 0, @vice.current_buffer
|
27
|
-
|
28
|
-
@vice.prev_buffer
|
29
|
-
assert_equal 2, @vice.current_buffer
|
30
|
-
|
31
|
-
@vice.prev_buffer
|
32
|
-
assert_equal 1, @vice.current_buffer
|
33
|
-
|
34
|
-
@vice.prev_buffer
|
35
|
-
assert_equal 0, @vice.current_buffer
|
36
|
-
end
|
37
|
-
end
|
data/test/vice/buffer.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
require_relative '../../lib/vice'
|
4
|
-
|
5
|
-
class TestBuffer < MiniTest::Test
|
6
|
-
def setup
|
7
|
-
@buffer = Vice::Buffer.new nil
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_create_buffer
|
11
|
-
assert_equal [''], @buffer.buffer
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_newline_valid
|
15
|
-
@buffer.newline 0
|
16
|
-
assert_equal ['', ''], @buffer.buffer
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_newline_negative_index
|
20
|
-
assert_raises RuntimeError do
|
21
|
-
@buffer.newline -1
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_insert_and_insertf_valid
|
26
|
-
@buffer.insert 'chunky bacon'
|
27
|
-
assert_equal 'chunky bacon', @buffer.buffer[0]
|
28
|
-
|
29
|
-
@buffer.insertf 0, 6, ' crispy'
|
30
|
-
assert_equal 'chunky crispy bacon', @buffer.buffer[0]
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_insertf_out_of_bounds
|
34
|
-
# negative line index
|
35
|
-
assert_raises RuntimeError do
|
36
|
-
@buffer.insertf -1, 0, ''
|
37
|
-
end
|
38
|
-
|
39
|
-
# out of bounds line index
|
40
|
-
assert_raises RuntimeError do
|
41
|
-
@buffer.insertf 2, 0, ''
|
42
|
-
end
|
43
|
-
|
44
|
-
@buffer.newline 0
|
45
|
-
|
46
|
-
# negative column index
|
47
|
-
assert_raises RuntimeError do
|
48
|
-
@buffer.insertf 0, -1, ''
|
49
|
-
end
|
50
|
-
|
51
|
-
# out of bounds column index
|
52
|
-
assert_raises RuntimeError do
|
53
|
-
@buffer.insertf 0, 2, ''
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_setline_valid
|
58
|
-
assert_equal [''], @buffer.buffer
|
59
|
-
|
60
|
-
@buffer.setline 0, 'chunky bacon'
|
61
|
-
assert_equal 'chunky bacon', @buffer.buffer[0]
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_rmlinef_valid
|
65
|
-
assert_equal [''], @buffer.buffer
|
66
|
-
|
67
|
-
@buffer.rmlinef 0
|
68
|
-
assert_equal [], @buffer.buffer
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_getline_valid
|
72
|
-
@buffer.setline 0, 'chunky bacon'
|
73
|
-
assert_equal 'chunky bacon', @buffer.getline(0)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_modified
|
77
|
-
assert_equal false, @buffer.modified
|
78
|
-
|
79
|
-
@buffer.newline 0
|
80
|
-
assert_equal true, @buffer.modified
|
81
|
-
end
|
82
|
-
end
|
data/test/vice/movement.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
require_relative '../../lib/vice'
|
4
|
-
|
5
|
-
class TestMovement < MiniTest::Test
|
6
|
-
def test_w_end_of_string
|
7
|
-
assert_equal Vice::Movement.w('abc', 0), 2
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_w_some_words
|
11
|
-
assert_equal Vice::Movement.w('jantje zag eens', 2), 7
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_w_with_other_whitespace_chars
|
15
|
-
assert_equal Vice::Movement.w("jantje\t\nzag eens", 2), 8
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_b_start_of_string
|
19
|
-
assert_equal Vice::Movement.b('aaaaa', 5), 0
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_b_some_words
|
23
|
-
assert_equal Vice::Movement.b('ab cd', 4), 3
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_b_from_start_of_word
|
27
|
-
assert_equal Vice::Movement.b('jantje zag eens', 11), 7
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_w_w_large_difference
|
31
|
-
string = 'aaa-bbb ccc'
|
32
|
-
assert_equal Vice::Movement.w(string, 1), 4
|
33
|
-
assert_equal Vice::Movement.w_large(string, 1), 8
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_b_b_large_difference
|
37
|
-
string = 'bbb-ccc'
|
38
|
-
assert_equal Vice::Movement.b(string, 5), 4
|
39
|
-
assert_equal Vice::Movement.b_large(string, 5), 0
|
40
|
-
end
|
41
|
-
end
|
data/test/vice/parser.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
require_relative '../../lib/vice'
|
4
|
-
|
5
|
-
class TestParser < MiniTest::Test
|
6
|
-
def setup
|
7
|
-
@vice = Vice::Vice.new nil
|
8
|
-
@vice.buffers.push Vice::Buffer.new nil
|
9
|
-
@parser = Vice::Parser.new
|
10
|
-
@buffer = 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_parsechar_command_movement_up_down
|
14
|
-
@vice.buffers[@buffer].newline 0
|
15
|
-
assert_equal @vice.buffers[@buffer].cursor.line, 0
|
16
|
-
|
17
|
-
# go down one line
|
18
|
-
@parser.parsechar_command @vice, @buffer, 'j'
|
19
|
-
assert_equal @vice.buffers[@buffer].cursor.line, 1
|
20
|
-
|
21
|
-
# don't go down another line if no more lines exist
|
22
|
-
@parser.parsechar_command @vice, @buffer, 'j'
|
23
|
-
assert_equal @vice.buffers[@buffer].cursor.line, 1
|
24
|
-
|
25
|
-
# go up one line
|
26
|
-
@parser.parsechar_command @vice, @buffer, 'k'
|
27
|
-
assert_equal @vice.buffers[@buffer].cursor.line, 0
|
28
|
-
|
29
|
-
# don't go up another line if no more lines exist
|
30
|
-
@parser.parsechar_command @vice, @buffer, 'k'
|
31
|
-
assert_equal @vice.buffers[@buffer].cursor.line, 0
|
32
|
-
end
|
33
|
-
|
34
|
-
# test that we enter insert mode after pressing i
|
35
|
-
def test_parsechar_command_i
|
36
|
-
assert_equal @vice.mode, :command
|
37
|
-
|
38
|
-
@parser.parsechar_command @vice, @buffer, 'i'
|
39
|
-
assert_equal @vice.mode, :insert
|
40
|
-
end
|
41
|
-
|
42
|
-
# test the I command
|
43
|
-
def test_parsechar_command_i_large
|
44
|
-
@vice.buffers[@buffer].setline 0, 'abcdefg'
|
45
|
-
@vice.buffers[@buffer].cursor.col = 4
|
46
|
-
|
47
|
-
@parser.parsechar_command @vice, @buffer, 'I'
|
48
|
-
assert_equal @vice.mode, :insert
|
49
|
-
assert_equal @vice.buffers[@buffer].cursor.col, 0
|
50
|
-
end
|
51
|
-
|
52
|
-
# test inserting characters
|
53
|
-
def test_insert_some_text
|
54
|
-
@vice.mode = :insert
|
55
|
-
@parser.parsechar_insert @vice, @buffer, 'h'
|
56
|
-
@parser.parsechar_insert @vice, @buffer, 'e'
|
57
|
-
@parser.parsechar_insert @vice, @buffer, 'y'
|
58
|
-
assert_equal @vice.buffers[@buffer].getline(0), 'hey'
|
59
|
-
end
|
60
|
-
|
61
|
-
# test inserting characters in a more random place
|
62
|
-
def test_parsechar_insert_in_the_middle
|
63
|
-
@vice.mode = :insert
|
64
|
-
@vice.buffers[@buffer].newline 0
|
65
|
-
@vice.buffers[@buffer].newline 0
|
66
|
-
@vice.buffers[@buffer].setline 1, 'é melhorser alegre'
|
67
|
-
assert_equal @vice.buffers[@buffer].buffer, ['', 'é melhorser alegre', '']
|
68
|
-
|
69
|
-
@vice.buffers[@buffer].cursor.line = 1
|
70
|
-
@vice.buffers[@buffer].cursor.col = 8
|
71
|
-
@parser.parsechar_insert @vice, @buffer, ' '
|
72
|
-
assert_equal @vice.buffers[@buffer].getline(1), 'é melhor ser alegre'
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_parsechar_insert_escape
|
76
|
-
@vice.mode = :insert
|
77
|
-
|
78
|
-
@parser.parsechar_insert @vice, @buffer, 27
|
79
|
-
assert_equal @vice.mode, :command
|
80
|
-
end
|
81
|
-
end
|