Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] [Feature] Added unit tests for DOM elements, and modified Test's grammar #20

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/text.qf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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",
System("/usr/bin/google-chrome-stable"),
Animated,
a
}
strikethrough Green Text("This text is Green")
Green strikethrough Text("This text is Green")
Horizontal {
hyperlink Blue Text("Google", "https://www.google.com/")
Blue hyperlink Text("Google", "https://www.google.com/")
}
Button {
"Exit",
Expand Down
6 changes: 3 additions & 3 deletions examples/text_styles.qf
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,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 = "";
std::string link = "";
};
Expand Down Expand Up @@ -295,8 +295,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)
(std::string, link)
)
Expand Down Expand Up @@ -954,7 +954,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 >> -(',' >> quoted_string) >> ')';

sep_comp %= -(sep_kw) >> qi::lit("separator");
Expand Down
130 changes: 130 additions & 0 deletions tests/test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
} \
}"));
}
Loading