- RepeatabilityRepeatability - while we are implementing code, we can repeatedly run one test until it gives the correct results.
- ConfidenceAnalysability - weit's easy to run all the tests every timetest suite under Valgrind to ensure that we're not accessing memory we make a changeshouldn't, alerting us immediately if our new code broke something that used to workor leaking or double-freeing.
- AnalysabilityReviewability - it's easy to run the test suite under Valgrind to ensure that we're not accessing memory we shouldn't, or leaking or doubleeveryone can see exactly what testing has been done -freeing and, crucially, whether something was missed.
- Reviewability - everyone can see exactly what testing has been doneMantainability - and, cruciallywe run all the tests every time we make a change, whetheralerting us immediately if our new code broke something was missedthat used to work. Remember that the person modifying the code in future won't have the same insight into its operation as you do right now.
int main(void)
{
unsigned failures = 0;
failures += TEST_STR_SPLIT(NULL, NULL, 0, NULL);
failures += TEST_STR_SPLIT(NULL, "abc", 1, NULL);
failures += TEST_STR_SPLIT(NULL, "abc", -1, NULL);
{
const char *expected[] = {"abc", NULL};
failures += TEST_STR_SPLIT("abc", NULL, 0, expected);
}
{
const char *expected[] = {"abc", NULL};
/* I would prefer this to return {"a", "b", "c", NULL }. */
/* But the documentation is clear that's not what we get. */
failures += TEST_STR_SPLIT("abc", "", 0, expected);
}
{
/* I would prefer this to return {"", NULL }. */
/* But the documentation is clear that's not what we get. */
failures += TEST_STR_SPLIT("", ".", 0, NULL);
}
/* single character separator */
{
const char *expected[] = {"", NULL };
failures += TEST_STR_SPLIT("", ".", -1, expected);
}
{
const char *expected[] = {"=abc", NULL};
failures += TEST_STR_SPLIT("=abc", "=", 0, expected);
}
{
const char *expected[] = {"", "abc", NULL};
failures += TEST_STR_SPLIT("=abc", "=", -1, expected);
}
{
const char *expected[] = {"abc", "", NULL};
failures += TEST_STR_SPLIT("abc=", "=", -1, expected);
}
{
const char *expected[] = {"", "abc", "", NULL};
failures += TEST_STR_SPLIT("=abc=", "=", 2-1, expected);
}
{
const char *expected[] = {"ab", "cd", NULL};
failures += TEST_STR_SPLIT("ab=cd", "=", -1, expected);
}
{
const char *expected[] = {"ab", "cd", "ef", NULL};
failures += TEST_STR_SPLIT("ab=cd=ef", "=", -1, expected);
}
{
const char *expected[] = {"ab", "", "cd", NULL};
failures += TEST_STR_SPLIT("ab==cd", "=", 2-1, expected);
}
{
const char *expected[] = {"ab", "cd=ef", NULL};
failures += TEST_STR_SPLIT("ab=cd=ef", "=", 1, expected);
}
{
const char *expected[] = {"ab", "cd", "ef", NULL};
failures += TEST_STR_SPLIT("ab=cd=ef", "=", 2, expected);
}
/* multi-char separator */
{
const char *expected[] = {"ab", "cd", "ef"NULL};
failures += TEST_STR_SPLIT("ab==cd", "==", -1, expected);
}
{
const char *expected[] = {"", "ab", "=cd", NULL};
failures += TEST_STR_SPLIT("ab=cd=ef""==ab===cd", "=""==", 5-1, expected);
}
{
const char *expected[] = {"ab", "cd", NULL};
failures += TEST_STR_SPLIT("ab==>cd", "==>", -1, expected);
}
{
const char *expected[] = {"ab", "-=cd", NULL};
failures += TEST_STR_SPLIT("ab=-=-=cd", "=-=", -1, expected);
}
printf("There were %u test failures\n", failures);
return failures > 0;
}