|
|
@@ -31,12 +31,142 @@
|
|
|
#include <RmlUi/Core/PropertyDefinition.h>
|
|
|
#include <RmlUi/Core/PropertyDictionary.h>
|
|
|
#include <RmlUi/Core/PropertySpecification.h>
|
|
|
+#include <RmlUi/Core/StyleSheetSpecification.h>
|
|
|
#include <doctest.h>
|
|
|
#include <limits.h>
|
|
|
|
|
|
+namespace Rml {
|
|
|
+class TestPropertySpecification {
|
|
|
+public:
|
|
|
+ using SplitOption = PropertySpecification::SplitOption;
|
|
|
+ TestPropertySpecification(const PropertySpecification& specification) : specification(specification) {}
|
|
|
+
|
|
|
+ bool ParsePropertyValues(StringList& values_list, const String& values, SplitOption split_option) const
|
|
|
+ {
|
|
|
+ return specification.ParsePropertyValues(values_list, values, split_option);
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ const PropertySpecification& specification;
|
|
|
+};
|
|
|
+} // namespace Rml
|
|
|
+
|
|
|
using namespace Rml;
|
|
|
|
|
|
-TEST_CASE("PropertySpecification")
|
|
|
+static String Stringify(const StringList& list)
|
|
|
+{
|
|
|
+ String result = "[";
|
|
|
+ for (int i = 0; i < (int)list.size(); i++)
|
|
|
+ {
|
|
|
+ if (i != 0)
|
|
|
+ result += "; ";
|
|
|
+ result += list[i];
|
|
|
+ }
|
|
|
+ result += ']';
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+TEST_CASE("PropertySpecification.ParsePropertyValues")
|
|
|
+{
|
|
|
+ TestsSystemInterface system_interface;
|
|
|
+ TestsRenderInterface render_interface;
|
|
|
+ SetRenderInterface(&render_interface);
|
|
|
+ SetSystemInterface(&system_interface);
|
|
|
+ Rml::Initialise();
|
|
|
+
|
|
|
+ using SplitOption = TestPropertySpecification::SplitOption;
|
|
|
+ const TestPropertySpecification& specification = TestPropertySpecification(StyleSheetSpecification::GetPropertySpecification());
|
|
|
+
|
|
|
+ struct Expected {
|
|
|
+ Expected(const char* value) : values{String(value)} {}
|
|
|
+ Expected(std::initializer_list<String> list) : values(list) {}
|
|
|
+ StringList values;
|
|
|
+ };
|
|
|
+
|
|
|
+ auto Parse = [&](const String& test_value, const Expected& expected, SplitOption split = SplitOption::Whitespace) {
|
|
|
+ StringList parsed_values;
|
|
|
+ bool success = specification.ParsePropertyValues(parsed_values, test_value, split);
|
|
|
+ const String split_str[] = {"none", "whitespace", "comma"};
|
|
|
+
|
|
|
+ INFO("\n\tSplit: ", split_str[(int)split], "\n\tInput: ", test_value, "\n\tExpected: ", Stringify(expected.values),
|
|
|
+ "\n\tResult: ", Stringify(parsed_values));
|
|
|
+ CHECK(success);
|
|
|
+ CHECK(parsed_values == expected.values);
|
|
|
+ };
|
|
|
+
|
|
|
+ Parse("red", "red");
|
|
|
+ Parse(" red ", "red");
|
|
|
+ Parse("inline-block", "inline-block");
|
|
|
+
|
|
|
+ Parse("none red", {"none", "red"});
|
|
|
+ Parse("none red", {"none", "red"});
|
|
|
+ Parse("none\t \r \nred", {"none", "red"});
|
|
|
+
|
|
|
+ Parse("none red", "none red", SplitOption::None);
|
|
|
+ Parse(" none red ", "none red", SplitOption::None);
|
|
|
+ Parse("none red", "none red", SplitOption::None);
|
|
|
+ Parse("none\t \r \nred", "none\t \r \nred", SplitOption::None);
|
|
|
+ Parse("none,red", "none,red", SplitOption::None);
|
|
|
+ Parse(" \"none,red\" ", "none,red", SplitOption::None);
|
|
|
+
|
|
|
+ Parse("none,red", {"none,red"});
|
|
|
+ Parse("none, red", {"none,", "red"});
|
|
|
+ Parse("none , red", {"none", ",", "red"});
|
|
|
+ Parse("none , red", {"none", ",", "red"});
|
|
|
+ Parse("none,,red", "none,,red");
|
|
|
+ Parse("none,,,red", "none,,,red");
|
|
|
+
|
|
|
+ Parse("none,red", {"none", "red"}, SplitOption::Comma);
|
|
|
+ Parse("none, red", {"none", "red"}, SplitOption::Comma);
|
|
|
+ Parse("none , red", {"none", "red"}, SplitOption::Comma);
|
|
|
+ Parse("none , red", {"none", "red"}, SplitOption::Comma);
|
|
|
+ Parse("none,,red", {"none", "red"}, SplitOption::Comma);
|
|
|
+ Parse("none,,,red", {"none", "red"}, SplitOption::Comma);
|
|
|
+ Parse("none, , ,red", {"none", "red"}, SplitOption::Comma);
|
|
|
+
|
|
|
+ Parse("\"string with spaces\"", "string with spaces");
|
|
|
+ Parse("\"string with spaces\" two", {"string with spaces", "two"});
|
|
|
+ Parse("\"string with spaces\"two", {"string with spaces", "two"});
|
|
|
+ Parse("\"string with spaces\"two", "string with spaces two", SplitOption::None);
|
|
|
+
|
|
|
+ Parse("\"string (with) ((parenthesis\" two", {"string (with) ((parenthesis", "two"});
|
|
|
+ Parse("\"none,,red\" two", {"none,,red", "two"});
|
|
|
+
|
|
|
+ Parse("aa(bb( cc ) dd) ee", {"aa(bb( cc ) dd)", "ee"});
|
|
|
+ Parse("aa(\"bb cc ) dd\") ee", {"aa(\"bb cc ) dd\")", "ee"});
|
|
|
+ Parse("aa(\"bb cc \\) dd\") ee", {"aa(\"bb cc \\) dd\")", "ee"});
|
|
|
+ Parse("aa(\"bb cc \\) dd\") ee", "aa(\"bb cc \\) dd\") ee", SplitOption::Comma);
|
|
|
+
|
|
|
+ Parse("none(\"long string\"), aa, \"bb() cc\"", {"none(\"long string\"),", "aa,", "bb() cc"});
|
|
|
+ Parse("none(\"long string\"), aa, \"bb() cc\"", {"none(\"long string\")", "aa", "\"bb() cc\""}, SplitOption::Comma);
|
|
|
+ Parse("none(\"long string\"), aa, bb() cc", {"none(\"long string\")", "aa", "bb() cc"}, SplitOption::Comma);
|
|
|
+
|
|
|
+ Parse("tiled-horizontal( title-bar-l, title-bar-c, title-bar-r )", "tiled-horizontal( title-bar-l, title-bar-c, title-bar-r )");
|
|
|
+ Parse("tiled-horizontal( title-bar-l, title-bar-c,\n\ttitle-bar-r )", "tiled-horizontal( title-bar-l, title-bar-c,\n\ttitle-bar-r )");
|
|
|
+ Parse("tiled-horizontal( title-bar-l, title-bar-c )", "tiled-horizontal( title-bar-l, title-bar-c )", SplitOption::Comma);
|
|
|
+
|
|
|
+ Parse("linear-gradient(110deg, #fff, #000 10%) border-box, image(invader.png)",
|
|
|
+ {"linear-gradient(110deg, #fff, #000 10%)", "border-box,", "image(invader.png)"});
|
|
|
+ Parse("linear-gradient(110deg, #fff, #000 10%) border-box, image(invader.png)",
|
|
|
+ {"linear-gradient(110deg, #fff, #000 10%) border-box", "image(invader.png)"}, SplitOption::Comma);
|
|
|
+
|
|
|
+ Parse(R"(image( a\) b ))", {R"(image( a\))", "b", ")"});
|
|
|
+ Parse(R"(image( a\) b ))", R"(image( a\) b ))", SplitOption::Comma);
|
|
|
+
|
|
|
+ Parse(R"(image( ))", R"(image( ))");
|
|
|
+ Parse(R"(image( a\\b ))", R"(image( a\\b ))");
|
|
|
+ Parse(R"(image( a\\\b ))", R"(image( a\\\b ))");
|
|
|
+ Parse(R"(image( a\\\\b ))", R"(image( a\\\\b ))");
|
|
|
+ Parse(R"(image("a\)b"))", R"(image("a\)b"))");
|
|
|
+ Parse(R"(image("a\\)b"))", R"(image("a\)b"))");
|
|
|
+ Parse(R"(image("a\\b"))", R"(image("a\b"))");
|
|
|
+ Parse(R"(image("a\\\b"))", R"(image("a\\b"))");
|
|
|
+ Parse(R"(image("a\\\\b"))", R"(image("a\\b"))");
|
|
|
+
|
|
|
+ Rml::Shutdown();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_CASE("PropertySpecification.string")
|
|
|
{
|
|
|
TestsSystemInterface system_interface;
|
|
|
TestsRenderInterface render_interface;
|
|
|
@@ -89,13 +219,6 @@ TEST_CASE("PropertySpecification")
|
|
|
Parse(R"(image(a, "b"))", R"(image(a, "b"))");
|
|
|
Parse(R"V("image(a, \"b\")")V", R"V(image(a, "b"))V");
|
|
|
|
|
|
- Parse(R"(image( ))", R"(image( ))");
|
|
|
- Parse(R"(image( a\)b ))", R"(image( a)b ))");
|
|
|
- Parse(R"(image("a\)b"))", R"(image("a)b"))");
|
|
|
- Parse(R"(image( a\\b ))", R"(image( a\b ))");
|
|
|
- Parse(R"(image( a\\\b ))", R"(image( a\\b ))");
|
|
|
- Parse(R"(image( a\\\\b ))", R"(image( a\\b ))");
|
|
|
-
|
|
|
Rml::Shutdown();
|
|
|
}
|
|
|
|
|
|
@@ -107,6 +230,7 @@ TEST_CASE("PropertyParser.Keyword")
|
|
|
SetSystemInterface(&system_interface);
|
|
|
Rml::Initialise();
|
|
|
|
|
|
+ // Test keyword parser. Ensure that the keyword values are correct.
|
|
|
PropertySpecification specification(20, 0);
|
|
|
|
|
|
auto Parse = [&](const PropertyId id, const String& test_value, int expected_value) {
|