Add verification to missing var declaration in spec to know which declaration is missing

This commit is contained in:
Brendon 2017-09-20 12:40:56 +02:00
parent d02ecf53b0
commit b6f535abc0
7 changed files with 35 additions and 37 deletions

View file

@ -1 +1 @@
truc_bidule = true character = true

View file

@ -1 +1 @@
truc_bidule = 10 nombre = 10

View file

@ -1 +1 @@
truc_bidule = "test" a_girl_has_no_name = "Arya Stark"

View file

@ -1 +1 @@
truc_bidule AND machin a_girl_has_no_name AND character

View file

@ -1 +1 @@
truc_bidule OR machin a_girl_has_no_name OR character

View file

@ -13,21 +13,19 @@ describe Mm2ep::Depend::Parser do
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n") .read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
parser.names = {} parser.names = {}
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
token.errors errors = token.errors.select { |el| el.is_a? Mm2ep::Depend::VarNotDefined }
.select do |elem| errors.size.must_equal 1
elem.is_a? Mm2ep::Depend::VarNotDefined errors[0].var.must_equal 'character'
end.size.must_equal 1
end end
it 'has to report vars which are not defined' do it 'has to report vars which are not defined' do
line = File line = File.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = {} parser.names = {}
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
token.errors errors = token.errors.select { |el| el.is_a? Mm2ep::Depend::VarNotDefined }
.select do |elem| errors.size.must_equal 2
elem.is_a? Mm2ep::Depend::VarNotDefined errors[0].var.must_equal 'a_girl_has_no_name'
end.size.must_equal 2 errors[1].var.must_equal 'character'
end end
it 'has to report invalid_grammar' do it 'has to report invalid_grammar' do

View file

@ -18,7 +18,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with bool expr and return true' do it 'has to evaluate eq with bool expr and return true' do
line = File line = File
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n") .read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true' } parser.names = { 'character' => 'true' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -26,7 +26,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with bool expr and return false' do it 'has to evaluate eq with bool expr and return false' do
line = File line = File
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n") .read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false' } parser.names = { 'character' => 'false' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end
@ -34,7 +34,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with number and return true' do it 'has to evaluate eq with number and return true' do
line = File line = File
.read(testfile('success_simple_eq_expr_number.txt')).delete("\n") .read(testfile('success_simple_eq_expr_number.txt')).delete("\n")
parser.names = { 'truc_bidule' => '10' } parser.names = { 'nombre' => '10' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -42,7 +42,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with number and return false' do it 'has to evaluate eq with number and return false' do
line = File line = File
.read(testfile('success_simple_eq_expr_number.txt')).delete("\n") .read(testfile('success_simple_eq_expr_number.txt')).delete("\n")
parser.names = { 'truc_bidule' => '11' } parser.names = { 'nombre' => '11' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end
@ -50,7 +50,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with string and return true' do it 'has to evaluate eq with string and return true' do
line = File line = File
.read(testfile('success_simple_eq_expr_string.txt')).delete("\n") .read(testfile('success_simple_eq_expr_string.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'test' } parser.names = { 'a_girl_has_no_name' => 'Arya Stark' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -58,7 +58,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with string and return false' do it 'has to evaluate eq with string and return false' do
line = File line = File
.read(testfile('success_simple_eq_expr_string.txt')).delete("\n") .read(testfile('success_simple_eq_expr_string.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'tes' } parser.names = { 'a_girl_has_no_name' => 'Sansa Stark' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end
@ -66,8 +66,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true OR true and return true' do it 'has to evaluate true OR true and return true' do
line = File line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n") .read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true', parser.names = { 'a_girl_has_no_name' => 'true',
'machin' => 'true' } 'character' => 'true' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -75,8 +75,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true OR false and return true' do it 'has to evaluate true OR false and return true' do
line = File line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n") .read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true', parser.names = { 'a_girl_has_no_name' => 'true',
'machin' => 'false' } 'character' => 'false' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -84,8 +84,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false OR true and return true' do it 'has to evaluate false OR true and return true' do
line = File line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n") .read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false', parser.names = { 'a_girl_has_no_name' => 'false',
'machin' => 'true' } 'character' => 'true' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -93,8 +93,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false OR false and return false' do it 'has to evaluate false OR false and return false' do
line = File line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n") .read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false', parser.names = { 'a_girl_has_no_name' => 'false',
'machin' => 'false' } 'character' => 'false' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end
@ -102,8 +102,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true AND true and return true' do it 'has to evaluate true AND true and return true' do
line = File line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n") .read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true', parser.names = { 'a_girl_has_no_name' => 'true',
'machin' => 'true' } 'character' => 'true' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(true, token.compute) assert_equal(true, token.compute)
end end
@ -111,8 +111,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true AND false and return false' do it 'has to evaluate true AND false and return false' do
line = File line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n") .read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true', parser.names = { 'a_girl_has_no_name' => 'true',
'machin' => 'false' } 'character' => 'false' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end
@ -120,8 +120,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false AND true and return false' do it 'has to evaluate false AND true and return false' do
line = File line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n") .read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false', parser.names = { 'a_girl_has_no_name' => 'false',
'machin' => 'true' } 'character' => 'true' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end
@ -129,8 +129,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false AND false and return false' do it 'has to evaluate false AND false and return false' do
line = File line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n") .read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false', parser.names = { 'a_girl_has_no_name' => 'false',
'machin' => 'false' } 'character' => 'false' }
token = parser.parse(line.chomp) token = parser.parse(line.chomp)
assert_equal(false, token.compute) assert_equal(false, token.compute)
end end