-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathif_test.cpp
94 lines (73 loc) · 1.66 KB
/
if_test.cpp
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
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <string>
#include "gtest/gtest.h"
#include "jinja2cpp/template.h"
using namespace jinja2;
TEST(IfTest, IfTrueTest)
{
std::string source = R"(
{% if TrueVal %}
Hello from Jinja template!
{% endif %}
)";
Template tpl;
ASSERT_TRUE(tpl.Load(source));
ValuesMap params = {
{"TrueVal", true},
{"FalseVal", true},
};
std::string result = tpl.RenderAsString(params).value();
std::cout << result << std::endl;
std::string expectedResult = R"(
Hello from Jinja template!
)";
EXPECT_EQ(expectedResult, result);
}
TEST(IfTest, IfFalseTest)
{
std::string source = R"(
{% if FalseVal %}
Hello from Jinja template!
{% else %}
Else branch triggered!
{% endif %}
)";
Template tpl;
ASSERT_TRUE(tpl.Load(source));
ValuesMap params = {
{"TrueVal", true},
{"FalseVal", false},
};
std::string result = tpl.RenderAsString(params).value();
std::cout << result << std::endl;
std::string expectedResult = R"(
Else branch triggered!
)";
EXPECT_EQ(expectedResult, result);
}
TEST(IfTest, ElseIfTrueTest)
{
std::string source = R"(
{% if FalseVal %}
Hello from Jinja template!
{% elif FalseVal %}
ElseIf 1 branch triggered!
{% elif TrueVal %}
ElseIf 2 branch triggered!
{% else %}
ElseIf branch triggered!
{% endif %}
)";
Template tpl;
ASSERT_TRUE(tpl.Load(source));
ValuesMap params = {
{"TrueVal", true},
{"FalseVal", false},
};
std::string result = tpl.RenderAsString(params).value();
std::cout << result << std::endl;
std::string expectedResult = R"(
ElseIf 2 branch triggered!
)";
EXPECT_EQ(expectedResult, result);
}