2017-09-20 12:08:32 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'mm2ep_depend'
|
|
|
|
|
|
|
|
describe Mm2ep::Depend::Lexer do
|
|
|
|
let(:lexer) do
|
|
|
|
Mm2ep::Depend::Lexer.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize AND operator' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = 'AND'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('AND_OP', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize EQ operator' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = '='
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('EQ_OP', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize OR operator' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = 'OR'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('OR_OP', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize NOT operator' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = 'NOT'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('NOT_OP', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize false boolean' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = 'false False'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('F_BOOL', lexer.next.type.to_s)
|
|
|
|
assert_equal('F_BOOL', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize true boolean' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = 'true True'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('T_BOOL', lexer.next.type.to_s)
|
|
|
|
assert_equal('T_BOOL', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize left parenthesis' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = '('
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('L_PAR', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize right parenthesis' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = ')'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('R_PAR', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize number' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = '7'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('NUMBER', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize string' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = %("Arya Stark")
|
2017-09-20 12:08:32 +02:00
|
|
|
lexer.input(line.chomp)
|
|
|
|
assert_equal('STRING', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize var' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = 'character'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('VAR', lexer.next.type.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to recognize illegal character and replace them with erase them' do
|
2019-12-21 16:55:15 +01:00
|
|
|
line = '?'
|
|
|
|
lexer.input(line)
|
2017-09-20 12:08:32 +02:00
|
|
|
assert_equal('', lexer.next.to_s)
|
|
|
|
end
|
|
|
|
end
|