11/* help_render.c -- Plain-text markdown rendering unit test */
22
3+ #include <stdlib.h>
34#include <string.h>
45
56#include "mux/help/help_index.h"
67#include "mux/help/help_render.h"
78#include "mux/help/help_types.h"
89#include "mux/server/game.h"
910
10- /*
11- * help_render_markdown() never calls these (the render test never invokes
12- * help_article_render_body or help_render_send), but the object file
13- * references them; stub them out so this test can link help_render.c
14- * without pulling in help_index.c and its server-wide dependencies.
15- */
11+ static const HelpArticle * test_articles ;
12+ static size_t test_article_count ;
13+
1614char * help_index_read_body (const HelpIndex * index , const HelpArticle * article ,
1715 size_t * out_length ) {
1816 (void )index ;
1917 (void )article ;
20- (void )out_length ;
21- return nullptr ;
18+ char * body = malloc (1 );
19+
20+ body [0 ] = '\0' ;
21+ if (out_length )
22+ * out_length = 0 ;
23+ return body ;
2224}
2325
2426size_t help_index_article_count (const HelpIndex * index ) {
2527 (void )index ;
26- return 0 ;
28+ return test_article_count ;
2729}
2830
2931const HelpArticle * help_index_article_at (const HelpIndex * index ,
3032 size_t article_index ) {
3133 (void )index ;
32- (void )article_index ;
33- return nullptr ;
34+ return & test_articles [article_index ];
3435}
3536
3637void notify_checked (EvaluationContext * evaluation , DbRef target , DbRef sender ,
@@ -53,6 +54,47 @@ static int help_render_test_expect(const char *markdown, const char *expected) {
5354 return ok ;
5455}
5556
57+ static int help_render_test_index_links (void ) {
58+ char * index_tags [] = {"index-entry" };
59+ char * index_keywords [] = {"index" };
60+ char * topic_tags [] = {"index-entry" };
61+ char * topic_keywords [] = {"topic name" };
62+ HelpArticle articles [] = {
63+ {
64+ .keywords = {.items = index_keywords , .count = 1 },
65+ .show_index_for_article_tags = {.items = index_tags , .count = 1 },
66+ },
67+ {
68+ .description = "A linked help topic." ,
69+ .keywords = {.items = topic_keywords , .count = 1 },
70+ .article_tags = {.items = topic_tags , .count = 1 },
71+ },
72+ };
73+ HelpTextBuffer buffer ;
74+ int ok ;
75+
76+ test_articles = articles ;
77+ test_article_count = sizeof (articles ) / sizeof (articles [0 ]);
78+ help_text_buffer_init (& buffer );
79+ help_article_render_body (nullptr , & articles [0 ], false, & buffer );
80+ ok = buffer .data != nullptr &&
81+ !strcmp (buffer .data ,
82+ "TOPIC DESCRIPTION\n"
83+ "[send=\"help topic name\"]topic name[/] "
84+ "A linked help topic.\n" );
85+ help_text_buffer_free (& buffer );
86+ articles [0 ].index_style = HELP_INDEX_STYLE_COLUMNAR ;
87+ help_text_buffer_init (& buffer );
88+ help_article_render_body (nullptr , & articles [0 ], false, & buffer );
89+ ok = ok && buffer .data != nullptr &&
90+ !strcmp (buffer .data ,
91+ "[send=\"help topic name\"]topic name[/] \n" );
92+ help_text_buffer_free (& buffer );
93+ test_articles = nullptr ;
94+ test_article_count = 0 ;
95+ return ok ;
96+ }
97+
5698int main (void ) {
5799 if (!help_render_test_expect ("# Header 1\n\nContent here\n\n## Header 2\n" ,
58100 "# Header 1\n\nContent here\n\n## Header 2" ))
@@ -76,5 +118,7 @@ int main(void) {
76118 "```\n" ,
77119 "@name drone=[[fg=bright-cyan]Aegis[[/]\n" ))
78120 return 6 ;
121+ if (!help_render_test_index_links ())
122+ return 8 ;
79123 return 0 ;
80124}
0 commit comments