43 lines
715 B
C++
43 lines
715 B
C++
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <test.h>
|
||
|
|
||
|
// FIXME: Add more tests.
|
||
|
|
||
|
TestResult test_basic_scanf()
|
||
|
{
|
||
|
char hello[21];
|
||
|
char world[21];
|
||
|
|
||
|
int parsed = sscanf("hello world", "%20s %20s", hello, world);
|
||
|
validate(parsed == 2);
|
||
|
|
||
|
validate(!strcmp(hello, "hello"));
|
||
|
validate(!strcmp(world, "world"));
|
||
|
|
||
|
test_success;
|
||
|
}
|
||
|
|
||
|
TestResult test_incomplete_scanf()
|
||
|
{
|
||
|
char hello[21];
|
||
|
char world[21];
|
||
|
|
||
|
int parsed = sscanf("hello ", "%20s %20s", hello, world);
|
||
|
validate(parsed == 1);
|
||
|
|
||
|
validate(!strcmp(hello, "hello"));
|
||
|
|
||
|
test_success;
|
||
|
}
|
||
|
|
||
|
Result<void> test_main()
|
||
|
{
|
||
|
test_prelude;
|
||
|
|
||
|
run_test(test_basic_scanf);
|
||
|
run_test(test_incomplete_scanf);
|
||
|
|
||
|
return {};
|
||
|
}
|