@@ -24,7 +24,7 @@ static void test_md_to_html(test_batch_runner *runner, const char *markdown,
24
24
const char * expected_html , const char * msg );
25
25
26
26
static void test_content (test_batch_runner * runner , cmark_node_type type ,
27
- int allowed_content );
27
+ unsigned int * allowed_content );
28
28
29
29
static void test_char (test_batch_runner * runner , int valid , const char * utf8 ,
30
30
const char * msg );
@@ -177,7 +177,7 @@ static void accessors(test_batch_runner *runner) {
177
177
OK (runner , cmark_node_set_literal (string , literal + sizeof ("prefix" )),
178
178
"set_literal suffix" );
179
179
180
- char * rendered_html = cmark_render_html (doc , CMARK_OPT_DEFAULT );
180
+ char * rendered_html = cmark_render_html (doc , CMARK_OPT_DEFAULT , NULL );
181
181
static const char expected_html [] =
182
182
"<h3>Header</h3>\n"
183
183
"<ol start=\"3\">\n"
@@ -299,7 +299,7 @@ static void iterator_delete(test_batch_runner *runner) {
299
299
}
300
300
}
301
301
302
- char * html = cmark_render_html (doc , CMARK_OPT_DEFAULT );
302
+ char * html = cmark_render_html (doc , CMARK_OPT_DEFAULT , NULL );
303
303
static const char expected [] = "<p>a c</p>\n"
304
304
"<p>a c</p>\n" ;
305
305
STR_EQ (runner , html , expected , "iterate and delete nodes" );
@@ -339,7 +339,7 @@ static void create_tree(test_batch_runner *runner) {
339
339
OK (runner , cmark_node_append_child (emph , str2 ), "append3" );
340
340
INT_EQ (runner , cmark_node_check (doc , NULL ), 0 , "append3 consistent" );
341
341
342
- html = cmark_render_html (doc , CMARK_OPT_DEFAULT );
342
+ html = cmark_render_html (doc , CMARK_OPT_DEFAULT , NULL );
343
343
STR_EQ (runner , html , "<p>Hello, <em>world</em>!</p>\n" , "render_html" );
344
344
free (html );
345
345
@@ -375,7 +375,7 @@ static void create_tree(test_batch_runner *runner) {
375
375
376
376
cmark_node_unlink (emph );
377
377
378
- html = cmark_render_html (doc , CMARK_OPT_DEFAULT );
378
+ html = cmark_render_html (doc , CMARK_OPT_DEFAULT , NULL );
379
379
STR_EQ (runner , html , "<p>brzz!</p>\n" , "render_html after shuffling" );
380
380
free (html );
381
381
@@ -407,7 +407,7 @@ static void custom_nodes(test_batch_runner *runner) {
407
407
STR_EQ (runner , cmark_node_get_on_exit (cb ), "" , "get_on_exit (empty)" );
408
408
cmark_node_append_child (doc , cb );
409
409
410
- html = cmark_render_html (doc , CMARK_OPT_DEFAULT );
410
+ html = cmark_render_html (doc , CMARK_OPT_DEFAULT , NULL );
411
411
STR_EQ (runner , html , "<p><ON ENTER|Hello|ON EXIT></p>\n<on enter|\n" ,
412
412
"render_html" );
413
413
free (html );
@@ -434,22 +434,18 @@ void hierarchy(test_batch_runner *runner) {
434
434
435
435
cmark_node_free (bquote1 );
436
436
437
- int max_node_type = CMARK_NODE_LAST_BLOCK > CMARK_NODE_LAST_INLINE
438
- ? CMARK_NODE_LAST_BLOCK
439
- : CMARK_NODE_LAST_INLINE ;
440
- OK (runner , max_node_type < 32 , "all node types < 32" );
441
-
442
- int list_item_flag = 1 << CMARK_NODE_ITEM ;
443
- int top_level_blocks =
444
- (1 << CMARK_NODE_BLOCK_QUOTE ) | (1 << CMARK_NODE_LIST ) |
445
- (1 << CMARK_NODE_CODE_BLOCK ) | (1 << CMARK_NODE_HTML_BLOCK ) |
446
- (1 << CMARK_NODE_PARAGRAPH ) | (1 << CMARK_NODE_HEADING ) |
447
- (1 << CMARK_NODE_THEMATIC_BREAK );
448
- int all_inlines = (1 << CMARK_NODE_TEXT ) | (1 << CMARK_NODE_SOFTBREAK ) |
449
- (1 << CMARK_NODE_LINEBREAK ) | (1 << CMARK_NODE_CODE ) |
450
- (1 << CMARK_NODE_HTML_INLINE ) | (1 << CMARK_NODE_EMPH ) |
451
- (1 << CMARK_NODE_STRONG ) | (1 << CMARK_NODE_LINK ) |
452
- (1 << CMARK_NODE_IMAGE );
437
+ unsigned int list_item_flag [] = {CMARK_NODE_ITEM , 0 };
438
+ unsigned int top_level_blocks [] = {
439
+ CMARK_NODE_BLOCK_QUOTE , CMARK_NODE_LIST ,
440
+ CMARK_NODE_CODE_BLOCK , CMARK_NODE_HTML_BLOCK ,
441
+ CMARK_NODE_PARAGRAPH , CMARK_NODE_HEADING ,
442
+ CMARK_NODE_THEMATIC_BREAK , 0 };
443
+ unsigned int all_inlines [] = {
444
+ CMARK_NODE_TEXT , CMARK_NODE_SOFTBREAK ,
445
+ CMARK_NODE_LINEBREAK , CMARK_NODE_CODE ,
446
+ CMARK_NODE_HTML_INLINE , CMARK_NODE_EMPH ,
447
+ CMARK_NODE_STRONG , CMARK_NODE_LINK ,
448
+ CMARK_NODE_IMAGE , 0 };
453
449
454
450
test_content (runner , CMARK_NODE_DOCUMENT , top_level_blocks );
455
451
test_content (runner , CMARK_NODE_BLOCK_QUOTE , top_level_blocks );
@@ -472,15 +468,18 @@ void hierarchy(test_batch_runner *runner) {
472
468
}
473
469
474
470
static void test_content (test_batch_runner * runner , cmark_node_type type ,
475
- int allowed_content ) {
471
+ unsigned int * allowed_content ) {
476
472
cmark_node * node = cmark_node_new (type );
477
473
478
474
for (int i = 0 ; i < num_node_types ; ++ i ) {
479
475
cmark_node_type child_type = node_types [i ];
480
476
cmark_node * child = cmark_node_new (child_type );
481
477
482
478
int got = cmark_node_append_child (node , child );
483
- int expected = (allowed_content >> child_type ) & 1 ;
479
+ int expected = 0 ;
480
+ if (allowed_content )
481
+ for (unsigned int * p = allowed_content ; * p ; ++ p )
482
+ expected |= * p == child_type ;
484
483
485
484
INT_EQ (runner , got , expected , "add %d as child of %d" , child_type , type );
486
485
@@ -505,17 +504,17 @@ static void render_html(test_batch_runner *runner) {
505
504
cmark_parse_document (markdown , sizeof (markdown ) - 1 , CMARK_OPT_DEFAULT );
506
505
507
506
cmark_node * paragraph = cmark_node_first_child (doc );
508
- html = cmark_render_html (paragraph , CMARK_OPT_DEFAULT );
507
+ html = cmark_render_html (paragraph , CMARK_OPT_DEFAULT , NULL );
509
508
STR_EQ (runner , html , "<p>foo <em>bar</em></p>\n" , "render single paragraph" );
510
509
free (html );
511
510
512
511
cmark_node * string = cmark_node_first_child (paragraph );
513
- html = cmark_render_html (string , CMARK_OPT_DEFAULT );
512
+ html = cmark_render_html (string , CMARK_OPT_DEFAULT , NULL );
514
513
STR_EQ (runner , html , "foo " , "render single inline" );
515
514
free (html );
516
515
517
516
cmark_node * emph = cmark_node_next (string );
518
- html = cmark_render_html (emph , CMARK_OPT_DEFAULT );
517
+ html = cmark_render_html (emph , CMARK_OPT_DEFAULT , NULL );
519
518
STR_EQ (runner , html , "<em>bar</em>" , "render inline with children" );
520
519
free (html );
521
520
0 commit comments