summaryrefslogtreecommitdiff
path: root/tests/unit/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-09-24 20:49:48 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-09-24 20:49:48 +0200
commit7d795c4d5301f265c077cad02f6803212a3db81b (patch)
treec03e8091559bb12ab20aec869b807a2a66aa2599 /tests/unit/core
parentdc5e334f5c8529d74c234a039dbc3d8dfd9199bd (diff)
downloadweechat-7d795c4d5301f265c077cad02f6803212a3db81b.zip
core: fix wrong results with the unary minus in calc expressions
Diffstat (limited to 'tests/unit/core')
-rw-r--r--tests/unit/core/test-core-calc.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/unit/core/test-core-calc.cpp b/tests/unit/core/test-core-calc.cpp
index 308708abe..ae0cea84e 100644
--- a/tests/unit/core/test-core-calc.cpp
+++ b/tests/unit/core/test-core-calc.cpp
@@ -53,13 +53,13 @@ TEST(CoreCalc, Expression)
WEE_CHECK_CALC("0", "-");
WEE_CHECK_CALC("0", "*");
WEE_CHECK_CALC("0", "/");
+ WEE_CHECK_CALC("0", "%");
WEE_CHECK_CALC("0", "0/0");
WEE_CHECK_CALC("0", "0//0");
WEE_CHECK_CALC("0", "0%0");
/* no operator */
WEE_CHECK_CALC("123", "123");
- WEE_CHECK_CALC("-2", "-2");
WEE_CHECK_CALC("1.5", "1.5");
/* addition */
@@ -71,6 +71,25 @@ TEST(CoreCalc, Expression)
WEE_CHECK_CALC("5", "8-3");
WEE_CHECK_CALC("-5", "3-8");
+ /* unary minus */
+ WEE_CHECK_CALC("0", "-0");
+ WEE_CHECK_CALC("-0.001", "-0.001");
+ WEE_CHECK_CALC("0", "(-0)");
+ WEE_CHECK_CALC("0", "0-0");
+ WEE_CHECK_CALC("-1", "-1");
+ WEE_CHECK_CALC("-2", "-1+-1");
+ WEE_CHECK_CALC("0", "-1+1");
+ WEE_CHECK_CALC("-2", "-3+1");
+ WEE_CHECK_CALC("-3", "1+-4");
+ WEE_CHECK_CALC("-4", "2*-2");
+ WEE_CHECK_CALC("-6", "-3*2");
+ WEE_CHECK_CALC("9", "-3*-3");
+ WEE_CHECK_CALC("-6", "3*(-2)");
+ WEE_CHECK_CALC("6", "-3*(-2)");
+ WEE_CHECK_CALC("12", "(-3)*(-4)");
+ WEE_CHECK_CALC("15", "(-3)*-5");
+ WEE_CHECK_CALC("9", "(-3)*(-4+1)");
+
/* multiplication */
WEE_CHECK_CALC("20", "10*2");
WEE_CHECK_CALC("-8", "-2*4");
@@ -86,6 +105,8 @@ TEST(CoreCalc, Expression)
/* modulo */
WEE_CHECK_CALC("4", "9%5");
WEE_CHECK_CALC("0.2", "9.2%3");
+ WEE_CHECK_CALC("-2", "-2%4");
+ WEE_CHECK_CALC("0", "-2%2");
/* multiple operators */
WEE_CHECK_CALC("11", "5+2*3");
@@ -105,6 +126,8 @@ TEST(CoreCalc, Expression)
WEE_CHECK_CALC("0", "1/123456789012");
/* expressions with parentheses */
+ WEE_CHECK_CALC("6", "((6))");
+ WEE_CHECK_CALC("-7.234", "((-7.234))");
WEE_CHECK_CALC("21", "(5+2)*3");
WEE_CHECK_CALC("3.15", "(1.5+2)*(1.8/2)");
WEE_CHECK_CALC("-1.26", "(1.5+2)*(1.8/(2-7))");