gemtext-parser/test/parse-gemtext0.c

103 lines
3.1 KiB
C
Raw Normal View History

2023-10-14 01:35:11 -04:00
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gemtext-parser.h"
gemtextLineQueue lq;
gemtextParser parser;
int main() {
int ret = 0;
FILE *stream = NULL;
gemtextLine *line = NULL;
stream = fopen("test0.gmi", "r");
assert(stream != NULL);
ret = gemtextLineQueueInit(&lq);
assert(ret == 0);
ret = gemtextParserInit(&parser, stream);
assert(ret == 0);
ret = parseGemtext(&parser, &lq);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType = h1Line);
assert(memcmp(line->str, "A Test Gemtext file", 19) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType = h2Line);
assert(memcmp(line->str, "Used for testing the parser in normal operation", 47) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == normalLine);
assert(*line->str == '\n');
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == normalLine);
assert(memcmp(line->str, "This is", 7) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == normalLine);
assert(*line->str == '\n');
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == quoteLine);
assert(memcmp(line->str, "Walk before you run.\n- Anonymous", 32) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == normalLine);
assert(*line->str == '\n');
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == h3Line);
assert(memcmp(line->str, "Let's check a list", 18) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == listLine);
assert(memcmp(line->str, "First item", 9) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == listLine);
assert(memcmp(line->str, "second item", 11) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == normalLine);
assert(*line->str == '\n');
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == linkLine);
assert(memcmp(line->link->url, "gemini://example.org/test.gmi", 29) == 0);
assert(memcmp(line->link->display, "This is a link", 14) == 0);
gemtextLineDeinit(line);
2023-10-25 23:05:10 -04:00
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == normalLine);
assert(*line->str == '\n');
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line->lineType == preformattedLine);
assert(memcmp(line->node->altText, "Test preformatted block", 23) == 0);
assert(memcmp(line->node->body, "This is a preformatted block", 28) == 0);
gemtextLineDeinit(line);
line = gemtextLineQueueTryPop(&lq);
assert(line != NULL);
assert(line->lineType == endOfStream);
gemtextLineDeinit(line);
2023-10-14 01:35:11 -04:00
gemtextParserDeinit(&parser);
return ret;
}