All tests passing for C implementation.
This commit is contained in:
68
packages/c/test/test-runner.c
Normal file
68
packages/c/test/test-runner.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "../parser.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
void linedata_basic (char indent) {
|
||||
char *line = NULL;
|
||||
size_t bufsize = 32;
|
||||
ssize_t c_read = 0;
|
||||
|
||||
terrace_linedata_t line_data;
|
||||
line_data.indent = indent;
|
||||
|
||||
while(c_read = getline(&line, &bufsize, stdin)) {
|
||||
if (c_read == -1) break;
|
||||
char *terrace_line = strtok(line, "\n");
|
||||
terrace_parse_line(terrace_line, &line_data);
|
||||
if (terrace_line == 0) terrace_line = "";
|
||||
|
||||
printf("| level %u | indent %c | offsetHead %u | offsetTail %u | line %s |\n", line_data.level, line_data.indent, line_data.offsetHead, line_data.offsetTail, terrace_line);
|
||||
};
|
||||
|
||||
free(line);
|
||||
}
|
||||
|
||||
void linedata_head_tail (char indent) {
|
||||
char *line = NULL;
|
||||
size_t bufsize = 32;
|
||||
ssize_t c_read = 0;
|
||||
|
||||
terrace_linedata_t line_data;
|
||||
line_data.indent = indent;
|
||||
|
||||
char *head;
|
||||
char *tail;
|
||||
|
||||
while(c_read = getline(&line, &bufsize, stdin)) {
|
||||
if (c_read == -1) break;
|
||||
char *terrace_line = strtok(line, "\n");
|
||||
terrace_parse_line(terrace_line, &line_data);
|
||||
if (terrace_line == 0) terrace_line = "";
|
||||
|
||||
if (line_data.offsetTail < c_read) tail = &terrace_line[line_data.offsetTail + 1];
|
||||
else tail = "";
|
||||
|
||||
// Cheeky move to avoid string slicing.
|
||||
if (line_data.offsetHead < c_read) {
|
||||
terrace_line[line_data.offsetTail] = '\0';
|
||||
head = &terrace_line[line_data.offsetHead];
|
||||
}
|
||||
else head = "";
|
||||
|
||||
printf("| head %s | tail %s |\n", head, tail);
|
||||
};
|
||||
|
||||
free(line);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) return 0;
|
||||
|
||||
char* test = argv[1];
|
||||
if (!strcmp(test, "linedata:basic")) linedata_basic(' ');
|
||||
if (!strcmp(test, "linedata:tabs")) linedata_basic('\t');
|
||||
if (!strcmp(test, "linedata:head-tail")) linedata_head_tail(' ');
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user