forked from github/server
test suite for the crazy stuff that umlaut.c does.
This commit is contained in:
parent
2638f42eca
commit
f8cadfebee
|
@ -5,8 +5,9 @@
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
|
||||||
#include <util/base36_test.c>
|
#include <util/base36_test.c>
|
||||||
#include <util/quicklist_test.c>
|
|
||||||
#include <util/functions_test.c>
|
#include <util/functions_test.c>
|
||||||
|
#include <util/quicklist_test.c>
|
||||||
|
#include <util/umlaut_test.c>
|
||||||
#include <kernel/move_test.c>
|
#include <kernel/move_test.c>
|
||||||
#include <kernel/spell_test.c>
|
#include <kernel/spell_test.c>
|
||||||
#include <kernel/curse_test.c>
|
#include <kernel/curse_test.c>
|
||||||
|
@ -38,6 +39,7 @@ int RunAllTests(void)
|
||||||
CuSuiteAddSuite(suite, get_base36_suite());
|
CuSuiteAddSuite(suite, get_base36_suite());
|
||||||
CuSuiteAddSuite(suite, get_quicklist_suite());
|
CuSuiteAddSuite(suite, get_quicklist_suite());
|
||||||
CuSuiteAddSuite(suite, get_functions_suite());
|
CuSuiteAddSuite(suite, get_functions_suite());
|
||||||
|
CuSuiteAddSuite(suite, get_umlaut_suite());
|
||||||
CuSuiteAddSuite(suite, get_curse_suite());
|
CuSuiteAddSuite(suite, get_curse_suite());
|
||||||
CuSuiteAddSuite(suite, get_market_suite());
|
CuSuiteAddSuite(suite, get_market_suite());
|
||||||
CuSuiteAddSuite(suite, get_move_suite());
|
CuSuiteAddSuite(suite, get_move_suite());
|
||||||
|
|
|
@ -151,6 +151,7 @@
|
||||||
<ClCompile Include="util\strings.c" />
|
<ClCompile Include="util\strings.c" />
|
||||||
<ClCompile Include="util\translation.c" />
|
<ClCompile Include="util\translation.c" />
|
||||||
<ClCompile Include="util\umlaut.c" />
|
<ClCompile Include="util\umlaut.c" />
|
||||||
|
<ClCompile Include="util\umlaut_test.c" />
|
||||||
<ClCompile Include="util\unicode.c" />
|
<ClCompile Include="util\unicode.c" />
|
||||||
<ClCompile Include="util\xml.c" />
|
<ClCompile Include="util\xml.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -205,5 +205,8 @@
|
||||||
<ClCompile Include="util\functions_test.c">
|
<ClCompile Include="util\functions_test.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="util\umlaut_test.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -4,20 +4,20 @@
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
|
|
||||||
|
|
||||||
static void test_all(CuTest * tc)
|
static void test_functions(CuTest * tc)
|
||||||
{
|
{
|
||||||
pf_generic fun;
|
pf_generic fun;
|
||||||
|
|
||||||
fun = get_function("herpderp");
|
fun = get_function("herpderp");
|
||||||
CuAssertTrue(tc, !fun);
|
CuAssertTrue(tc, !fun);
|
||||||
register_function((pf_generic)test_all, "herpderp");
|
register_function((pf_generic)test_functions, "herpderp");
|
||||||
fun = get_function("herpderp");
|
fun = get_function("herpderp");
|
||||||
CuAssertTrue(tc, fun==(pf_generic)test_all);
|
CuAssertTrue(tc, fun==(pf_generic)test_functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_functions_suite(void)
|
CuSuite *get_functions_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_all);
|
SUITE_ADD_TEST(suite, test_functions);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ void addtoken(tnode * root, const char *str, variant id)
|
||||||
next = next->nexthash;
|
next = next->nexthash;
|
||||||
if (!next) {
|
if (!next) {
|
||||||
tref *ref;
|
tref *ref;
|
||||||
tnode *node = calloc(1, sizeof(tnode));
|
tnode *node = (tnode *)calloc(1, sizeof(tnode));
|
||||||
|
|
||||||
if (ucs < 'a' || ucs > 'z') {
|
if (ucs < 'a' || ucs > 'z') {
|
||||||
lcs = towlower((wint_t) ucs);
|
lcs = towlower((wint_t) ucs);
|
||||||
|
@ -97,7 +97,7 @@ void addtoken(tnode * root, const char *str, variant id)
|
||||||
ucs = towupper((wint_t) ucs);
|
ucs = towupper((wint_t) ucs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ref = malloc(sizeof(tref));
|
ref = (tref *)malloc(sizeof(tref));
|
||||||
ref->ucs = ucs;
|
ref->ucs = ucs;
|
||||||
ref->node = node;
|
ref->node = node;
|
||||||
ref->nexthash = root->next[index];
|
ref->nexthash = root->next[index];
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
#include <cutest/CuTest.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "umlaut.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void test_umlaut(CuTest * tc)
|
||||||
|
{
|
||||||
|
char umlauts[] = { 0xc3, 0xa4, 0xc3, 0xb6, 0xc3, 0xbc, 0xc3, 0x9f, 0 }; /* auml ouml uuml szlig nul */
|
||||||
|
tnode tokens = { 0 };
|
||||||
|
variant id;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
id.i = 1;
|
||||||
|
addtoken(&tokens, "herp", id);
|
||||||
|
id.i = 2;
|
||||||
|
addtoken(&tokens, "derp", id);
|
||||||
|
id.i = 3;
|
||||||
|
addtoken(&tokens, umlauts, id);
|
||||||
|
|
||||||
|
result = findtoken(&tokens, "herp", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 1, id.i);
|
||||||
|
|
||||||
|
result = findtoken(&tokens, "derp", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 2, id.i);
|
||||||
|
|
||||||
|
result = findtoken(&tokens, umlauts, &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 3, id.i);
|
||||||
|
|
||||||
|
result = findtoken(&tokens, "AEoeUEss", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 3, id.i);
|
||||||
|
|
||||||
|
result = findtoken(&tokens, "herpderp", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_NOMATCH, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
CuSuite *get_umlaut_suite(void)
|
||||||
|
{
|
||||||
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_umlaut);
|
||||||
|
return suite;
|
||||||
|
}
|
Loading…
Reference in New Issue