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
|
// -*- mode: c++; c-basic-offset: 2; -*-
#include "common.hh"
#include "test.hh"
#include <memory>
#include "gui_htmlattrtext.hh"
namespace {
bool test_sanity() {
std::unique_ptr<HtmlAttributedText> attr(HtmlAttributedText::create());
HtmlAttributedText::Attribute red(0xff, 0, 0);
HtmlAttributedText::Attribute bold;
HtmlAttributedText::Attribute green(0, 0xff, 0);
bold.set_bold(true);
ASSERT_EQ("", attr->html());
attr->append("Hello World");
ASSERT_EQ("Hello World", attr->html());
attr->append(" <!>", red);
ASSERT_EQ("Hello World<span style=\"color: rgb(255, 0, 0); \"> <!></span>", attr->html());
attr->add(bold, 0, 5);
ASSERT_EQ("<span style=\"font-weight: bold; \">Hello</span> World<span style=\"color: rgb(255, 0, 0); \"> <!></span>", attr->html());
attr->add(red, 1, 2);
ASSERT_EQ("<span style=\"font-weight: bold; \">H<span style=\"color: rgb(255, 0, 0); \">el</span>lo</span> World<span style=\"color: rgb(255, 0, 0); \"> <!></span>", attr->html());
attr->set(green, 1, 1);
ASSERT_EQ("<span style=\"font-weight: bold; \">H</span><span style=\"color: rgb(0, 255, 0); \">e</span><span style=\"font-weight: bold; \"><span style=\"color: rgb(255, 0, 0); \">l</span>lo</span> World<span style=\"color: rgb(255, 0, 0); \"> <!></span>", attr->html());
return true;
}
} // namespace
int main(void) {
BEFORE;
RUN(test_sanity());
AFTER;
}
|