Xonotic
markdown.qh File Reference
#include "test.qh"
+ Include dependency graph for markdown.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define X(expect, in)
 

Functions

ERASEABLE string markdown (string s)
 handle string spacing as markdown: More...
 
 TEST (Markdown, LineWrap)
 

Macro Definition Documentation

◆ X

#define X (   expect,
  in 
)
Value:
MACRO_BEGIN \
string out = markdown(in); \
EXPECT_TRUE(expect == out); \
LOG_INFO(expect); \
LOG_INFO(out); \
MACRO_END
ERASEABLE string markdown(string s)
handle string spacing as markdown:
Definition: markdown.qh:9

Referenced by TEST().

Function Documentation

◆ markdown()

ERASEABLE string markdown ( string  s)

handle string spacing as markdown:

  • two spaces escape a linebreak (otherwise text wraps)
  • two linebreaks become a paragraph (remain unchanged)

Definition at line 9 of file markdown.qh.

References chr2str, FOREACH_CHAR, and strcat().

10 {
11  string buf = "";
12  int lines = 0;
13  int spaces = 0;
14  FOREACH_CHAR(s, true, {
15  switch (it) {
16  default:
17  for (; spaces > 0; --spaces) {
18  buf = strcat(buf, " ");
19  }
20  buf = strcat(buf, chr2str(it));
21  break;
22  case ' ':
23  spaces += 1;
24  break;
25  case '\n':
26  lines += 1;
27  if (lines > 1) {
28  lines = 0;
29  spaces = 0;
30  buf = strcat(buf, "\n\n");
31  break;
32  }
33  if (spaces < 2) {
34  spaces = 1;
35  } else {
36  spaces = 0;
37  buf = strcat(buf, "\n");
38  }
39  break;
40  }
41  });
42  return buf;
43 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define FOREACH_CHAR(s, cond, body)
Definition: iter.qh:62
#define chr2str
Definition: dpextensions.qh:48
+ Here is the call graph for this function:

◆ TEST()

TEST ( Markdown  ,
LineWrap   
)

Definition at line 45 of file markdown.qh.

References SUCCEED, and X.

46 {
47  #define X(expect, in) MACRO_BEGIN \
48  string out = markdown(in); \
49  EXPECT_TRUE(expect == out); \
50  LOG_INFO(expect); \
51  LOG_INFO(out); \
52  MACRO_END
53 
54  // identity
55  X("lorem ipsum", "lorem ipsum");
56  // trim trailing space
57  X("lorem ipsum", "lorem ipsum ");
58  // allow manual input wrapping
59  X("lorem ipsum", "lorem\nipsum");
60  // line break
61  X("lorem\nipsum", "lorem \nipsum");
62  // paragraph
63  X("lorem\n\nipsum", "lorem\n\nipsum");
64  SUCCEED();
65  #undef X
66 }
#define X(expect, in)
#define SUCCEED()
Must be present at the end of a test.
Definition: test.qh:15