This repository has been archived by the owner on Sep 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.pwn
84 lines (69 loc) · 2.29 KB
/
test.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#define RUN_TESTS
#include <a_samp>
#include <YSI\y_testing>
#include "templates.inc"
main() {
//
}
Test:Simple() {
new Template:t = CreateTemplate("Hello, {{ name }}! Today is {{ date }}");
new rendered[64];
new ret = RenderTemplate(t, rendered, sizeof rendered,
PAIR_STR("name", "Southclaws"),
PAIR_STR("date", "Monday")
);
printf("ret: %d rendered: '%s'", ret, rendered);
ASSERT(ret == 0);
ASSERT(strcmp(rendered, "Hello, Southclaws! Today is Monday") == 0);
}
Test:Types() {
new Template:t = CreateTemplate("String: {{ string }} Int: {{ int }} Float: {{ float }}");
new rendered[64];
new ret = RenderTemplate(t, rendered, sizeof rendered,
PAIR_STR("string", "hello"),
PAIR_INT("int", 42),
PAIR_FLOAT("float", 5.5)
);
printf("ret: %d rendered: '%s'", ret, rendered);
ASSERT(ret == 0);
ASSERT(strcmp(rendered, "String: hello Int: 42 Float: 5.5") == 0);
}
Test:Conditionals() {
new Template:t = CreateTemplate("Hello {% if name %}{{ name }}{% else %}Anonymous{% endif %}.");
new rendered[64];
new ret = RenderTemplate(t, rendered, sizeof rendered,
PAIR_STR("name", "Southclaws")
);
printf("ret: %d rendered: '%s'", ret, rendered);
ASSERT(ret == 0);
ASSERT(strcmp(rendered, "Hello Southclaws.") == 0);
// no variables passed here
ret = RenderTemplate(t, rendered, sizeof rendered);
printf("ret: %d rendered: '%s'", ret, rendered);
ASSERT(ret == 0);
ASSERT(strcmp(rendered, "Hello Anonymous.") == 0);
}
Test:Filters() {
new Template:t = CreateTemplate("{{ name | upcase }}");
new rendered[64];
new ret = RenderTemplate(t, rendered, sizeof rendered,
PAIR_STR("name", "Southclaws")
);
printf("ret: %d rendered: '%s'", ret, rendered);
ASSERT(ret == 0);
ASSERT(strcmp(rendered, "SOUTHCLAWS") == 0);
}
Test:Assignment() {
new Template:t = CreateTemplate("\
{% assign fruits = \"apples, oranges, peaches\" %}\
{% if fruits %}\
{{ fruits }}\
{% endif %}");
new rendered[64];
new ret = RenderTemplate(t, rendered, sizeof rendered,
PAIR_STR("name", "Southclaws")
);
printf("ret: %d rendered: '%s'", ret, rendered);
ASSERT(ret == 0);
ASSERT(strcmp(rendered, "apples, oranges, peaches") == 0);
}