mirror of
https://github.com/tailix/libkernaux.git
synced 2025-02-24 15:55:41 -05:00
Main: tests/test_ntoa.c: DRY test
This commit is contained in:
parent
cd14db08d7
commit
fdedd2574d
1 changed files with 8 additions and 18 deletions
|
@ -390,6 +390,11 @@ static void test_itoa_assert(char *const buffer, const int base)
|
||||||
assert(strstr(assert_last_file, "src/ntoa.c") != NULL);
|
assert(strstr(assert_last_file, "src/ntoa.c") != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *str_end(const char *str)
|
||||||
|
{
|
||||||
|
for (;; ++str) if (*str == '\0') return str;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
kernaux_assert_cb = assert_cb;
|
kernaux_assert_cb = assert_cb;
|
||||||
|
@ -430,12 +435,7 @@ int main()
|
||||||
utoa_cases[index].base
|
utoa_cases[index].base
|
||||||
);
|
);
|
||||||
assert(strcmp(buffer, utoa_cases[index].result) == 0);
|
assert(strcmp(buffer, utoa_cases[index].result) == 0);
|
||||||
for (const char *pos = buffer;; ++pos) {
|
assert(end == str_end(buffer));
|
||||||
if (*pos == '\0') {
|
|
||||||
assert(end == pos);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,24 +454,14 @@ int main()
|
||||||
|
|
||||||
const char *const end1 = kernaux_itoa(value, buffer, base);
|
const char *const end1 = kernaux_itoa(value, buffer, base);
|
||||||
assert(strcmp(buffer, utoa_cases[index].result) == 0);
|
assert(strcmp(buffer, utoa_cases[index].result) == 0);
|
||||||
for (const char *pos = buffer;; ++pos) {
|
assert(end1 == str_end(buffer));
|
||||||
if (*pos == '\0') {
|
|
||||||
assert(end1 == pos);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value <= 0 || base < 2 || base > 36) continue;
|
if (value <= 0 || base < 2 || base > 36) continue;
|
||||||
|
|
||||||
const char *const end2 = kernaux_itoa(-value, buffer, base);
|
const char *const end2 = kernaux_itoa(-value, buffer, base);
|
||||||
assert(buffer[0] == '-');
|
assert(buffer[0] == '-');
|
||||||
assert(strcmp(&buffer[1], utoa_cases[index].result) == 0);
|
assert(strcmp(&buffer[1], utoa_cases[index].result) == 0);
|
||||||
for (const char *pos = buffer;; ++pos) {
|
assert(end2 == str_end(buffer));
|
||||||
if (*pos == '\0') {
|
|
||||||
assert(end2 == pos);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue