2017-09-13 14:51:11 +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-20 13:44:55 +00:00
|
|
|
it 'has to find var and compute it to expr' do
|
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_var_expr.txt')).delete("\n")
|
|
|
|
parser.names = { 'a_girl_has_no_name' => 'true' }
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to find true boolean and compute it to expr' do
|
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_t_bool_expr.txt')).delete("\n")
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to find false boolean and compute it to expr' do
|
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_f_bool_expr.txt')).delete("\n")
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to find parenthesis expr and compute it to expr' do
|
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_parenthesis_expr.txt')).delete("\n")
|
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
2017-09-14 08:50:10 +00:00
|
|
|
it 'has to apply not on expr' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_not_expr.txt')).delete("\n")
|
2017-09-13 14:51:11 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
2017-09-14 08:50:10 +00:00
|
|
|
it 'has to evaluate eq with bool expr and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'character' => 'true' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate eq with bool expr and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_boolexpr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'character' => 'false' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate eq with number and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_number.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'nombre' => '10' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate eq with number and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_number.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'nombre' => '11' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate eq with string and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_string.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'Arya Stark' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate eq with string and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_eq_expr_string.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'Sansa Stark' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate true OR true and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'true',
|
|
|
|
'character' => 'true' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate true OR false and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'true',
|
|
|
|
'character' => 'false' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate false OR true and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'false',
|
|
|
|
'character' => 'true' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate false OR false and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_or_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'false',
|
|
|
|
'character' => 'false' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate true AND true and return true' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'true',
|
|
|
|
'character' => 'true' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(true, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate true AND false and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'true',
|
|
|
|
'character' => 'false' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate false AND true and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'false',
|
|
|
|
'character' => 'true' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has to evaluate false AND false and return false' do
|
2017-09-20 10:08:32 +00:00
|
|
|
line = File
|
|
|
|
.read(testfile('success_simple_expr_and_expr.txt')).delete("\n")
|
2017-09-20 10:40:56 +00:00
|
|
|
parser.names = { 'a_girl_has_no_name' => 'false',
|
|
|
|
'character' => 'false' }
|
2017-09-14 08:50:10 +00:00
|
|
|
token = parser.parse(line.chomp)
|
|
|
|
assert_equal(false, token.compute)
|
|
|
|
end
|
2017-09-13 14:51:11 +00:00
|
|
|
end
|