interpret/test/test_source.c

42 lines
1.1 KiB
C

#include "../src/source.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 j = journal();
struct sources s = sources(&j);
if(errno) goto catch;
const union line64 agenda = {{4,{{20,04,1996}}}},
before = {{1,{{1,1,1900}}}},
noentry = {{3,{{1,6,1995}}}};
const struct source *source;
source = source_lookup(&s, agenda);
printf("agenda: <%.*s>\n",
(int)(source->name.b - source->name.a), source->name.a);
assert(pair_is_string(source->name, "1995agenda"));
source = source_lookup(&s, before);
printf("before: <%.*s>\n",
(int)(source->name.b - source->name.a), source->name.a);
assert(pair_is_string(source->name, 0));
source = source_lookup(&s, noentry);
printf("noentry: <%.*s>\n",
(int)(source->name.b - source->name.a), source->name.a);
assert(pair_is_string(source->name, 0));
goto finally;
catch:
success = EXIT_FAILURE, perror("source");
finally:
sources_(&s);
journal_(&j);
return success;
}