]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: test-lua - Use bool for expected_isnum in check_tointegerx_compat
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 10 May 2021 16:23:48 +0000 (19:23 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 12 May 2021 09:06:46 +0000 (09:06 +0000)
src/lib-lua/test-lua.c

index 59a669d2ef68673319486d055a9f7691c1a212b5..acf58244f2a9e3e5a4fe29714bc14c9bdc218dc8 100644 (file)
@@ -356,7 +356,7 @@ static void test_tls(void)
 }
 
 /* check lua_tointegerx against top-of-stack item */
-static void check_tointegerx_compat(lua_State *L, int expected_isnum,
+static void check_tointegerx_compat(lua_State *L, bool expected_isnum,
                                    bool expected_isint,
                                    lua_Integer expected_value)
 {
@@ -364,7 +364,7 @@ static void check_tointegerx_compat(lua_State *L, int expected_isnum,
        int isnum;
 
        value = lua_tointegerx(L, -1, &isnum);
-       test_assert(isnum == expected_isnum);
+       test_assert((isnum == 1) == expected_isnum);
 
        if (isnum == 1)
                test_assert(value == expected_value);
@@ -379,36 +379,36 @@ static void test_compat_tointegerx_and_isinteger(void)
        static const struct {
                const char *input;
                lua_Integer output;
-               int isnum;
+               bool isnum;
        } str_tests[] = {
-               { "-1", -1, 1 },
-               { "0", 0, 1 },
-               { "1", 1, 1 },
-               { "-2147483648", -2147483648, 1 },
-               { "2147483647", 2147483647, 1 },
-               { "0x123", 0x123, 1 },
-               { "0123", 123, 1 }, /* NB: lua doesn't use leading zero for octal */
-               { "0xabcdef", 0xabcdef, 1 },
-               { "0xabcdefg", 0, 0 },
-               { "abc", 0, 0 },
-               { "1.525", 0, 0 },
-               { "52.51", 0, 0 },
+               { "-1", -1, TRUE },
+               { "0", 0, TRUE },
+               { "1", 1, TRUE },
+               { "-2147483648", -2147483648, TRUE },
+               { "2147483647", 2147483647, TRUE },
+               { "0x123", 0x123, TRUE },
+               { "0123", 123, TRUE }, /* NB: lua doesn't use leading zero for octal */
+               { "0xabcdef", 0xabcdef, TRUE },
+               { "0xabcdefg", 0, FALSE },
+               { "abc", 0, FALSE },
+               { "1.525", 0, FALSE },
+               { "52.51", 0, FALSE },
        };
        static const struct {
                lua_Number input;
                lua_Integer output;
-               int isnum;
+               bool isnum;
        } num_tests[] = {
-               { -1, -1, 1 },
-               { 0, 0, 1 },
-               { 1, 1, 1 },
-               { INT_MIN, INT_MIN, 1 },
-               { INT_MAX, INT_MAX, 1 },
-               { 1.525, 0, 0 },
-               { 52.51, 0, 0 },
-               { NAN, 0, 0 },
-               { +INFINITY, 0, 0},
-               { -INFINITY, 0, 0},
+               { -1, -1, TRUE },
+               { 0, 0, TRUE },
+               { 1, 1, TRUE },
+               { INT_MIN, INT_MIN, TRUE },
+               { INT_MAX, INT_MAX, TRUE },
+               { 1.525, 0, FALSE },
+               { 52.51, 0, FALSE },
+               { NAN, 0, FALSE },
+               { +INFINITY, 0, FALSE },
+               { -INFINITY, 0, FALSE },
        };
        static const struct {
                lua_Integer input;
@@ -441,7 +441,7 @@ static void test_compat_tointegerx_and_isinteger(void)
 #if LUA_VERSION_NUM == 503
                isint = FALSE;
 #else
-               isint = (num_tests[i].isnum == 1);
+               isint = num_tests[i].isnum;
 #endif
 
                lua_pushnumber(script->L, num_tests[i].input);
@@ -452,7 +452,7 @@ static void test_compat_tointegerx_and_isinteger(void)
 
        for (i = 0; i < N_ELEMENTS(int_tests); i++) {
                lua_pushinteger(script->L, int_tests[i].input);
-               check_tointegerx_compat(script->L, 1, TRUE,
+               check_tointegerx_compat(script->L, TRUE, TRUE,
                                        int_tests[i].output);
        }