File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change 1
1
class Parser
2
- attr_reader :lines
3
-
4
2
def initialize ( input )
5
- input = input . gsub ( %r{//.*$} , '' ) . strip
6
- @lines = input . lines
3
+ @lines = split_lines ( input )
7
4
end
8
5
9
6
def has_more_commands?
10
- !@ lines. empty?
7
+ !lines . empty?
11
8
end
12
9
13
10
def advance
14
- @lines . shift
11
+ lines . shift
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :lines
17
+
18
+ def split_lines ( input )
19
+ input
20
+ . lines
21
+ . map { |line | line . sub ( %r{//.*$} , '' ) . strip }
22
+ . reject ( &:empty? )
15
23
end
16
24
end
Original file line number Diff line number Diff line change 102
102
expect ( parser . has_more_commands? ) . to be_falsy
103
103
end
104
104
end
105
+
106
+ context 'with interleaved comments' do
107
+ let ( :input ) do
108
+ <<-eop
109
+ @R0
110
+ // An interleaved comment
111
+ D=M
112
+ eop
113
+ end
114
+
115
+ it 'leaves no more commands' do
116
+ expect ( parser . has_more_commands? ) . to be_truthy
117
+ parser . advance
118
+ expect ( parser . has_more_commands? ) . to be_truthy
119
+ parser . advance
120
+ expect ( parser . has_more_commands? ) . to be_falsy
121
+ end
122
+ end
105
123
end
106
124
107
125
describe '#command_type' do
You can’t perform that action at this time.
0 commit comments