[gnome-calculator] Fixed bitshift precedence (#98)



commit 8492383ceb7b2c382677c4d64e86acb09ec46f14
Author: Robert Roth <robert roth off gmail com>
Date:   Wed Apr 3 08:13:37 2019 +0300

    Fixed bitshift precedence (#98)

 lib/equation-parser.vala |  2 +-
 tests/test-equation.vala | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/lib/equation-parser.vala b/lib/equation-parser.vala
index 71b53fdb..ea92d6e4 100644
--- a/lib/equation-parser.vala
+++ b/lib/equation-parser.vala
@@ -34,12 +34,12 @@ private enum Precedence
     NOT             = 6,
     FUNCTION        = 7,
     BOOLEAN         = 8,
+    SHIFT           = 8,
     PERCENTAGE      = 9,
     /* UNARY_MINUS, ROOT and POWER must have same precedence. */
     UNARY_MINUS     = 10,
     POWER           = 10,
     ROOT            = 10,
-    SHIFT           = 10,
     FACTORIAL       = 11,
     NUMBER_VARIABLE = 12,
     /* DEPTH should be always at the bottom. It stops node jumping off the current depth level. */
diff --git a/tests/test-equation.vala b/tests/test-equation.vala
index e1fa390d..e909a5df 100644
--- a/tests/test-equation.vala
+++ b/tests/test-equation.vala
@@ -673,6 +673,15 @@ private void test_equations ()
     //test ("¬¬10₂", "10₂", 0);
 }
 
+private void test_bit_shift ()
+{
+    number_base = 10;
+    test ("1«2", "4", 0);
+    test ("1«2»1«2", "8", 0);
+    test ("32»3", "4", 0);
+    test ("0x1 « 0x10", "65536", 0);
+}
+
 private void test_base_conversion ()
 {
     number_base = 10;
@@ -809,6 +818,7 @@ public int main (string[] args)
     test_base_conversion ();
     test_precedence ();
     test_custom_functions ();
+    test_bit_shift ();
 
     if (fail_count == 0)
         stdout.printf ("Passed all %i tests\n", pass_count);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]