2024-05-05 23:31:42 +02:00
# include <string>
# include <include/docpp.hpp>
# include <src/docpp.cpp>
# include <catch2/catch_test_macros.hpp>
/**
2024-05-07 00:08:54 +02:00
* @ brief Test cases for the docpp namespace .
2024-05-05 23:31:42 +02:00
*/
SCENARIO ( " Test HTML " , " [HTML] " ) {
2024-05-12 20:05:23 +02:00
const auto test1 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Document doc { } ;
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section html ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section head ( docpp : : HTML : : ELEMENT_HEAD , { } ) ;
docpp : : HTML : : Section body ( docpp : : HTML : : ELEMENT_BODY , { } ) ;
docpp : : HTML : : Section div ( docpp : : HTML : : ELEMENT_DIV , { } ) ;
docpp : : HTML : : Section footer ( docpp : : HTML : : ELEMENT_FOOTER , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
head . push_back ( docpp : : HTML : : Element ( " title " , { } , " Test Title " ) ) ;
body . push_back ( docpp : : HTML : : Element ( " h1 " , { } , " Test Header " ) ) ;
body . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test Paragraph " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Properties prop { } ;
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " id " , " test_id " ) ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
body . push_back ( docpp : : HTML : : Element ( " p " , prop , " Test Paragraph With ID " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
div . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test Paragraph In Div " ) ) ;
2024-05-05 23:31:42 +02:00
body . push_back ( div ) ;
2024-05-12 20:18:06 +02:00
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " class " , " class1 class2 class3 " ) ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
body . push_back ( docpp : : HTML : : Element ( " p " , prop , " Test Paragraph With ID And Class " ) ) ;
2024-05-05 23:31:42 +02:00
html . push_back ( head ) ;
html . push_back ( body ) ;
html . push_back ( footer ) ;
doc . set ( html ) ;
const std : : string expected_html { " <!DOCTYPE html><html><head><title>Test Title</title></head><body><h1>Test Header</h1><p>Test Paragraph</p><p id= \" test_id \" >Test Paragraph With ID</p><div><p>Test Paragraph In Div</p></div><p id= \" test_id \" class= \" class1 class2 class3 \" >Test Paragraph With ID And Class</p></body><footer></footer></html> " } ;
2024-05-14 10:04:32 +02:00
REQUIRE ( doc . get < std : : string > ( ) = = expected_html ) ;
REQUIRE ( doc . get < std : : string > ( docpp : : HTML : : FORMATTING_NEWLINE ) = = " <!DOCTYPE html> \n <html> \n <head> \n <title>Test Title</title> \n </head> \n <body> \n <h1>Test Header</h1> \n <p>Test Paragraph</p> \n <p id= \" test_id \" >Test Paragraph With ID</p> \n <div> \n <p>Test Paragraph In Div</p> \n </div> \n <p id= \" test_id \" class= \" class1 class2 class3 \" >Test Paragraph With ID And Class</p> \n </body> \n <footer> \n </footer> \n </html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test2 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . erase ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 1</p><p>Test 3</p></html> " ) ;
REQUIRE ( section . get < std : : string > ( docpp : : HTML : : FORMATTING_NEWLINE ) = = " <html> \n <p>Test 1</p> \n <p>Test 3</p> \n </html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test3 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 21:56:03 +02:00
std : : size_t pos = section . find ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
2024-05-12 20:18:06 +02:00
section . insert ( pos , docpp : : HTML : : Element ( " p " , { } , " Test 2.5 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 1</p><p>Test 2.5</p><p>Test 3</p></html> " ) ;
REQUIRE ( section . get < std : : string > ( docpp : : HTML : : FORMATTING_NEWLINE ) = = " <html> \n <p>Test 1</p> \n <p>Test 2.5</p> \n <p>Test 3</p> \n </html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test4 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 21:56:03 +02:00
std : : size_t pos = section . find ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
2024-05-05 23:31:42 +02:00
section . erase ( pos ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 1</p><p>Test 3</p></html> " ) ;
REQUIRE ( section . get < std : : string > ( docpp : : HTML : : FORMATTING_NEWLINE ) = = " <html> \n <p>Test 1</p> \n <p>Test 3</p> \n </html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test5 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
docpp : : HTML : : Section subsection ( docpp : : HTML : : ELEMENT_DIV , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
subsection . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section subsection2 ( docpp : : HTML : : ELEMENT_DIV , { } ) ;
2024-05-12 20:18:06 +02:00
subsection2 . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
2024-05-05 23:31:42 +02:00
subsection . push_back ( subsection2 ) ;
section . push_back ( subsection ) ;
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Document doc { } ;
2024-05-05 23:31:42 +02:00
doc . set ( section ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( doc . get < std : : string > ( ) = = " <!DOCTYPE html><html><div><p>Test 1</p><div><p>Test 2</p></div></div></html> " ) ;
REQUIRE ( doc . get < std : : string > ( docpp : : HTML : : FORMATTING_NEWLINE ) = = " <!DOCTYPE html> \n <html> \n <div> \n <p>Test 1</p> \n <div> \n <p>Test 2</p> \n </div> \n </div> \n </html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test6 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : CSS : : Stylesheet css { } ;
docpp : : CSS : : Element element { " p " , { { " color " , " red " } , { " font-size " , " 16px " } , { " font-family " , " Arial " } } } ;
2024-05-05 23:31:42 +02:00
css . push_back ( element ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( css . get < std : : string > ( ) = = " p {color: red;font-size: 16px;font-family: Arial;} " ) ;
REQUIRE ( css . get < std : : string > ( docpp : : CSS : : FORMATTING_NEWLINE ) = = " p { \n color: red; \n font-size: 16px; \n font-family: Arial; \n } \n " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test7 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : CSS : : Stylesheet css = docpp : : CSS : : Stylesheet { } ;
docpp : : CSS : : Element element = docpp : : CSS : : Element { " p " , { { " color " , " red " } , { " font-size " , " 16px " } , { " font-family " , " Arial " } } } ;
docpp : : CSS : : Element element2 { " div " , { { " color " , " blue " } , { " font-size " , " 12px " } , { " font-family " , " Arial " } } } ;
2024-05-05 23:31:42 +02:00
css . push_back ( element ) ;
css . push_front ( element2 ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( css . get < std : : string > ( ) = = " div {color: blue;font-size: 12px;font-family: Arial;}p {color: red;font-size: 16px;font-family: Arial;} " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test8 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : CSS : : Stylesheet css = docpp : : CSS : : Stylesheet { } ;
docpp : : CSS : : Element element = docpp : : CSS : : Element { " p " , { { " color " , " red " } , { " font-size " , " 16px " } , { " font-family " , " Arial " } } } ;
docpp : : CSS : : Element element2 { " div " , { { " color " , " blue " } , { " font-size " , " 12px " } , { " font-family " , " Arial " } } } ;
2024-05-05 23:31:42 +02:00
css . push_back ( element ) ;
css . push_front ( element2 ) ;
css . erase ( css . find ( element2 ) ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( css . get < std : : string > ( ) = = " p {color: red;font-size: 16px;font-family: Arial;} " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test9 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : CSS : : Stylesheet css = docpp : : CSS : : Stylesheet { } ;
docpp : : CSS : : Element element = docpp : : CSS : : Element { " p " , { { " color " , " red " } , { " font-size " , " 16px " } , { " font-family " , " Arial " } } } ;
docpp : : CSS : : Element element2 { " div " , { { " color " , " blue " } , { " font-size " , " 12px " } , { " font-family " , " Arial " } } } ;
2024-05-05 23:31:42 +02:00
css . push_back ( element ) ;
css . push_front ( element2 ) ;
css . erase ( css . find ( element2 ) ) ;
css . push_front ( element2 ) ;
css . swap ( css . find ( element ) , css . find ( element2 ) ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( css . get < std : : string > ( ) = = " p {color: red;font-size: 16px;font-family: Arial;}div {color: blue;font-size: 12px;font-family: Arial;} " ) ;
2024-05-06 11:06:45 +02:00
2024-05-12 20:18:06 +02:00
element . push_front ( docpp : : CSS : : Property ( " font-weight " , " bold " ) ) ;
2024-05-06 11:06:45 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( element . get < std : : string > ( ) = = " p {font-weight: bold;color: red;font-size: 16px;font-family: Arial;} " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test10 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . swap ( section . find ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) , section . find ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 1</p><p>Test 3</p><p>Test 2</p></html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test11 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . swap ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) , docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 1</p><p>Test 3</p><p>Test 2</p></html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test12 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-12 20:18:06 +02:00
section . push_front ( docpp : : HTML : : Element ( " p " , { } , " Test 0 " ) ) ;
2024-05-05 23:31:42 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 0</p><p>Test 1</p><p>Test 2</p><p>Test 3</p></html> " ) ;
2024-05-05 23:31:42 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test13 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-06 02:45:15 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 4 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 5 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 6 " ) ) ;
2024-05-06 02:45:15 +02:00
2024-05-12 21:56:03 +02:00
const std : : size_t pos { section . find ( " <p>Test 2</p> " ) } ;
2024-05-06 02:45:15 +02:00
2024-05-12 20:18:06 +02:00
REQUIRE ( pos ! = docpp : : HTML : : Section : : npos ) ;
2024-05-06 02:45:15 +02:00
2024-05-12 21:56:03 +02:00
const std : : size_t pos2 { section . find ( " <p>Test 6</p> " ) } ;
2024-05-06 02:45:15 +02:00
section . erase ( pos ) ;
section . erase ( pos2 ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <html><p>Test 1</p><p>Test 3</p><p>Test 4</p><p>Test 5</p></html> " ) ;
2024-05-06 02:45:15 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test14 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : CSS : : Element element { " p " , { { " color " , " red " } , { " font-size " , " 16px " } , { " font-family " , " Arial " } } } ;
2024-05-06 11:47:24 +02:00
const int red = element . find ( " color " ) ;
2024-05-12 20:18:06 +02:00
REQUIRE ( red ! = docpp : : CSS : : Element : : npos ) ;
2024-05-06 11:47:24 +02:00
const int blue = element . find ( " blue " ) ;
2024-05-12 20:18:06 +02:00
REQUIRE ( blue = = docpp : : CSS : : Element : : npos ) ;
2024-05-06 11:47:24 +02:00
element . erase ( red ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( element . get < std : : string > ( ) = = " p {font-size: 16px;font-family: Arial;} " ) ;
2024-05-06 11:47:24 +02:00
2024-05-12 20:18:06 +02:00
element . insert ( red , docpp : : CSS : : Property ( " color " , " red " ) ) ;
2024-05-06 11:47:24 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( element . get < std : : string > ( ) = = " p {color: red;font-size: 16px;font-family: Arial;} " ) ;
2024-05-06 11:47:24 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test15 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Properties prop { } ;
2024-05-06 13:19:16 +02:00
2024-05-12 20:18:06 +02:00
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " id " , " test_id " ) ) ) ;
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " class " , " class1 class2 class3 " ) ) ) ;
2024-05-06 13:19:16 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( docpp : : HTML : : Element ( " p " , prop , { } ) . get < std : : string > ( ) = = " <p id= \" test_id \" class= \" class1 class2 class3 \" ></p> " ) ;
2024-05-06 13:19:16 +02:00
const int pos = prop . find ( " class " ) ;
2024-05-12 20:18:06 +02:00
REQUIRE ( pos ! = docpp : : HTML : : Properties : : npos ) ;
2024-05-06 13:19:16 +02:00
const int pos2 = prop . find ( " class2 " ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( prop . at ( pos2 ) . get_key < std : : string > ( ) = = " class " ) ;
REQUIRE ( prop . at ( pos2 ) . get_value < std : : string > ( ) = = " class1 class2 class3 " ) ;
2024-05-06 14:18:01 +02:00
2024-05-12 20:18:06 +02:00
REQUIRE ( pos2 ! = docpp : : HTML : : Properties : : npos ) ;
2024-05-06 13:19:16 +02:00
const int pos3 = prop . find ( " class4 " ) ;
2024-05-12 20:18:06 +02:00
REQUIRE ( pos3 = = docpp : : HTML : : Properties : : npos ) ;
2024-05-06 13:19:16 +02:00
prop . erase ( pos ) ;
2024-05-14 10:04:32 +02:00
REQUIRE ( docpp : : HTML : : Element ( " p " , prop , { } ) . get < std : : string > ( ) = = " <p id= \" test_id \" ></p> " ) ;
2024-05-06 13:19:16 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test16 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Document doc = docpp : : HTML : : Section ( { } ) ;
2024-05-07 00:08:54 +02:00
2024-05-13 12:00:47 +02:00
doc . get_section ( ) . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
doc . get_section ( ) . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
doc . get_section ( ) . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-07 00:08:54 +02:00
2024-05-15 10:21:39 +02:00
doc . get_section ( ) = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-07 00:08:54 +02:00
2024-05-13 12:00:47 +02:00
doc . get_section ( ) . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 4 " ) ) ;
doc . get_section ( ) . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 5 " ) ) ;
doc . get_section ( ) . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 6 " ) ) ;
2024-05-07 00:08:54 +02:00
2024-05-13 12:00:47 +02:00
doc . get_section ( ) + = docpp : : HTML : : Element ( " p " , { } , " Test 7 " ) ;
2024-05-07 00:08:54 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( doc . get < std : : string > ( ) = = " <!DOCTYPE html><html><p>Test 4</p><p>Test 5</p><p>Test 6</p><p>Test 7</p></html> " ) ;
2024-05-07 00:08:54 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test17 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-07 17:26:11 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-07 17:26:11 +02:00
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Document doc { section } ;
2024-05-07 17:26:11 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( doc . get < std : : string > ( docpp : : HTML : : FORMATTING_PRETTY ) = = " <!DOCTYPE html> \n <html> \n \t <p>Test 1</p> \n \t <p>Test 2</p> \n \t <p>Test 3</p> \n </html> " ) ;
2024-05-07 17:26:11 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test18 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_EMPTY , { } ) ;
2024-05-07 21:21:58 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-07 21:21:58 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . get < std : : string > ( ) = = " <p>Test 1</p><p>Test 2</p><p>Test 3</p> " ) ;
2024-05-07 21:21:58 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test19 = [ ] ( ) {
2024-05-15 10:21:39 +02:00
docpp : : HTML : : Section section = docpp : : HTML : : Section ( docpp : : HTML : : ELEMENT_HTML , { } ) ;
2024-05-07 22:58:53 +02:00
2024-05-12 20:18:06 +02:00
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
section . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-07 22:58:53 +02:00
2024-05-14 10:04:32 +02:00
REQUIRE ( section . front ( ) . get < std : : string > ( ) = = " <p>Test 1</p> " ) ;
REQUIRE ( section . back ( ) . get < std : : string > ( ) = = " <p>Test 3</p> " ) ;
2024-05-07 22:58:53 +02:00
} ;
2024-05-12 20:05:23 +02:00
const auto test20 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Properties prop { } ;
2024-05-12 20:05:23 +02:00
2024-05-12 20:18:06 +02:00
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " id " , " test_id " ) ) ) ;
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " class " , " class1 class2 class3 " ) ) ) ;
prop . push_back ( docpp : : HTML : : Property ( std : : pair < std : : string , std : : string > ( " style " , " color: red; font-size: 16px; font-family: Arial; " ) ) ) ;
2024-05-12 20:05:23 +02:00
2024-05-12 20:18:06 +02:00
for ( const docpp : : HTML : : Property & p : prop ) {
2024-05-14 10:04:32 +02:00
REQUIRE ( p . get_key < std : : string > ( ) = = " id " ) ;
REQUIRE ( p . get_value < std : : string > ( ) = = " test_id " ) ;
2024-05-12 20:05:23 +02:00
break ;
}
2024-05-12 20:18:06 +02:00
for ( docpp : : HTML : : Properties : : iterator it = + + prop . begin ( ) ; it ! = prop . end ( ) ; + + it ) {
2024-05-14 10:04:32 +02:00
REQUIRE ( it - > get_key < std : : string > ( ) = = " class " ) ;
REQUIRE ( it - > get_value < std : : string > ( ) = = " class1 class2 class3 " ) ;
2024-05-12 20:05:23 +02:00
break ;
}
} ;
const auto test21 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Section sect { } ;
2024-05-12 20:05:23 +02:00
2024-05-12 20:18:06 +02:00
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-12 20:05:23 +02:00
2024-05-12 20:18:06 +02:00
for ( const docpp : : HTML : : Element & elem : sect ) {
2024-05-14 10:04:32 +02:00
REQUIRE ( elem . get < std : : string > ( ) = = " <p>Test 1</p> " ) ;
2024-05-12 20:05:23 +02:00
break ;
}
2024-05-12 20:18:06 +02:00
for ( docpp : : HTML : : Section : : iterator it = + + sect . begin ( ) ; it ! = sect . end ( ) ; + + it ) {
docpp : : HTML : : Element elem = * it ;
2024-05-14 10:04:32 +02:00
REQUIRE ( elem . get < std : : string > ( ) = = " <p>Test 2</p> " ) ;
2024-05-12 20:05:23 +02:00
break ;
}
} ;
const auto test22 = [ ] ( ) {
2024-05-12 20:18:06 +02:00
docpp : : HTML : : Section sect { } ;
2024-05-12 20:05:23 +02:00
2024-05-12 20:18:06 +02:00
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
2024-05-12 20:05:23 +02:00
bool caught { false } ;
try {
sect . at ( 1337 ) ;
} catch ( const docpp : : out_of_range & e ) {
caught = true ;
}
REQUIRE ( caught ) ;
} ;
2024-05-12 23:43:44 +02:00
const auto test23 = [ ] ( ) {
docpp : : HTML : : Section sect { } ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 1 " ) ) ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 2 " ) ) ;
sect . push_back ( docpp : : HTML : : Element ( " p " , { } , " Test 3 " ) ) ;
REQUIRE ( sect . get < std : : string > ( ) = = " <p>Test 1</p><p>Test 2</p><p>Test 3</p> " ) ;
} ;
2024-05-07 00:08:54 +02:00
std : : vector < void ( * ) ( ) > tests {
test1 ,
test2 ,
test3 ,
test4 ,
test5 ,
test6 ,
test7 ,
test8 ,
test9 ,
test10 ,
test11 ,
test12 ,
test13 ,
test14 ,
test15 ,
test16 ,
2024-05-07 17:26:11 +02:00
test17 ,
2024-05-07 21:21:58 +02:00
test18 ,
2024-05-07 22:58:53 +02:00
test19 ,
2024-05-12 20:05:23 +02:00
test20 ,
test21 ,
test22 ,
2024-05-12 23:43:44 +02:00
test23 ,
2024-05-07 00:08:54 +02:00
} ;
2024-05-05 23:31:42 +02:00
for ( const auto & test : tests ) {
test ( ) ;
}
}