diff --git a/Makefile b/Makefile index bd0a5db..874a241 100644 --- a/Makefile +++ b/Makefile @@ -162,8 +162,7 @@ tests: $(TESTS) json_wrapper $(BASE_LIB) $(WIDGET_LIB) run-tests: tests - ./tests/runner -s - ./tests/runner -r compact + ./tests/runner clean: rm -f *.res diff --git a/src/settings/ThemeConfig.cpp b/src/settings/ThemeConfig.cpp index 40c9562..9283f9b 100644 --- a/src/settings/ThemeConfig.cpp +++ b/src/settings/ThemeConfig.cpp @@ -23,12 +23,22 @@ ThemeConfig::~ThemeConfig() {} * Set the current theme * * @param string theme_name - * @return void + * @return bool */ -void ThemeConfig::SetTheme(string theme_name) +bool ThemeConfig::SetTheme(string theme_name) { JsonValue theme_list = this->GetRoot(); - this->current_theme = theme_list.get(theme_name, JsonValue()); + JsonValue selected_theme = theme_list.get(theme_name, JsonValue()); + + if (selected_theme.isNull()) return FALSE; + + if (selected_theme.isObject()) + { + this->current_theme = selected_theme; + return TRUE; + } + + return FALSE; } /** @@ -77,6 +87,6 @@ wxColor ThemeConfig::GetThemeColor(string type, string key) } else { - return wxColor("black"); + return wxColor("BLACK"); } } \ No newline at end of file diff --git a/src/settings/ThemeConfig.h b/src/settings/ThemeConfig.h index 8064e8a..5aa5410 100644 --- a/src/settings/ThemeConfig.h +++ b/src/settings/ThemeConfig.h @@ -12,7 +12,7 @@ class ThemeConfig : TyroConfig { public: ThemeConfig(); ~ThemeConfig(); - void SetTheme(string theme_name); + bool SetTheme(string theme_name); JsonValue GetTheme(); JsonValue GetThemeValue(string type, string key); wxColor GetThemeColor(string type, string key); diff --git a/tests/LangConfigTest.cpp b/tests/LangConfigTest.cpp index fea3548..600af28 100644 --- a/tests/LangConfigTest.cpp +++ b/tests/LangConfigTest.cpp @@ -41,16 +41,25 @@ TEST_CASE("Language Config Library") SECTION("GetCurrentLangName()") { - + config->SetLang("cpp"); + REQUIRE("C / C++" == config->GetCurrentLangName()); } SECTION("GetLexerMap()") { + JsonValue lexer_map = config->GetLexerMap("none"); + REQUIRE(lexer_map.isNull()); + lexer_map = config->GetLexerMap("cpp"); + REQUIRE(lexer_map.isArray()); } SECTION("GetKeywordList()") { + JsonValue keyword_list = config->GetKeywordList("none"); + REQUIRE(keyword_list.isNull()); + keyword_list = config->GetKeywordList("cpp"); + REQUIRE(keyword_list.isArray()); } } diff --git a/tests/ThemeConfigTest.cpp b/tests/ThemeConfigTest.cpp new file mode 100644 index 0000000..634ce06 --- /dev/null +++ b/tests/ThemeConfigTest.cpp @@ -0,0 +1,28 @@ +#include "catch.hpp" +#include "../src/settings/ThemeConfig.h" + +TEST_CASE("Theme Config Library") +{ + ThemeConfig *config = new ThemeConfig(); + + SECTION("GetTheme()") + { + JsonValue theme = config->GetTheme(); + REQUIRE(theme.isObject()); + } + + SECTION("SetTheme()") + { + REQUIRE_FALSE(config->SetTheme("foobar")); + REQUIRE(config->SetTheme("Solarized")); + } + + SECTION("GetThemeColor()") + { + REQUIRE(config->SetTheme("Solarized")); + + // Bad color + wxColor theme_color = config->GetThemeColor("foo", "bar"); + REQUIRE(wxColor("BLACK") == theme_color); + } +} diff --git a/tests/catch.hpp b/tests/catch.hpp index 2964790..0b09e67 100644 --- a/tests/catch.hpp +++ b/tests/catch.hpp @@ -62,6 +62,7 @@ #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) +#include #include #include #include