interpret/test/test_source.c

42 lines
1.1 KiB
C

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