Add second, more complicated gemtext test
This commit is contained in:
parent
b4c0b24a4a
commit
dc6a0150d9
4 changed files with 120 additions and 0 deletions
|
@ -362,6 +362,7 @@ int parsePreformatted(gemtextParser *parser, gemtextLineQueue *lq, char c) {
|
||||||
switch (parser->state) {
|
switch (parser->state) {
|
||||||
case trimStart:
|
case trimStart:
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
|
lineBufferReset(&parser->buffer);
|
||||||
parser->state = lineStart;
|
parser->state = lineStart;
|
||||||
parser->altText = NULL;
|
parser->altText = NULL;
|
||||||
} else if (c == ' ' || c == '\t') {
|
} else if (c == ' ' || c == '\t') {
|
||||||
|
|
|
@ -37,6 +37,7 @@ LDLIBS += ../libgemtext.a
|
||||||
LDLIBS += $(LIBS)
|
LDLIBS += $(LIBS)
|
||||||
|
|
||||||
tests += parse-gemtext0
|
tests += parse-gemtext0
|
||||||
|
tests += parse-gemtext1
|
||||||
|
|
||||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||||
|
|
||||||
|
|
101
test/parse-gemtext1.c
Normal file
101
test/parse-gemtext1.c
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "gemtext-parser.h"
|
||||||
|
|
||||||
|
gemtextLineQueue lq;
|
||||||
|
gemtextParser parser;
|
||||||
|
|
||||||
|
char * preBlk =
|
||||||
|
"Just a regular preformatted block.\n"
|
||||||
|
"Nothing special";
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int ret = 0;
|
||||||
|
FILE *stream = NULL;
|
||||||
|
gemtextLine *line = NULL;
|
||||||
|
|
||||||
|
stream = fopen("test1.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 more complicated example", 26) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == listLine);
|
||||||
|
assert(memcmp(line->str, "list item with no leading space", 30) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == listLine);
|
||||||
|
assert(memcmp(line->str, "list item with several leading spaces", 37) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == h2Line);
|
||||||
|
assert(memcmp(line->str, "After this H2, an empty quote", 29) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == normalLine);
|
||||||
|
assert(memcmp(line->str, "\n", 1) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == h3Line);
|
||||||
|
assert(memcmp(line->str, "Now we'll", 9) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == normalLine);
|
||||||
|
assert(memcmp(line->str, "``", 2) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == normalLine);
|
||||||
|
assert(memcmp(line->str, "=", 1) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == normalLine);
|
||||||
|
assert(memcmp(line->str, "And maybe", 9) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == linkLine);
|
||||||
|
assert(memcmp(line->link->url, "spartan://example.org", 21) == 0);
|
||||||
|
assert(line->link->display == NULL);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == normalLine);
|
||||||
|
assert(memcmp(line->str, "Let's enter", 11) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == preformattedLine);
|
||||||
|
assert(line->node->altText == NULL);
|
||||||
|
assert(memcmp(line->node->body, preBlk, 50) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == normalLine);
|
||||||
|
assert(memcmp(line->str, "And we'll finish", 16) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
line = gemtextLineQueueTryPop(&lq);
|
||||||
|
assert(line->lineType == linkLine);
|
||||||
|
assert(line->link->display == NULL);
|
||||||
|
assert(memcmp(line->link->url, "finger://example.org/joe", 24) == 0);
|
||||||
|
gemtextLineDeinit(line);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
17
test/test1.gmi
Normal file
17
test/test1.gmi
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# A more complicated example
|
||||||
|
*list item with no leading space
|
||||||
|
* list item with several leading spaces
|
||||||
|
##After this H2, an empty quote
|
||||||
|
>
|
||||||
|
### Now we'll mess with incomplete linetype signifiers
|
||||||
|
``
|
||||||
|
=
|
||||||
|
And maybe a link with no display element..
|
||||||
|
=> spartan://example.org/
|
||||||
|
Let's enter preformatted for reals this time.
|
||||||
|
```
|
||||||
|
Just a regular preformatted block.
|
||||||
|
Nothing special
|
||||||
|
```
|
||||||
|
And we'll finish with a link.
|
||||||
|
=> finger://example.org/joe
|
Loading…
Add table
Reference in a new issue