From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- test/test_tag.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/test_tag.cc (limited to 'test/test_tag.cc') 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 + +TEST(tag, empty) { + auto tag = Tag::create("br"); + std::string out; + tag->render(&out); + EXPECT_EQ("
", out); +} + +TEST(tag, text) { + auto tag = Tag::create("p"); + tag->add("Hello World!"); + std::string out; + tag->render(&out); + EXPECT_EQ("

Hello <b>World</b>!

", 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("

Hello World!

", out); + tag->clear_content(); + EXPECT_TRUE(tag->empty()); + tag->add("Goodbye"); + out.clear(); + tag->render(&out); + EXPECT_EQ("

Goodbye

", 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("Link", out); +} + +TEST(tag, script_with_content) { + auto tag = Tag::create("script"); + tag->add("alert('Hello World');"); + std::string out; + tag->render(&out); + EXPECT_EQ("", 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("", out); +} -- cgit v1.2.3-70-g09d2