diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
| commit | 6232d13f5321b87ddf12a1aa36b4545da45f173d (patch) | |
| tree | 23f3316470a14136debd9d02f9e920ca2b06f4cc /test/test_tag.cc | |
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in
memroy.
Diffstat (limited to 'test/test_tag.cc')
| -rw-r--r-- | test/test_tag.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/test_tag.cc b/test/test_tag.cc new file mode 100644 index 0000000..d65f8d2 --- /dev/null +++ b/test/test_tag.cc @@ -0,0 +1,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); +} |
