Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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:
 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); \
#define MACRO_END
Definition macro.qh:7
ERASEABLE string markdown(string s)
Handle string spacing as markdown:
Definition markdown.qh:7

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 7 of file markdown.qh.

8{
9 string buf = "";
10 int lines = 0;
11 int spaces = 0;
12 FOREACH_CHAR(s, true,
13 {
14 switch (it)
15 {
16 default:
17 for (; spaces > 0; --spaces)
18 buf = strcat(buf, " ");
19 buf = strcat(buf, chr2str(it));
20 break;
21 case ' ':
22 ++spaces;
23 break;
24 case '\n':
25 ++lines;
26 if (lines > 1)
27 {
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 {
37 spaces = 0;
38 buf = strcat(buf, "\n");
39 }
40 break;
41 }
42 });
43 return buf;
44}
#define chr2str
#define FOREACH_CHAR(s, cond, body)
Definition iter.qh:61
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References chr2str, FOREACH_CHAR, and strcat().

◆ TEST()

TEST ( Markdown ,
LineWrap  )

Definition at line 46 of file markdown.qh.

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

References SUCCEED, and X.