-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrbehave.h
65 lines (55 loc) · 1.74 KB
/
crbehave.h
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
#ifndef CRBEHAVE_H
#define CRBEHAVE_H
#include <sys/types.h>
#define MATCH_MAX_SUB 256
#define MAX_TABLE_COLS 32
struct match;
int match(struct match *, const char *, const char *);
char *match_str(struct match *, int);
int match_int(struct match *, int);
double match_double(struct match *, int);
void match_free(struct match *);
/*
* CRBEHAVE_EXPECT(m, e):
* Like assert, evaluates expression 'e'.
*
* Example:
* CRBEHAVE_EXPECT(m, 1 == 2);
*/
#define CRBEHAVE_EXPECT(_m, e) \
match_expect((_m), __FILE__, __LINE__, (e), #e)
int match_expect(struct match *, const char *, int, int, const char *);
/*
* CRBEHAVE_EXPECT_STREQ(m, val, ref):
* Like CRBEHAVE_EXPECT, but has special support for comparing strings
* for string equality, including checking for NULL and displaying the
* strings in the fail message.
*
* Example:
* CRBEHAVE_EXPECT_STREQ(m, "hello", "world");
*/
#define CRBEHAVE_EXPECT_STREQ(_m, _val, _ref) \
match_expect_streq((_m), __FILE__, __LINE__, (_val), (_ref))
int match_expect_streq(struct match *, const char *, int, const char *,
const char *);
/*
* int nfields = parse_table_row(str, fields, max_fields):
* Parses table row and writes the result to fields, up to
* max_fields. Returns number of fields.
*
* Example:
* char *fields[2];
* int nfields;
*
* nfields = parse_table_row("| col1 | col2 |", fields, 2);
* puts(fields[0]);
* puts(fields[1]);
*/
int parse_table_row(char *, char **, size_t);
typedef void (*KeywordCallback)(struct match *, const char *, const char *);
typedef void (*ResetCallback)(void);
int
crbehave_run(int argc, char **argv,
KeywordCallback given, KeywordCallback when, KeywordCallback then,
ResetCallback reset);
#endif