source: appstream-generator/contrib/subprojects/mustache-d-0.1.3/example/whitespace_spec.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 1.8 KB
Line 
1import mustache;
2import std.stdio;
3
4alias MustacheEngine!(string) Mustache;
5
6void main()
7{
8    Mustache mustache;
9    auto context = new Mustache.Context;
10    context.useSection("boolean");
11
12    // from https://github.com/mustache/spec/blob/master/specs/sections.yml
13    assert(mustache.renderString(" | {{#boolean}}\t|\t{{/boolean}} | \n", context) == " | \t|\t | \n");
14    assert(mustache.renderString(" | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n", context) == " |  \n  | \n");
15    assert(mustache.renderString(" {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n", context) == " YES\n GOOD\n");
16    assert(mustache.renderString("#{{#boolean}}\n/\n  {{/boolean}}", context) == "#\n/\n");
17    assert(mustache.renderString("  {{#boolean}}\n#{{/boolean}}\n/", context) == "#\n/");
18
19    auto expected = `This Is
20
21A Line`;
22    auto t = `This Is
23  {{#boolean}}
24
25  {{/boolean}}
26A Line`;
27    assert(mustache.renderString(t, context) == expected);
28
29    auto t2 = `This Is
30  {{#boolean}}
31
32  {{/boolean}}
33A Line`;
34    assert(mustache.renderString(t, context) == expected);
35
36    // TODO: \r\n support
37
38    issue2();
39    issue9();
40}
41
42void issue2()
43{
44    Mustache mustache;
45    auto context = new Mustache.Context;
46    context["module_name"] = "mustache";
47    context.useSection("static_imports");
48
49    auto text = `module {{module_name}};
50
51{{#static_imports}}
52/*
53 * Auto-generated static imports
54 */
55{{/static_imports}}`;
56
57    assert(mustache.renderString(text, context) == `module mustache;
58
59/*
60 * Auto-generated static imports
61 */
62`);
63}
64
65void issue9()
66{
67    Mustache mustache;
68    auto context = new Mustache.Context;
69    context.useSection("section");
70
71    auto text = `FOO
72
73{{#section}}BAR{{/section}}`;
74
75    assert(mustache.renderString(text, context) == `FOO
76
77BAR`);
78}
Note: See TracBrowser for help on using the repository browser.