interpret/test/test_source.c

43 lines
1.1 KiB
C
Raw Normal View History

2023-02-02 21:53:59 -05:00
#include "../src/journal.h"
#include "../src/source.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
2023-02-03 14:50:10 -05:00
#include <errno.h>
2023-02-02 21:53:59 -05:00
int main(void) {
int success = EXIT_SUCCESS;
2023-03-10 23:06:11 -05:00
errno = 0; /* `errno` is not set correctly to 0 in some debug situations. */
2023-02-02 21:53:59 -05:00
struct journal j = journal();
struct sources s = sources(&j);
if(errno) goto catch;
2023-02-04 22:06:43 -05:00
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));
2023-02-02 21:53:59 -05:00
goto finally;
catch:
success = EXIT_FAILURE, perror("source");
finally:
sources_(&s);
journal_(&j);
return success;
}