From 95f19d7f02b5cc4c58eb493a0eda15913830e3d8 Mon Sep 17 00:00:00 2001 From: Vedant Date: Tue, 19 Sep 2023 00:35:33 +0530 Subject: [PATCH] Added unit tests for DOM elements, and modified Test's grammar for uniformity Signed-off-by: Vedant --- examples/text.qf | 4 +- examples/text_styles.qf | 6 +- include/quick-ftxui.hpp | 6 +- tests/test1.cpp | 130 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 8 deletions(-) diff --git a/examples/text.qf b/examples/text.qf index d3a2aa2..039a2df 100644 --- a/examples/text.qf +++ b/examples/text.qf @@ -1,5 +1,5 @@ Vertical { - bold BlueLight Text("The given button opens chrome in Linux") + BlueLight bold Text("The given button opens chrome in Linux") str a Red Button { "chrome", @@ -7,7 +7,7 @@ Vertical { Animated, a } - strikethrough Green Text("This text is Green") + Green strikethrough Text("This text is Green") Button { "Exit", "Exit" diff --git a/examples/text_styles.qf b/examples/text_styles.qf index d7e5a5d..7db6097 100644 --- a/examples/text_styles.qf +++ b/examples/text_styles.qf @@ -1,11 +1,11 @@ Vertical { Text("This is normal") - bold Yellow Text("This is bold, yellow text") + Yellow bold Text("This is bold, yellow text") dim Text("This is dim") underlined Text("Underlined text") - underlinedDouble Magenta Text("Double underlines!!") + Magenta underlinedDouble Text("Double underlines!!") blink Text("This is blinking") - inverted Red Text("This has an inverted look") + Red inverted Text("This has an inverted look") strikethrough Text("This is strikethrough") Red Button { "X", diff --git a/include/quick-ftxui.hpp b/include/quick-ftxui.hpp index 53bd25a..3c36a44 100644 --- a/include/quick-ftxui.hpp +++ b/include/quick-ftxui.hpp @@ -179,8 +179,8 @@ struct dropdown { }; struct dom_text { - text_style style = text_style::none; colours color = colours::Default; + text_style style = text_style::none; std::string content = ""; }; @@ -293,8 +293,8 @@ BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::dropdown, ) BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::dom_text, - (quick_ftxui_ast::text_style, style) (quick_ftxui_ast::colours, color) + (quick_ftxui_ast::text_style, style) (std::string, content) ) @@ -939,7 +939,7 @@ struct parser str_var_decl %= qi::lit("str") >> identifier >> -('=' > quoted_string); - text_comp %= -(text_style_kw) >> -(color_kw) >> qi::lit("Text") >> '(' >> + text_comp %= -(color_kw) >> -(text_style_kw) >> qi::lit("Text") >> '(' >> quoted_string >> ')'; sep_comp %= -(sep_kw) >> qi::lit("separator"); diff --git a/tests/test1.cpp b/tests/test1.cpp index 54c71d7..2b8bd18 100644 --- a/tests/test1.cpp +++ b/tests/test1.cpp @@ -173,3 +173,133 @@ TEST_CASE("Parse Recursive") { }\ }")); } + +TEST_CASE("Parse DOM elements") { + REQUIRE(parse_helper("Vertical {\ + Text(\"Hello World\") \ + separator \ + Paragraph(\"Hello to his paragraph\")\ + HeavyBorder Horizontal { \ + RedLight dim Text(\"amool\") \ + }\ + }")); + + // Parse text and its styles + REQUIRE(parse_helper("Vertical {\ + Blue Text(\"Hello World\") \ + Red bold Text(\"amool\") \ + dim Text(\"bmpp\") \ + underlined Text(\"cmqq\") \ + Magenta underlinedDouble Text(\"dmrr\") \ + blink Text(\"emss\") \ + Red inverted Text(\"This has an inverted look\") \ + strikethrough Text(\"This is strikethrough\") \ + }")); + + REQUIRE(!parse_helper("Vertical {\ + blue Text(\"Hello World\") \ + Bold Red Text(\"amool\") \ + DIM Text(\"bmpp\") \ + underlined Text(cmqq) \ + underlinedDouble Magenta Text(\"dmrr\") \ + blink Text(123) \ + inverted Red Text(\"This has an inverted look\") \ + strikethrough Text(\"This is strikethrough\") \ + }")); + + // Paragraphs, separators and borders + REQUIRE(parse_helper("HeavyBorder Vertical {\ + Paragraph(\"I guess I should have talked before going into the unknown\")\ + separator \ + Paragraph(\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \ + Ut enim ad minim veniam, quis nostrud exercitation ullamco \ + laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure \ + dolor in reprehenderit in voluptate velit esse cillum dolore \ + eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \ + non proident, sunt in culpa qui officia deserunt mollit anim \ + id est laborum.\") \ + Dashed separator \ + Border Horizontal { \ + Paragraph(\"This is my peace offering.\") \ + }\ + }")); + + REQUIRE(!parse_helper("Heavy Border Vertical {\ + Paragraph(\"I guess I should have talked before going into the unknown\")\ + separator \ + Paragraph(\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \ + Ut enim ad minim veniam, quis nostrud exercitation ullamco \ + laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure \ + dolor in reprehenderit in voluptate velit esse cillum dolore \ + eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \ + non proident, sunt in culpa qui officia deserunt mollit anim \ + id est laborum.\") \ + dashed separator \ + Paragraph(This is my peace offering) \ + }")); +} + +TEST_CASE("Parse Components and DOM together") { + REQUIRE(parse_helper("HeavyBorder Vertical {\ + int x \ + Blue Slider{ \ + \"amool\", \ + x, \ + 0, \ + 30, \ + 2 \ + } \ + Double separator \ + LightBorder Horizontal { \ + Yellow dim Text(\"bmpp\") \ + } \ + str y \ + Button { \ + \"amool\", \ + System(\"ls -l\"), \ + y \ + } \ + }")); + + REQUIRE(parse_helper("DashedBorder Vertical{\ + int x \ + Blue Dropdown{ \ + [\"amool\", \"bmpp\", \"cmqq\",], \ + x \ + } \ + Light separator \ + RoundedBorder Horizontal { \ + Yellow strikethrough Text(\"dmrr\") \ + } \ + str y \ + Button { \ + \"amool\", \ + System(\"ls -l\"), \ + Animated, \ + y \ + } \ + }")); + + REQUIRE(!parse_helper("Heavy Border Vertical {\ + int x \ + Blue Slider{ \ + \"amool\", \ + x, \ + 0, \ + 30, \ + 2 \ + } \ + Double Separator \ + Horizontal { \ + LightBorder Yellow dim Text(\"bmpp\") \ + } \ + str y \ + Button { \ + \"amool\", \ + System(\"ls -l\"), \ + y \ + } \ + }")); +}