Add some priority spec
This commit is contained in:
parent
7efd578a9a
commit
01b610b146
12 changed files with 51 additions and 9 deletions
|
@ -20,7 +20,11 @@ module Mm2ep
|
||||||
class VarValue < TreeValue
|
class VarValue < TreeValue
|
||||||
def initialize(str, value)
|
def initialize(str, value)
|
||||||
@name = str
|
@name = str
|
||||||
@value = value
|
@value = case value
|
||||||
|
when /true/i then true
|
||||||
|
when /false/i then false
|
||||||
|
else value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def compute
|
def compute
|
||||||
|
@ -62,7 +66,10 @@ module Mm2ep
|
||||||
|
|
||||||
class BoolValue < TreeValue
|
class BoolValue < TreeValue
|
||||||
def initialize(str)
|
def initialize(str)
|
||||||
@value = str
|
@value = case str
|
||||||
|
when /true/i then true
|
||||||
|
when /false/i then false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def compute
|
def compute
|
||||||
|
@ -125,7 +132,7 @@ module Mm2ep
|
||||||
end
|
end
|
||||||
|
|
||||||
def compute
|
def compute
|
||||||
@lval.value.eql? @rval.value
|
@lval.value == @rval.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
1
spec/files/priority_not_and.txt
Normal file
1
spec/files/priority_not_and.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
NOT false AND NOT false
|
1
spec/files/priority_not_or.txt
Normal file
1
spec/files/priority_not_or.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
NOT true OR NOT true
|
1
spec/files/priority_or_and.txt
Normal file
1
spec/files/priority_or_and.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
false OR true AND false
|
1
spec/files/priority_or_and_or.txt
Normal file
1
spec/files/priority_or_and_or.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
false OR false AND true OR true
|
|
@ -1 +1 @@
|
||||||
truc_bidule and machin
|
truc_bidule AND machin
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
truc_bidule or machin
|
truc_bidule OR machin
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
NOT ( truc_bidule = true ) OR ( truc ) AND machin = false
|
|
|
@ -1 +0,0 @@
|
||||||
NOT ( truc_bidule = true ) OR ( true ) AND machin = false
|
|
|
@ -1 +0,0 @@
|
||||||
NOT true OR NOT false AND true OR false
|
|
34
spec/mm2ep_depend/priority_parser_spec.rb
Normal file
34
spec/mm2ep_depend/priority_parser_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'mm2ep_depend'
|
||||||
|
|
||||||
|
describe Mm2ep::Depend::Parser do
|
||||||
|
|
||||||
|
it 'has to do not before or' do
|
||||||
|
line = File.read(testfile('priority_not_or.txt')).delete("\n")
|
||||||
|
parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new)
|
||||||
|
token = parser.parse(line.chomp)
|
||||||
|
assert_equal(false, token.compute)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has to do not before and' do
|
||||||
|
line = File.read(testfile('priority_not_and.txt')).delete("\n")
|
||||||
|
parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new)
|
||||||
|
token = parser.parse(line.chomp)
|
||||||
|
assert_equal(true, token.compute)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has to do and before or' do
|
||||||
|
line = File.read(testfile('priority_or_and.txt')).delete("\n")
|
||||||
|
parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new)
|
||||||
|
token = parser.parse(line.chomp)
|
||||||
|
assert_equal(false, token.compute)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has to do and before or operators' do
|
||||||
|
line = File.read(testfile('priority_or_and_or.txt')).delete("\n")
|
||||||
|
parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new)
|
||||||
|
token = parser.parse(line.chomp)
|
||||||
|
assert_equal(true, token.compute)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -59,7 +59,7 @@ describe Mm2ep::Depend::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has to evaluate true OR true and return true' do
|
it 'has to evaluate true OR true and return true' do
|
||||||
line = File.read(testfile('simple_or_expr_string.txt')).delete("\n")
|
line = File.read(testfile('simple_expr_or_expr.txt')).delete("\n")
|
||||||
parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new)
|
parser = Mm2ep::Depend::Parser.new(Mm2ep::Depend::Lexer.new)
|
||||||
parser.names={'truc_bidule' => 'true',
|
parser.names={'truc_bidule' => 'true',
|
||||||
'machin' => 'true'
|
'machin' => 'true'
|
Loading…
Reference in a new issue