commit 59b2344e6fdc6b2780f85c2e1951cf27e193bd41 from: Omar Polo date: Thu May 19 08:14:45 2022 UTC add a simple test for the text/gemini parser too commit - 0180fcdd5a586643934eb12262e33b815b4bcfcc commit + 59b2344e6fdc6b2780f85c2e1951cf27e193bd41 blob - adb6c9f11755729b61b438ca71c1a7c80646a596 blob + 457951c03488f44a788f4bc1eb201bcdfad0a2d6 --- test/Makefile.am +++ test/Makefile.am @@ -1,4 +1,4 @@ -check_PROGRAMS = gmparser +check_PROGRAMS = gmparser gmiparser gmparser_SOURCES = gmparser.c \ $(top_srcdir)/include/compat.h \ @@ -7,11 +7,20 @@ gmparser_SOURCES = gmparser.c \ $(top_srcdir)/parser/parser_gophermap.c \ $(top_srcdir)/utils.c +gmiparser_SOURCES = gmiparser.c \ + $(top_srcdir)/include/compat.h \ + $(top_srcdir)/include/parser.h \ + $(top_srcdir)/parser/parser.c \ + $(top_srcdir)/parser/parser_gemtext.c \ + $(top_srcdir)/utils.c + gmparser_CFLAGS = -I$(top_srcdir)/phos -I$(top_srcdir)/include +gmiparser_CFLAGS = -I$(top_srcdir)/phos -I$(top_srcdir)/include EXTRA_DIST = test-gmparser \ gm-00 \ - gm-01 + gm-01 \ + gmi-00 CLEANFILES = serialized.* blob - /dev/null blob + 0874296f44d32ba454b50db2f7b6d69f2cfa4f8e (mode 644) --- /dev/null +++ test/gmi-00 @@ -0,0 +1,17 @@ +* an item +*not an item + +# a title + +some text + +``` verbatim with alt +\o/ +``` + +``` +verbatim without alt description +(the extra space after the marker is there on purpose) +``` + +> a quote blob - 6fb362f166d0dce6398048fdb248e368d76acd8c blob + eb83c5994c07f41910a333e37177ea2e17531146 --- test/test-gmparser +++ test/test-gmparser @@ -7,3 +7,9 @@ for f in "$srcdir"/gm-*; do ./gmparser < "$f" > "$name" diff -u "$f" "$name" done + +for f in "$srcdir"/gmi-*; do + name=serialized."$(basename "$f")" + ./gmiparser < "$f" > "$name" + diff -u "$f" "$name" +done blob - /dev/null blob + 7954737c9081e72247721ed529cf6c9e05bba15a (mode 644) --- /dev/null +++ test/gmiparser.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Omar Polo + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "compat.h" + +#include +#include +#include + +#include "parser.h" +#include "telescope.h" + +/* XXX: needed just to please the linker */ +int hide_pre_context; +int hide_pre_closing_line; +int hide_pre_blocks; +int emojify_link; + +int +emojied_line(const char *s, const char **space_ret) +{ + return 0; +} + +void +erase_buffer(struct buffer *buffer) +{ + return; +} + +int +main(void) +{ + FILE *fp; + struct tab tab; + struct hist hist; + ssize_t r; + size_t blen; + char buf[BUFSIZ], *b; + + memset(&tab, 0, sizeof(tab)); + memset(&hist, 0, sizeof(hist)); + tab.hist_cur = &hist; + + parser_init(&tab, gemtext_initparser); + for (;;) { + if ((r = read(0, buf, sizeof(buf))) == -1) + err(1, "read"); + if (r == 0) + break; + if (!parser_parse(&tab, buf, r)) + err(1, "parser_parse"); + } + + if (!parser_free(&tab)) + err(1, "parser_free"); + + if ((fp = open_memstream(&b, &blen)) == NULL) + err(1, "open_memstream"); + + if (parser_serialize(&tab, fp) == -1) + err(1, "parser_serialize"); + + fclose(fp); + write(1, b, blen); + + return 0; +}