@@ -558,9 +558,48 @@ TEST(rst_ship_gate) {
558558 PASS ();
559559}
560560
561+ /* A section's text is cut before the first character that does not fit its
562+ * 500 bytes: only whole characters are written, and the text ends at the last
563+ * one written (it once tested an unwritten byte past the end, so where the
564+ * text ended depended on what that memory held). */
565+ TEST (rst_section_text_cut ) {
566+ static const struct {
567+ const char * tail ;
568+ const char * want_tail ;
569+ } cases [] = {
570+ {" xxxxx tail" , " xxxxx" }, /* a word that ends at byte 500 */
571+ {" xxxx\xc3\xa9 more" , " xxxx" }, /* a two-byte character that would cross it */
572+ {" yyyyyyyy" , " yyyyy" }, /* a word cut at a character */
573+ };
574+ for (size_t c = 0 ; c < sizeof (cases ) / sizeof (cases [0 ]); c ++ ) {
575+ char doc [1024 ];
576+ char want [600 ];
577+ int n = snprintf (doc , sizeof (doc ), "Title\n=====\n\n" );
578+ int w = 0 ;
579+ for (int k = 0 ; k < 99 ; k ++ ) { /* 99 words: 494 bytes, nine per paragraph */
580+ n += snprintf (doc + n , sizeof (doc ) - (size_t )n , "%sabcd" ,
581+ k == 0 ? ""
582+ : k % 9 == 0 ? "\n\n"
583+ : " " );
584+ w += snprintf (want + w , sizeof (want ) - (size_t )w , "%sabcd" , k ? " " : "" );
585+ }
586+ snprintf (doc + n , sizeof (doc ) - (size_t )n , "%s\n" , cases [c ].tail );
587+ snprintf (want + w , sizeof (want ) - (size_t )w , "%s" , cases [c ].want_tail );
588+ CBMFileResult * r = dm_extract (doc , CBM_LANG_RST , "docs/cut.rst" );
589+ ASSERT_NOT_NULL (r );
590+ const CBMDefinition * t = rst_def (r , "Section" , "Title" );
591+ ASSERT_NOT_NULL (t );
592+ ASSERT_NOT_NULL (t -> docstring );
593+ ASSERT_STR_EQ (t -> docstring , want );
594+ cbm_free_result (r );
595+ }
596+ PASS ();
597+ }
598+
561599SUITE (doc_links_rst ) {
562600 dm_ship_held_families ();
563601 RUN_TEST (rst_scan_structure );
602+ RUN_TEST (rst_section_text_cut );
564603 RUN_TEST (rst_python_scope_blob );
565604 RUN_TEST (rst_links_pipeline );
566605 RUN_TEST (rst_c_member_owner );
0 commit comments