Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
markdown.qh
Go to the documentation of this file.
1#include "test.qh"
2
7string markdown(string s)
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}
45
46TEST(Markdown, LineWrap)
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 chr2str
#define FOREACH_CHAR(s, cond, body)
Definition iter.qh:61
#define ERASEABLE
Definition _all.inc:37
#define X(expect, in)
ERASEABLE string markdown(string s)
Handle string spacing as markdown:
Definition markdown.qh:7
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define TEST(suite, test)
Use UpperCamelCase for suite and test only.
Definition test.qh:6
#define SUCCEED()
Must be present at the end of a test.
Definition test.qh:17