forked from ulises-jeremias/simple-parse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparse_test.c
79 lines (61 loc) · 1.66 KB
/
sparse_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <sparse.h>
#define mu_assert(message, test) do { \
if (!(test)) return message; \
} while (0)
#define mu_run_test(test) do { \
char *message = test(); \
tests_run++; \
if (message) return message; \
} while (0)
int tests_run = 0;
static char* TEST_VALUE;
static char* TEST_EXPECTED;
static char*
sparse_compare()
{
printf("Compare %s to %s\n", TEST_VALUE, TEST_EXPECTED);
int diff = strcmp(TEST_VALUE, TEST_EXPECTED);
mu_assert("Compare does not match", diff == 0);
return NULL;
}
static char*
sparse_test(int argc, char** argv)
{
char* testType = sparse_flag("type", "UNDEFINED", argc, argv);
TEST_VALUE = sparse_flag("val", "UNDEFINED", argc, argv);
printf("type is %s %d\n", testType, strcmp(testType, "boolean"));
if (strcmp(testType, "boolean") == 0)
{
TEST_EXPECTED = "TRUE";
}
else if (strcmp(testType, "empty") == 0)
{
TEST_EXPECTED = "";
}
else if (strcmp(testType, "value") == 0)
{
TEST_EXPECTED = "innerValue";
}
else if (strcmp(testType, "missing") == 0)
{
TEST_EXPECTED = "UNDEFINED";
}
else
{
return "no such test";
}
mu_run_test(sparse_compare);
return NULL;
}
int
main(int argc, char* argv[])
{
char* result = sparse_test(argc, argv);
if (result != 0)
printf("%s\n", result);
return result != NULL;
}