From 40be4077fe9a12c82777c0e2a737da9afe8cd219 Mon Sep 17 00:00:00 2001
From: Brendon <torre.brendon@gmail.com>
Date: Wed, 20 Sep 2017 15:44:55 +0200
Subject: [PATCH] Add some spec for simple expr (var, bool expr ) and change
 priority check

---
 spec/files/success_simple_f_bool_expr.txt     |  1 +
 .../files/success_simple_parenthesis_expr.txt |  1 +
 spec/files/success_simple_t_bool_expr.txt     |  1 +
 spec/files/success_simple_var_expr.txt        |  1 +
 spec/mm2ep_depend/priority_parser_spec.rb     | 18 +++++++++---
 spec/mm2ep_depend/simple_expr_parser_spec.rb  | 29 +++++++++++++++++++
 6 files changed, 47 insertions(+), 4 deletions(-)
 create mode 100644 spec/files/success_simple_f_bool_expr.txt
 create mode 100644 spec/files/success_simple_parenthesis_expr.txt
 create mode 100644 spec/files/success_simple_t_bool_expr.txt
 create mode 100644 spec/files/success_simple_var_expr.txt

diff --git a/spec/files/success_simple_f_bool_expr.txt b/spec/files/success_simple_f_bool_expr.txt
new file mode 100644
index 0000000..c508d53
--- /dev/null
+++ b/spec/files/success_simple_f_bool_expr.txt
@@ -0,0 +1 @@
+false
diff --git a/spec/files/success_simple_parenthesis_expr.txt b/spec/files/success_simple_parenthesis_expr.txt
new file mode 100644
index 0000000..1f1e63c
--- /dev/null
+++ b/spec/files/success_simple_parenthesis_expr.txt
@@ -0,0 +1 @@
+( true )
diff --git a/spec/files/success_simple_t_bool_expr.txt b/spec/files/success_simple_t_bool_expr.txt
new file mode 100644
index 0000000..27ba77d
--- /dev/null
+++ b/spec/files/success_simple_t_bool_expr.txt
@@ -0,0 +1 @@
+true
diff --git a/spec/files/success_simple_var_expr.txt b/spec/files/success_simple_var_expr.txt
new file mode 100644
index 0000000..c055200
--- /dev/null
+++ b/spec/files/success_simple_var_expr.txt
@@ -0,0 +1 @@
+a_girl_has_no_name
diff --git a/spec/mm2ep_depend/priority_parser_spec.rb b/spec/mm2ep_depend/priority_parser_spec.rb
index 878bc6e..f056523 100644
--- a/spec/mm2ep_depend/priority_parser_spec.rb
+++ b/spec/mm2ep_depend/priority_parser_spec.rb
@@ -12,27 +12,37 @@ describe Mm2ep::Depend::Parser do
     line = File
            .read(testfile('success_priority_not_or.txt')).delete("\n")
     token = parser.parse(line.chomp)
-    assert_equal(false, token.compute)
+    assert_equal('( NOT ( bool:true ) ) OR ( NOT ( bool:true ) )', token.to_s)
   end
 
   it 'has to do not before and' do
     line = File
            .read(testfile('success_priority_not_and.txt')).delete("\n")
     token = parser.parse(line.chomp)
-    assert_equal(true, token.compute)
+    assert_equal(
+      '( NOT ( bool:false ) ) AND ( NOT ( bool:false ) )',
+      token.to_s
+    )
   end
 
   it 'has to do and before or' do
     line = File
            .read(testfile('success_priority_or_and.txt')).delete("\n")
     token = parser.parse(line.chomp)
-    assert_equal(false, token.compute)
+    assert_equal(
+      '( bool:false ) OR ( ( bool:true ) AND ( bool:false ) )',
+      token.to_s
+    )
   end
 
   it 'has to do and before or operators' do
     line = File
            .read(testfile('success_priority_or_and_or.txt')).delete("\n")
     token = parser.parse(line.chomp)
-    assert_equal(true, token.compute)
+    assert_equal(
+      '( ( bool:false ) OR ( ( bool:false ) '\
+      'AND ( bool:true ) ) ) OR ( bool:true )',
+      token.to_s
+    )
   end
 end
diff --git a/spec/mm2ep_depend/simple_expr_parser_spec.rb b/spec/mm2ep_depend/simple_expr_parser_spec.rb
index a695e5f..71751a4 100644
--- a/spec/mm2ep_depend/simple_expr_parser_spec.rb
+++ b/spec/mm2ep_depend/simple_expr_parser_spec.rb
@@ -8,6 +8,35 @@ describe Mm2ep::Depend::Parser do
     )
   end
 
+  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
+
   it 'has to apply not on expr' do
     line = File
            .read(testfile('success_simple_not_expr.txt')).delete("\n")