Skip to content

Commit 00eefd4

Browse files
committed
Add test for strict source positions
1 parent 161f7f1 commit 00eefd4

File tree

2 files changed

+170
-1
lines changed

2 files changed

+170
-1
lines changed

api_test/main.c

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ static void source_pos(test_batch_runner *runner) {
952952
" </paragraph>\n"
953953
" <block_quote sourcepos=\"6:1-10:20\">\n"
954954
" <list sourcepos=\"6:3-10:20\" type=\"ordered\" start=\"1\" delim=\"period\" tight=\"false\">\n"
955-
" <item sourcepos=\"6:3-8:1\">\n"
955+
" <item sourcepos=\"6:3-7:10\">\n"
956956
" <paragraph sourcepos=\"6:6-7:10\">\n"
957957
" <text sourcepos=\"6:6-6:10\" xml:space=\"preserve\">Okay.</text>\n"
958958
" <softbreak />\n"
@@ -1067,6 +1067,173 @@ static void ref_source_pos(test_batch_runner *runner) {
10671067
cmark_node_free(doc);
10681068
}
10691069

1070+
static void source_pos_pathological(test_batch_runner *runner) {
1071+
static const char markdown[] =
1072+
"> ```\n"
1073+
"> This code block is closed implicitly by the end of the block quote.\n"
1074+
"> \n"
1075+
"\n"
1076+
"> <pre>\n"
1077+
"> This HTML block is closed implicitly by the end of the block quote.\n"
1078+
"> \n"
1079+
"\n"
1080+
"- ```\n"
1081+
" This code block is closed implicitly by the end of the list item.\n"
1082+
" \n"
1083+
"- <pre>\n"
1084+
" This code block is closed implicitly by the end of the list item.\n"
1085+
" \n"
1086+
"- \n"
1087+
"\n"
1088+
" \n"
1089+
" Indented code block...\n"
1090+
" \n"
1091+
" doesn't contain trailing blank lines,\n"
1092+
" but it does contain trailing spaces at end of the line \n"
1093+
" \n"
1094+
"\n"
1095+
"```\n"
1096+
"Explicitly closed code block\n"
1097+
"```\n"
1098+
"\n"
1099+
"<pre>\n"
1100+
"Explicitly closed HTML block\n"
1101+
"</pre>\n"
1102+
"\n"
1103+
"\n"
1104+
"<!-- multiple HTML blocks --> <!-- in a line --> with trailing text.\n"
1105+
"\n"
1106+
"\n"
1107+
" Setext heading across\n"
1108+
" multiple lines\n"
1109+
" =====================\n"
1110+
"\n"
1111+
"\n"
1112+
"---\n"
1113+
"\n"
1114+
" ### ATX heading\n"
1115+
"\n"
1116+
"\n"
1117+
"[\n"
1118+
"foo\n"
1119+
"]:\n"
1120+
"/url\n"
1121+
"'\n"
1122+
"Link reference definitions followed by a paragraph\n"
1123+
"'\n"
1124+
"bar\n"
1125+
"\n"
1126+
"> [foo]: /url 'Block containing only link reference definitions'\n"
1127+
"\n"
1128+
"\n"
1129+
">\n"
1130+
"> \n"
1131+
"> \n"
1132+
"\n"
1133+
"\n"
1134+
" > Indented code block\n"
1135+
"> with offseted first line.\n"
1136+
"\n"
1137+
"> Indented code block\n"
1138+
" > with offseted second line.\n"
1139+
"\n"
1140+
"\n"
1141+
"- Empty list items\n"
1142+
"- \n"
1143+
"- -\n"
1144+
" - -\n";
1145+
1146+
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
1147+
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
1148+
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1149+
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1150+
"<document sourcepos=\"1:1-73:5\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1151+
" <block_quote sourcepos=\"1:1-3:4\">\n"
1152+
" <code_block sourcepos=\"1:3-3:4\" xml:space=\"preserve\">This code block is closed implicitly by the end of the block quote.\n"
1153+
" \n"
1154+
"</code_block>\n"
1155+
" </block_quote>\n"
1156+
" <block_quote sourcepos=\"5:1-7:4\">\n"
1157+
" <html_block sourcepos=\"5:3-7:4\" xml:space=\"preserve\">&lt;pre&gt;\n"
1158+
"This HTML block is closed implicitly by the end of the block quote.\n"
1159+
" \n"
1160+
"</html_block>\n"
1161+
" </block_quote>\n"
1162+
" <list sourcepos=\"9:1-15:2\" type=\"bullet\" tight=\"true\">\n"
1163+
" <item sourcepos=\"9:1-11:3\">\n"
1164+
" <code_block sourcepos=\"9:3-11:3\" xml:space=\"preserve\">This code block is closed implicitly by the end of the list item.\n"
1165+
" \n"
1166+
"</code_block>\n"
1167+
" </item>\n"
1168+
" <item sourcepos=\"12:1-14:3\">\n"
1169+
" <html_block sourcepos=\"12:3-14:3\" xml:space=\"preserve\">&lt;pre&gt;\n"
1170+
"This code block is closed implicitly by the end of the list item.\n"
1171+
" \n"
1172+
"</html_block>\n"
1173+
" </item>\n"
1174+
" <item sourcepos=\"15:1-15:2\" />\n"
1175+
" </list>\n"
1176+
" <code_block sourcepos=\"18:5-21:61\" xml:space=\"preserve\">Indented code block...\n"
1177+
"\n"
1178+
"doesn't contain trailing blank lines,\n"
1179+
"but it does contain trailing spaces at end of the line \n"
1180+
"</code_block>\n"
1181+
" <code_block sourcepos=\"24:1-26:3\" xml:space=\"preserve\">Explicitly closed code block\n"
1182+
"</code_block>\n"
1183+
" <html_block sourcepos=\"28:1-30:6\" xml:space=\"preserve\">&lt;pre&gt;\n"
1184+
"Explicitly closed HTML block\n"
1185+
"&lt;/pre&gt;\n"
1186+
"</html_block>\n"
1187+
" <html_block sourcepos=\"33:1-33:68\" xml:space=\"preserve\">&lt;!-- multiple HTML blocks --&gt; &lt;!-- in a line --&gt; with trailing text.\n"
1188+
"</html_block>\n"
1189+
" <heading sourcepos=\"36:3-38:23\" level=\"1\">\n"
1190+
" <text sourcepos=\"36:3-36:23\" xml:space=\"preserve\">Setext heading across</text>\n"
1191+
" <softbreak />\n"
1192+
" <text sourcepos=\"37:3-37:16\" xml:space=\"preserve\">multiple lines</text>\n"
1193+
" </heading>\n"
1194+
" <thematic_break sourcepos=\"41:1-41:3\" />\n"
1195+
" <heading sourcepos=\"43:2-43:16\" level=\"3\">\n"
1196+
" <text sourcepos=\"43:6-43:16\" xml:space=\"preserve\">ATX heading</text>\n"
1197+
" </heading>\n"
1198+
" <paragraph sourcepos=\"53:0-53:3\">\n"
1199+
" <text sourcepos=\"53:0-53:2\" xml:space=\"preserve\">bar</text>\n"
1200+
" </paragraph>\n"
1201+
" <block_quote sourcepos=\"55:1-55:66\" />\n"
1202+
" <block_quote sourcepos=\"58:1-60:3\" />\n"
1203+
" <block_quote sourcepos=\"63:4-64:31\">\n"
1204+
" <code_block sourcepos=\"63:10-64:31\" xml:space=\"preserve\">Indented code block\n"
1205+
"with offseted first line.\n"
1206+
"</code_block>\n"
1207+
" </block_quote>\n"
1208+
" <block_quote sourcepos=\"66:1-67:35\">\n"
1209+
" <code_block sourcepos=\"66:7-67:35\" xml:space=\"preserve\">Indented code block\n"
1210+
"with offseted second line.\n"
1211+
"</code_block>\n"
1212+
" </block_quote>\n"
1213+
" <list sourcepos=\"70:1-73:5\" type=\"bullet\" tight=\"true\">\n"
1214+
" <item sourcepos=\"70:1-70:18\">\n"
1215+
" <paragraph sourcepos=\"70:3-70:18\">\n"
1216+
" <text sourcepos=\"70:3-70:18\" xml:space=\"preserve\">Empty list items</text>\n"
1217+
" </paragraph>\n"
1218+
" </item>\n"
1219+
" <item sourcepos=\"71:1-71:4\" />\n"
1220+
" <item sourcepos=\"72:1-73:5\">\n"
1221+
" <list sourcepos=\"72:3-73:5\" type=\"bullet\" tight=\"true\">\n"
1222+
" <item sourcepos=\"72:3-72:3\" />\n"
1223+
" <item sourcepos=\"73:3-73:5\">\n"
1224+
" <list sourcepos=\"73:5-73:5\" type=\"bullet\" tight=\"true\">\n"
1225+
" <item sourcepos=\"73:5-73:5\" />\n"
1226+
" </list>\n"
1227+
" </item>\n"
1228+
" </list>\n"
1229+
" </item>\n"
1230+
" </list>\n"
1231+
"</document>\n",
1232+
"sourcepos are as expected");
1233+
free(xml);
1234+
cmark_node_free(doc);
1235+
}
1236+
10701237
int main(void) {
10711238
int retval;
10721239
test_batch_runner *runner = test_batch_runner_new();
@@ -1096,6 +1263,7 @@ int main(void) {
10961263
source_pos(runner);
10971264
source_pos_inlines(runner);
10981265
ref_source_pos(runner);
1266+
source_pos_pathological(runner);
10991267

11001268
test_print_summary(runner);
11011269
retval = test_ok(runner) ? 0 : 1;

test/regression.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,4 @@ Link reference definitions are blocks when checking list tightness.
404404
</li>
405405
</ul>
406406
````````````````````````````````
407+

0 commit comments

Comments
 (0)