blob: bc2aec449836d9dd4dd6000b81c9974d03012439 (
plain)
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
|
RSpec.describe CodeRay::Scanners::SimpleScanner do
let(:scanner) { described_class }
describe '#scan_tokens_code' do
subject { scanner.send :scan_tokens_code }
it 'throws an error' do
expect { subject }.to raise_error(CodeRay::Scanners::SimpleScannerDSL::NoStatesError)
end
end
describe 'with one state' do
let(:scanner) do
Class.new described_class do
state :somepony do
on %r/rainbow/, :dash
end
end
end
describe '#scan_tokens_code' do
subject { scanner.send :scan_tokens_code }
it 'returns an scanner with one states' do
is_expected.to eq <<-RUBY
state = options[:state] || @state
states = [state]
until eos?
case state
when :somepony
if match = scan(/rainbow/)
encoder.text_token match, :dash
else
encoder.text_token getch, :error
end
else
raise_inspect 'Unknown state: %p' % [state], encoder
end
end
@state = state if options[:keep_state]
close_groups(encoder, states)
encoder
RUBY
end
end
end
end
|