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
|
#include "common.hh"
#include "tag.hh"
#include <gtest/gtest.h>
TEST(tag, empty) {
auto tag = Tag::create("br");
std::string out;
tag->render(&out);
EXPECT_EQ("<br/>", out);
}
TEST(tag, text) {
auto tag = Tag::create("p");
tag->add("Hello <b>World</b>!");
std::string out;
tag->render(&out);
EXPECT_EQ("<p>Hello <b>World</b>!</p>", out);
}
TEST(tag, tags_and_text) {
auto tag = Tag::create("p");
tag->add("Hello ");
tag->add_tag("b", "World");
tag->add("!");
EXPECT_FALSE(tag->empty());
std::string out;
tag->render(&out);
EXPECT_EQ("<p>Hello <b>World</b>!</p>", out);
tag->clear_content();
EXPECT_TRUE(tag->empty());
tag->add("Goodbye");
out.clear();
tag->render(&out);
EXPECT_EQ("<p>Goodbye</p>", out);
}
TEST(tag, onclick) {
auto tag = Tag::create("a");
tag->add("Link");
tag->attr("href", "http://example.org");
tag->attr("onclick", "alert('Hello World');");
std::string out;
tag->render(&out);
EXPECT_EQ("<a href=\"http://example.org\" onclick=\"alert('Hello World');\">Link</a>", out);
}
TEST(tag, script_with_content) {
auto tag = Tag::create("script");
tag->add("alert('Hello <b>World</b>');");
std::string out;
tag->render(&out);
EXPECT_EQ("<script>alert('Hello <b>World</b>');</script>", out);
}
TEST(tag, script_with_src) {
auto tag = Tag::create("script");
tag->attr("src", "/js/helloworld.js");
std::string out;
tag->render(&out);
EXPECT_EQ("<script src=\"/js/helloworld.js\"></script>", out);
}
|