require_relative '../../spec_helper' require 'ios_parser' require 'ios_parser/lexer' module IOSParser describe Lexer do describe '#call' do subject { klass.new.call(input) } let(:subject_pure) do IOSParser::PureLexer.new.call(input) end context 'indented region' do let(:input) { <<-END.unindent } policy-map mypolicy_in class myservice_service police 300000000 1000000 exceed-action policed-dscp-transmit set dscp cs1 class other_service police 600000000 1000000 exceed-action policed-dscp-transmit set dscp cs2 END let(:output) do ['policy-map', 'mypolicy_in', :EOL, :INDENT, 'class', 'myservice_service', :EOL, :INDENT, 'police', 300_000_000, 1_000_000, 'exceed-action', 'policed-dscp-transmit', :EOL, :INDENT, 'set', 'dscp', 'cs1', :EOL, :DEDENT, :DEDENT, 'class', 'other_service', :EOL, :INDENT, 'police', 600_000_000, 1_000_000, 'exceed-action', 'policed-dscp-transmit', :EOL, :INDENT, 'set', 'dscp', 'cs2', :EOL, :DEDENT, :DEDENT, :DEDENT] end subject { klass.new.call(input).map(&:last) } it('enclosed in symbols') { should == output } it('enclosed in symbols (using the pure ruby lexer)') do expect(subject_pure.map(&:last)).to eq output end end context 'ASR indented regions' do context 'indented region' do let(:input) { <<-END.unindent } router static vrf MGMT address-family ipv4 unicast 0.0.0.0/0 1.2.3.4 ! ! ! router ospf 12345 nsr END let(:expectation) do ['router', 'static', :EOL, :INDENT, 'vrf', 'MGMT', :EOL, :INDENT, 'address-family', 'ipv4', 'unicast', :EOL, :INDENT, '0.0.0.0/0', '1.2.3.4', :EOL, :DEDENT, :DEDENT, :DEDENT, 'router', 'ospf', 12_345, :EOL, :INDENT, 'nsr', :EOL, :DEDENT] end it 'pure' do tokens = IOSParser::PureLexer.new.call(input) expect(tokens.map(&:last)).to eq expectation end # it 'pure' do it 'default' do tokens = IOSParser.lexer.new.call(input) expect(tokens.map(&:last)).to eq expectation end # it 'c' do end # context 'indented region' do end # context 'ASR indented regions' do context 'banners' do let(:input) do <<-END.unindent banner foobar ^ asdf 1234 9786 asdf line 2 line 3 ^ END end let(:output) do [[0, 'banner'], [7, 'foobar'], [14, :BANNER_BEGIN], [16, "asdf 1234 9786 asdf\nline 2\nline 3\n "], [52, :BANNER_END], [53, :EOL]] end it('tokenized and enclosed in symbols') { should == output } it('tokenized and enclodes in symbols (using the pure ruby lexer)') do expect(subject_pure).to eq output end end context 'complex banner' do let(:input) do text_fixture('complex_banner') end let(:output) do content = text_fixture('complex_banner').lines[1..-2].join ['banner', 'exec', :BANNER_BEGIN, content, :BANNER_END, :EOL] end it { expect(subject.map(&:last)).to eq output } it { expect(subject_pure.map(&:last)).to eq output } end context 'complex eos banner' do let(:input) { "banner motd\n'''\nEOF\n" } let(:output) do content = input.lines[1..-2].join ['banner', 'motd', :BANNER_BEGIN, content, :BANNER_END, :EOL] end it { expect(subject.map(&:last)).to eq output } it { expect(subject_pure.map(&:last)).to eq output } end context 'decimal number' do let(:input) { 'boson levels at 93.2' } let(:output) { ['boson', 'levels', 'at', 93.2] } subject { klass.new.call(input).map(&:last) } it('converts to Float') { should == output } end context 'cryptographic certificate' do let(:input) do <