namarara/spec/mm2ep_depend/parser_spec.rb

49 lines
1.4 KiB
Ruby
Raw Normal View History

2017-09-15 10:52:29 +00:00
require 'spec_helper'
require 'mm2ep_depend'
describe Mm2ep::Depend::Parser do
let(:parser) do
Mm2ep::Depend::Parser.new(
Mm2ep::Depend::Lexer.new
)
end
2017-09-15 10:52:29 +00:00
it 'has to report var which is not defined' do
2019-12-21 15:55:15 +00:00
line = 'character = true'
2017-09-15 10:52:29 +00:00
parser.names = {}
2019-12-21 15:55:15 +00:00
token = parser.parse(line)
errors = token.errors.select { |el| el.is_a? Mm2ep::Depend::VarNotDefined }
errors.size.must_equal 1
errors[0].var.must_equal 'character'
2017-09-15 10:52:29 +00:00
end
it 'has to report vars which are not defined' do
2019-12-21 15:55:15 +00:00
line = 'a_girl_has_no_name AND character'
2017-09-15 10:52:29 +00:00
parser.names = {}
2019-12-21 15:55:15 +00:00
token = parser.parse(line)
errors = token.errors.select { |el| el.is_a? Mm2ep::Depend::VarNotDefined }
errors.size.must_equal 2
errors[0].var.must_equal 'a_girl_has_no_name'
errors[1].var.must_equal 'character'
2017-09-15 10:52:29 +00:00
end
it 'has to report invalid_grammar' do
2019-12-21 15:55:15 +00:00
line = '( a_girl_has_no_name = true ) ' \
'ANDAND ( character = "Arya Stark" ) OR false AND true'
2017-09-15 10:52:29 +00:00
parser.names = { 'a_girl_has_no_name' => true, 'character' => 'Arya Stark' }
2019-12-21 15:55:15 +00:00
token = parser.parse(line)
2017-09-15 10:52:29 +00:00
parser.check_grammar line, token
token.errors.select do |elem|
elem.is_a? Mm2ep::Depend::InvalidGrammar
end.size.must_equal 1
end
it 'has to be nil when grammar is completely invalid' do
2019-12-21 15:55:15 +00:00
line = 'false = "Arya"'
2017-09-15 10:52:29 +00:00
parser.names = {}
2019-12-21 15:55:15 +00:00
token = parser.parse(line)
2017-09-15 10:52:29 +00:00
parser.check_grammar line, token
assert_nil token
end
end