Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 518e240

Browse files
[[ cpptest ]] Expand lextable test to cover all the tables
1 parent 4f02ce3 commit 518e240

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

engine/src/lextable.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ static LT unit_table[] =
22022202
{"codepoint", TT_UNDEFINED, FU_CODEPOINT},
22032203
{"codepoints", TT_UNDEFINED, FU_CODEPOINT},
22042204
{"codeunit", TT_UNDEFINED, FU_CODEUNIT},
2205-
{"codeunit", TT_UNDEFINED, FU_CODEUNIT},
2205+
{"codeunits", TT_UNDEFINED, FU_CODEUNIT},
22062206
{"element", TT_UNDEFINED, FU_ELEMENT},
22072207
{"int1", TT_UNDEFINED, FU_INT1},
22082208
{"int1s", TT_UNDEFINED, FU_INT1},
@@ -2361,6 +2361,7 @@ LT *table_pointers[] =
23612361
visual_table,
23622362
server_table
23632363
};
2364+
extern const uint4 table_pointers_size = ELEMENTS(table_pointers);
23642365

23652366
uint2 table_sizes[] =
23662367
{
@@ -2399,3 +2400,4 @@ uint2 table_sizes[] =
23992400
ELEMENTS(visual_table),
24002401
ELEMENTS(server_table),
24012402
};
2403+
extern const uint4 table_sizes_size = ELEMENTS(table_sizes);

engine/test/test_lextable.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,50 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2020
#include "parsedef.h"
2121
#include "scriptpt.h"
2222

23+
TEST(lextable, constant_table)
24+
//
25+
// Checks that the entries of constant_table are in alphabetical order.
26+
//
27+
{
28+
extern Cvalue constant_table[];
29+
extern const uint4 constant_table_size;
30+
31+
ASSERT_GE(constant_table_size, 1);
32+
33+
for(uint4 i = 0; i < constant_table_size - 1; i++) {
34+
EXPECT_LT(strcmp(constant_table[i].token, constant_table[i+1].token), 0)
35+
<< "\"" << constant_table[i+1].token << "\""
36+
<< " comes before "
37+
<< "\"" << constant_table[i].token << "\"";
38+
}
39+
}
40+
2341

24-
TEST(lextable, factor_table)
42+
TEST(lextable, table_pointer)
2543
//
2644
// Checks that the entries of factor_table are in alphabetical order.
2745
//
2846
{
29-
extern LT factor_table[];
30-
extern const uint4 factor_table_size;
47+
extern LT *table_pointers[];
48+
extern const uint4 table_pointers_size;
3149

32-
ASSERT_GE(factor_table_size, 1);
50+
extern uint2 table_sizes[];
51+
extern const uint4 table_sizes_size;
3352

34-
for(uint4 i = 0; i < factor_table_size - 1; i++) {
35-
EXPECT_LT(strcmp(factor_table[i].token, factor_table[i+1].token), 0)
36-
<< "\"" << factor_table[i+1].token << "\""
37-
<< " comes before "
38-
<< "\"" << factor_table[i].token << "\"";
53+
ASSERT_EQ(table_pointers_size, table_sizes_size);
54+
55+
for (uint4 i = 0; i < table_pointers_size; i++) {
56+
57+
LT* table = table_pointers[i];
58+
const uint4 table_size = table_sizes[i];
59+
60+
ASSERT_GE(table_size, 1);
61+
62+
for (uint4 j = 0; j < table_size - 1; j++) {
63+
EXPECT_LT(strcmp(table[j].token, table[j+1].token), 0)
64+
<< "\"" << table[j+1].token << "\""
65+
<< " comes before "
66+
<< "\"" << table[j].token << "\"";
67+
}
3968
}
4069
}

0 commit comments

Comments
 (0)