diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-21 01:17:49 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-21 01:17:49 +0100 |
commit | 6decad0b8e7e369bd8215f31a45dd3eae982d2a9 (patch) | |
tree | 96d22db47629956c554d11a9e56bc68a2fc9b40b /test/core | |
parent | 311a770805dff2cdffc1ecbfbbf0c5aae44c8878 (diff) |
Some further refactoring -- renamed Scope to ParserScope, got rid of parser namespace, added new functionality to RegistryClass, wrote documentation, added function for extracting file extensions to Utils
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/RegistryTest.cpp | 67 | ||||
-rw-r--r-- | test/core/common/UtilsTest.cpp | 19 | ||||
-rw-r--r-- | test/core/parser/ParserStackTest.cpp | 3 | ||||
-rw-r--r-- | test/core/parser/StandaloneParserContext.hpp | 7 |
4 files changed, 89 insertions, 7 deletions
diff --git a/test/core/RegistryTest.cpp b/test/core/RegistryTest.cpp index 45e09d3..21195f2 100644 --- a/test/core/RegistryTest.cpp +++ b/test/core/RegistryTest.cpp @@ -20,18 +20,83 @@ #include <sstream> +#include <core/common/Exceptions.hpp> +#include <core/parser/Parser.hpp> +#include <core/parser/ParserContext.hpp> #include <core/resource/ResourceLocator.hpp> #include <core/Registry.hpp> namespace ousia { +namespace { +class TestParser : public Parser { +protected: + Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override + { + return new Node{ctx.manager}; + } +}; +} + +static const Rtti rtti1{"rtti1"}; +static const Rtti rtti2{"rtti2"}; + +TEST(Registry, parsers) +{ + Registry registry; + + TestParser parser1; + TestParser parser2; + + registry.registerParser({"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"}, + {&rtti1, &rtti2}, &parser1); + registry.registerParser({"text/vnd.ousia.opd"}, {&rtti2}, &parser2); + + ASSERT_THROW( + registry.registerParser({"text/vnd.ousia.opd"}, {&rtti2}, &parser1), + OusiaException); + + { + auto res = registry.getParserForMimetype("text/vnd.ousia.oxm"); + ASSERT_EQ(&parser1, res.first); + ASSERT_EQ(RttiSet({&rtti1, &rtti2}), res.second); + } + + { + auto res = registry.getParserForMimetype("text/vnd.ousia.opd"); + ASSERT_EQ(&parser2, res.first); + ASSERT_EQ(RttiSet({&rtti2}), res.second); + } + + { + auto res = registry.getParserForMimetype("application/javascript"); + ASSERT_EQ(nullptr, res.first); + ASSERT_EQ(RttiSet({}), res.second); + } +} + +TEST(Registry, extensions) +{ + Registry registry; + + registry.registerExtension("oxm", "text/vnd.ousia.oxm"); + registry.registerExtension("oxd", "text/vnd.ousia.oxd"); + ASSERT_EQ("text/vnd.ousia.oxm", registry.getMimetypeForExtension("oxm")); + ASSERT_EQ("text/vnd.ousia.oxm", registry.getMimetypeForExtension("OXM")); + ASSERT_EQ("text/vnd.ousia.oxd", registry.getMimetypeForExtension("OxD")); + ASSERT_EQ("", registry.getMimetypeForExtension("pdf")); + + ASSERT_THROW(registry.registerExtension("oxm", "text/vnd.ousia.oxm"), + OusiaException); +} + TEST(Registry, locateResource) { StaticResourceLocator locator; locator.store("path", "test"); Registry registry; - registry.registerResourceLocator(locator); + registry.registerResourceLocator(&locator); Resource res; ASSERT_TRUE( diff --git a/test/core/common/UtilsTest.cpp b/test/core/common/UtilsTest.cpp index 53beb79..c8f6922 100644 --- a/test/core/common/UtilsTest.cpp +++ b/test/core/common/UtilsTest.cpp @@ -54,5 +54,24 @@ TEST(Utils, split) ASSERT_EQ(std::vector<std::string>({"", "a", "be", "c", ""}), Utils::split(".a.be.c.", '.')); } + +TEST(Utils, toLower) +{ + ASSERT_EQ("", Utils::toLower("")); + ASSERT_EQ("foo00", Utils::toLower("foo00")); + ASSERT_EQ("foo00", Utils::toLower("fOO00")); +} + +TEST(Utils, extractFileExtension) +{ + ASSERT_EQ("", Utils::extractFileExtension("")); + ASSERT_EQ("", Utils::extractFileExtension("test")); + ASSERT_EQ("ext", Utils::extractFileExtension("test.ext")); + ASSERT_EQ("", Utils::extractFileExtension("foo.bar/test")); + ASSERT_EQ("", Utils::extractFileExtension("foo.bar\\test")); + ASSERT_EQ("ext", Utils::extractFileExtension("foo.bar/test.ext")); + ASSERT_EQ("ext", Utils::extractFileExtension("foo.bar/test.EXT")); +} + } diff --git a/test/core/parser/ParserStackTest.cpp b/test/core/parser/ParserStackTest.cpp index 69978b0..81160da 100644 --- a/test/core/parser/ParserStackTest.cpp +++ b/test/core/parser/ParserStackTest.cpp @@ -24,7 +24,6 @@ #include <core/parser/StandaloneParserContext.hpp> namespace ousia { -namespace parser { static const State STATE_DOCUMENT = 0; static const State STATE_BODY = 1; @@ -168,7 +167,5 @@ TEST(ParserStack, validation) ASSERT_FALSE(logger.hasError()); s.end(); } - -} } diff --git a/test/core/parser/StandaloneParserContext.hpp b/test/core/parser/StandaloneParserContext.hpp index 347d34f..51cd1e6 100644 --- a/test/core/parser/StandaloneParserContext.hpp +++ b/test/core/parser/StandaloneParserContext.hpp @@ -23,16 +23,18 @@ #include <core/model/Project.hpp> #include <core/parser/Parser.hpp> +#include <core/parser/ParserScope.hpp> +#include <core/parser/ParserContext.hpp> +#include <core/Registry.hpp> namespace ousia { -namespace parser { struct StandaloneParserContext { public: Manager manager; Logger logger; - Scope scope; Registry registry; + ParserScope scope; Rooted<model::Project> project; ParserContext context; @@ -47,7 +49,6 @@ public: context(scope, registry, externalLogger, manager, project){}; }; } -} #endif /* _OUSIA_STANDALONE_PARSER_CONTEXT_ */ |