interpret/test/test_source.c

42 lines
1.1 KiB
C
Raw Permalink Normal View History

2023-04-30 04:29:27 +00:00
#include "../src/scan.h"
2023-02-03 02:53:59 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
2023-02-03 19:50:10 +00:00
#include <errno.h>
2023-02-03 02:53:59 +00:00
int main(void) {
int success = EXIT_SUCCESS;
2023-03-11 04:06:11 +00:00
errno = 0; /* `errno` is not set correctly to 0 in some debug situations. */
struct journal jrnl = journal(/*"../journal"*/);
2023-04-30 04:29:27 +00:00
struct scan scn = scan(&jrnl);
2023-02-03 02:53:59 +00:00
if(errno) goto catch;
2023-02-05 03:06:43 +00:00
const union line64 agenda = {{4,{{20,04,1996}}}},
before = {{1,{{1,1,1900}}}},
noentry = {{3,{{1,6,1995}}}};
2023-05-07 07:22:58 +00:00
const struct kvpair *source;
2023-02-05 03:06:43 +00:00
2023-04-30 04:29:27 +00:00
source = scan_source_lookup(&scn, agenda);
2023-02-05 03:06:43 +00:00
printf("agenda: <%.*s>\n",
2023-05-07 07:22:58 +00:00
(int)(source->key.b - source->key.a), source->key.a);
assert(pair_is_string(source->key, "1995agenda"));
2023-02-05 03:06:43 +00:00
2023-04-30 04:29:27 +00:00
source = scan_source_lookup(&scn, before);
2023-02-05 03:06:43 +00:00
printf("before: <%.*s>\n",
2023-05-07 07:22:58 +00:00
(int)(source->key.b - source->key.a), source->key.a);
assert(pair_is_string(source->key, 0));
2023-02-05 03:06:43 +00:00
2023-04-30 04:29:27 +00:00
source = scan_source_lookup(&scn, noentry);
2023-02-05 03:06:43 +00:00
printf("noentry: <%.*s>\n",
2023-05-07 07:22:58 +00:00
(int)(source->key.b - source->key.a), source->key.a);
assert(pair_is_string(source->key, 0));
2023-02-05 03:06:43 +00:00
2023-02-03 02:53:59 +00:00
goto finally;
catch:
success = EXIT_FAILURE, perror("source");
finally:
2023-04-30 04:29:27 +00:00
scan_(&scn);
journal_(&jrnl);
2023-02-03 02:53:59 +00:00
return success;
}