-
Notifications
You must be signed in to change notification settings - Fork 11
/
buffer.rb
142 lines (113 loc) · 4.57 KB
/
buffer.rb
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
require_relative '../preparation'
describe 'A Diakonos user can' do
before do
@d = $diakonos
@b = @d.open_file( SAMPLE_FILE )
cursor_should_be_at 0,0
end
after do
@d.close_buffer @b, to_all: Diakonos::CHOICE_NO_TO_ALL
end
it 'can close a buffer' do
name = @d.buffer_current.name
n = @d.buffers.size
n.should > 0
@d.buffers.map(&:name).should.include name
@d.close_buffer
@d.buffers.size.should.equal n-1
@d.buffer_current.name.should.not.equal name
@d.buffers.map(&:name).should.not.include name
end
it 'see nothing untoward happen after attempting to open ""' do
$keystrokes = [ Diakonos::ENTER ]
lambda {
@d.open_file_ask
}.should.not.raise Exception
end
it 'open a file at a specific line number' do
@b = @d.open_file( "#{SAMPLE_FILE_LONGER}:45" )
cursor_should_be_at 44, 0
@d.close_buffer @b, to_all: Diakonos::CHOICE_NO_TO_ALL
@b = @d.open_file( "#{SAMPLE_FILE_LONGER}:50:" )
cursor_should_be_at 49, 0
@d.close_buffer @b, to_all: Diakonos::CHOICE_NO_TO_ALL
@b = @d.open_file( "#{SAMPLE_FILE_LONGER}:54: in `block in methodname'" )
cursor_should_be_at 53, 0
@d.close_buffer @b, to_all: Diakonos::CHOICE_NO_TO_ALL
@b = @d.open_file( " from #{SAMPLE_FILE_LONGER}:57: in `block in methodname'" )
cursor_should_be_at 56, 0
@d.close_buffer @b, to_all: Diakonos::CHOICE_NO_TO_ALL
@b = @d.open_file( %{ File "#{SAMPLE_FILE_LONGER}", line 55, in decoration} )
cursor_should_be_at 54, 0
@d.close_buffer @b, to_all: Diakonos::CHOICE_NO_TO_ALL
@b = @d.open_file( " at #{SAMPLE_FILE_LONGER} line 61" )
cursor_should_be_at 60, 0
end
it 'start up Diakonos and open a file at a specific line' do
d2 = Diakonos::Diakonos.new [ '-e', 'quit', '--test', "#{SAMPLE_FILE_LONGER}:45" ]
d2.start
@b = d2.buffer_current
cursor_should_be_at 44, 0
end
it 'renumber a buffer' do
@d.open_file SAMPLE_FILE_LONGER
@d.open_file SAMPLE_FILE_C
numbered_buffer_should_be_named 2, 'sample-file.rb'
numbered_buffer_should_be_named 3, 'longer-sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.c'
@d.switch_to_buffer_number 2
name = File.basename( @d.buffer_current.name )
name.should.equal 'sample-file.rb'
@d.renumber_buffer 4
name = File.basename( @d.buffer_current.name )
name.should.equal 'sample-file.rb'
numbered_buffer_should_be_named 2, 'longer-sample-file.rb'
numbered_buffer_should_be_named 3, 'sample-file.c'
numbered_buffer_should_be_named 4, 'sample-file.rb'
@d.switch_to_buffer_number 3
name = File.basename( @d.buffer_current.name )
name.should.equal 'sample-file.c'
@d.renumber_buffer 2
name = File.basename( @d.buffer_current.name )
name.should.equal 'sample-file.c'
numbered_buffer_should_be_named 2, 'sample-file.c'
numbered_buffer_should_be_named 3, 'longer-sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.rb'
@d.switch_to_buffer_number 2
# Switch twice because of Diakonos' behaviour of switching to previous
# buffer when trying to switching to the current buffer.
@d.switch_to_buffer_number 2
name = File.basename( @d.buffer_current.name )
name.should.equal 'sample-file.c'
@d.renumber_buffer 2
numbered_buffer_should_be_named 2, 'sample-file.c'
numbered_buffer_should_be_named 3, 'longer-sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.rb'
name = File.basename( @d.buffer_current.name )
name.should.equal 'sample-file.c'
@d.renumber_buffer 5
numbered_buffer_should_be_named 2, 'longer-sample-file.rb'
numbered_buffer_should_be_named 3, 'sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.c'
@d.renumber_buffer 99
numbered_buffer_should_be_named 2, 'longer-sample-file.rb'
numbered_buffer_should_be_named 3, 'sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.c'
@d.renumber_buffer 1
numbered_buffer_should_be_named 1, 'sample-file.c'
numbered_buffer_should_be_named 3, 'longer-sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.rb'
should.raise do
@d.renumber_buffer 0
end
numbered_buffer_should_be_named 1, 'sample-file.c'
numbered_buffer_should_be_named 3, 'longer-sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.rb'
should.raise do
@d.renumber_buffer -1
end
numbered_buffer_should_be_named 1, 'sample-file.c'
numbered_buffer_should_be_named 3, 'longer-sample-file.rb'
numbered_buffer_should_be_named 4, 'sample-file.rb'
end
end