Skip to content

Commit

Permalink
More (conditional) sourcepos!
Browse files Browse the repository at this point in the history
+ Expose references as part of the AST
  • Loading branch information
MathieuDuponchelle committed Jan 5, 2017
1 parent c786cac commit ce27a8f
Show file tree
Hide file tree
Showing 20 changed files with 963 additions and 88 deletions.
37 changes: 37 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define CMARK_NO_SHORT_NAMES
#include "cmark.h"
#include "node.h"
#include "parser.h"

#include "harness.h"
#include "cplusplus.h"
Expand Down Expand Up @@ -883,6 +884,41 @@ static void test_feed_across_line_ending(test_batch_runner *runner) {
cmark_node_free(document);
}

static cmark_node *S_parse_with_fake_total(bufsize_t fake_total,
const char *str,
cmark_err_type *err) {
cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
parser->total_bytes = fake_total;
cmark_parser_feed(parser, str, strlen(str));
cmark_node *doc = cmark_parser_finish(parser);
*err = cmark_parser_get_error(parser);
cmark_parser_free(parser);
return doc;
}

static void test_bufsize_overflow(test_batch_runner *runner) {
cmark_node *doc;
cmark_err_type err;

doc = S_parse_with_fake_total(BUFSIZE_MAX, "a", &err);
OK(runner, doc == NULL, "parse 1 byte after BUFSIZE_MAX bytes fails");
INT_EQ(runner, err, CMARK_ERR_INPUT_TOO_LARGE,
"parse 1 byte after BUFSIZE_MAX bytes error code");

doc = S_parse_with_fake_total(BUFSIZE_MAX - 9, "0123456789", &err);
OK(runner, doc == NULL, "parse 10 byte after BUFSIZE_MAX-9 bytes fails");
INT_EQ(runner, err, CMARK_ERR_INPUT_TOO_LARGE,
"parse 10 byte after BUFSIZE_MAX-9 bytes error code");

doc = S_parse_with_fake_total(BUFSIZE_MAX - 1, "a", &err);
OK(runner, doc != NULL, "parse 1 byte after BUFSIZE_MAX-1 bytes");
cmark_node_free(doc);

doc = S_parse_with_fake_total(BUFSIZE_MAX - 10, "0123456789", &err);
OK(runner, doc != NULL, "parse 10 byte after BUFSIZE_MAX-10 bytes");
cmark_node_free(doc);
}

int main() {
int retval;
test_batch_runner *runner = test_batch_runner_new();
Expand All @@ -908,6 +944,7 @@ int main() {
test_cplusplus(runner);
test_safe(runner);
test_feed_across_line_ending(runner);
test_bufsize_overflow(runner);

test_print_summary(runner);
retval = test_ok(runner) ? 0 : 1;
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(HEADERS
houdini.h
cmark_ctype.h
render.h
source_map.h
)
set(LIBRARY_SOURCES
cmark.c
Expand All @@ -40,6 +41,7 @@ set(LIBRARY_SOURCES
houdini_html_e.c
houdini_html_u.c
cmark_ctype.c
source_map.c
${HEADERS}
)

Expand Down
Loading

0 comments on commit ce27a8f

Please sign in to comment.