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")
parser.names = {}
token = parser.parse(line.chomp)
token.errors
.select do |elem|
elem.is_a? Mm2ep::Depend::VarNotDefined
end.size.must_equal 1
errors = token.errors.select { |el| el.is_a? Mm2ep::Depend::VarNotDefined }
errors.size.must_equal 1
errors[0].var.must_equal 'character'
end
it 'has to report vars which are not defined' do
line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
line = File.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = {}
token = parser.parse(line.chomp)
token.errors
.select do |elem|
elem.is_a? Mm2ep::Depend::VarNotDefined
end.size.must_equal 2
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'
end
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
line = File
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true' }
parser.names = { 'character' => 'true' }
token = parser.parse(line.chomp)
assert_equal(true, token.compute)
end
@ -26,7 +26,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with bool expr and return false' do
line = File
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false' }
parser.names = { 'character' => 'false' }
token = parser.parse(line.chomp)
assert_equal(false, token.compute)
end
@ -34,7 +34,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with number and return true' do
line = File
.read(testfile('success_simple_eq_expr_number.txt')).delete("\n")
parser.names = { 'truc_bidule' => '10' }
parser.names = { 'nombre' => '10' }
token = parser.parse(line.chomp)
assert_equal(true, token.compute)
end
@ -42,7 +42,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with number and return false' do
line = File
.read(testfile('success_simple_eq_expr_number.txt')).delete("\n")
parser.names = { 'truc_bidule' => '11' }
parser.names = { 'nombre' => '11' }
token = parser.parse(line.chomp)
assert_equal(false, token.compute)
end
@ -50,7 +50,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with string and return true' do
line = File
.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)
assert_equal(true, token.compute)
end
@ -58,7 +58,7 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate eq with string and return false' do
line = File
.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)
assert_equal(false, token.compute)
end
@ -66,8 +66,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true OR true and return true' do
line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true',
'machin' => 'true' }
parser.names = { 'a_girl_has_no_name' => 'true',
'character' => 'true' }
token = parser.parse(line.chomp)
assert_equal(true, token.compute)
end
@ -75,8 +75,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true OR false and return true' do
line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true',
'machin' => 'false' }
parser.names = { 'a_girl_has_no_name' => 'true',
'character' => 'false' }
token = parser.parse(line.chomp)
assert_equal(true, token.compute)
end
@ -84,8 +84,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false OR true and return true' do
line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false',
'machin' => 'true' }
parser.names = { 'a_girl_has_no_name' => 'false',
'character' => 'true' }
token = parser.parse(line.chomp)
assert_equal(true, token.compute)
end
@ -93,8 +93,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false OR false and return false' do
line = File
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false',
'machin' => 'false' }
parser.names = { 'a_girl_has_no_name' => 'false',
'character' => 'false' }
token = parser.parse(line.chomp)
assert_equal(false, token.compute)
end
@ -102,8 +102,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true AND true and return true' do
line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true',
'machin' => 'true' }
parser.names = { 'a_girl_has_no_name' => 'true',
'character' => 'true' }
token = parser.parse(line.chomp)
assert_equal(true, token.compute)
end
@ -111,8 +111,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate true AND false and return false' do
line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'true',
'machin' => 'false' }
parser.names = { 'a_girl_has_no_name' => 'true',
'character' => 'false' }
token = parser.parse(line.chomp)
assert_equal(false, token.compute)
end
@ -120,8 +120,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false AND true and return false' do
line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false',
'machin' => 'true' }
parser.names = { 'a_girl_has_no_name' => 'false',
'character' => 'true' }
token = parser.parse(line.chomp)
assert_equal(false, token.compute)
end
@ -129,8 +129,8 @@ describe Mm2ep::Depend::Parser do
it 'has to evaluate false AND false and return false' do
line = File
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
parser.names = { 'truc_bidule' => 'false',
'machin' => 'false' }
parser.names = { 'a_girl_has_no_name' => 'false',
'character' => 'false' }
token = parser.parse(line.chomp)
assert_equal(false, token.compute)
end