Ver código fonte

Tolerate directory properties and bool defaults (#581)

Co-authored-by: louzt <louzt@users.noreply.github.com>
David Mireles 4 meses atrás
pai
commit
c0f7b8380b

+ 2 - 1
CMakeLists.txt

@@ -505,7 +505,8 @@ if(BUILD_TESTING)
         src/WallpaperEngine/Testing/Input/TestingMouseInput.h
         src/WallpaperEngine/Testing/Harnesses/RenderHarness.cpp
         src/WallpaperEngine/Testing/Harnesses/RenderHarness.h
-        src/WallpaperEngine/Testing/Cases/MouseCoordinates.cpp)
+        src/WallpaperEngine/Testing/Cases/MouseCoordinates.cpp
+        src/WallpaperEngine/Testing/Cases/PropertyParser.cpp)
 endif()
 
 add_library(

+ 2 - 2
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp

@@ -26,7 +26,7 @@ PropertySharedPtr PropertyParser::parse (const JSON& it, const std::string& name
     if (type == "scenetexture") {
 	return parseSceneTexture (it, name);
     }
-    if (type == "file") {
+    if (type == "file" || type == "directory") {
 	return parseFile (it, name);
     }
     if (type == "textinput") {
@@ -95,7 +95,7 @@ PropertySharedPtr PropertyParser::parseBoolean (const JSON& it, const std::strin
 	    .name = name,
 	    .text = it.optional<std::string> ("text", ""),
 	},
-	it.require ("value", "Property must have a value")
+	it.optional ("value", false)
     );
 }
 

+ 33 - 0
src/WallpaperEngine/Testing/Cases/PropertyParser.cpp

@@ -0,0 +1,33 @@
+#include <catch2/catch_test_macros.hpp>
+
+#include "WallpaperEngine/Data/Parsers/PropertyParser.h"
+#include "WallpaperEngine/Data/Model/Property.h"
+
+using WallpaperEngine::Data::JSON::JSON;
+using WallpaperEngine::Data::Model::DynamicValue;
+using WallpaperEngine::Data::Parsers::PropertyParser;
+
+TEST_CASE ("Bool properties without a value default to false") {
+    const JSON propertyData = {
+	{ "type", "bool" },
+	{ "text", "Enabled" },
+    };
+
+    const auto property = PropertyParser::parse (propertyData, "enabled");
+
+    REQUIRE (property != nullptr);
+    CHECK (property->getType () == DynamicValue::Boolean);
+    CHECK_FALSE (property->getBool ());
+}
+
+TEST_CASE ("Directory properties are parsed as file-like properties") {
+    const JSON propertyData = {
+	{ "type", "directory" },
+	{ "text", "Folder" },
+    };
+
+    const auto property = PropertyParser::parse (propertyData, "folder");
+
+    REQUIRE (property != nullptr);
+    CHECK (property->dump ().find ("folder - file") != std::string::npos);
+}