2017-09-15 10:52:29 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'mm2ep_depend'
|
|
|
|
|
|
|
|
describe Mm2ep::Depend::Parser do
|
2017-09-20 10:08:32 +00:00
|
|
|
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
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
|
2017-09-15 10:52:29 +00:00
|
|
|
parser.names = {}
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
token.errors
|
|
|
|
.select do |elem|
|
|
|
|
elem.is_a? Mm2ep::Depend::VarNotDefined
|
|
|
|
end.size.must_equal 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to report vars which are not defined' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
|
2017-09-15 10:52:29 +00:00
|
|
|
parser.names = {}
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
token.errors
|
|
|
|
.select do |elem|
|
|
|
|
elem.is_a? Mm2ep::Depend::VarNotDefined
|
|
|
|
end.size.must_equal 2
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to report invalid_grammar' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('error_grammar_partially_invalid.txt')).delete("\n")
|
2017-09-15 10:52:29 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => true, 'character' => 'Arya Stark' }
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
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
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('error_grammar_completely_invalid.txt')).delete("\n")
|
2017-09-15 10:52:29 +00:00
|
|
|
parser.names = {}
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
parser.check_grammar line, token
|
|
|
|
assert_nil token
|
|
|
|
end
|
|
|
|
end
|