diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/src/UriTests.cpp | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp index 3cb5336..73848a9 100644 --- a/test/src/UriTests.cpp +++ b/test/src/UriTests.cpp @@ -7,9 +7,85 @@ */ #include <gtest/gtest.h> +#include <stddef.h> #include <Uri/Uri.hpp> -TEST(UriTests, Placeholder) { +TEST(UriTests, ParseFromStringUrl) { Uri::Uri uri; - ASSERT_TRUE(true); + ASSERT_TRUE(uri.ParseFromString("http://www.example.com/foo/bar")); + ASSERT_EQ("http", uri.GetScheme()); + ASSERT_EQ("www.example.com", uri.GetHost()); + ASSERT_EQ( + (std::vector< std::string >{ + "", + "foo", + "bar", + }), + uri.GetPath() + ); +} + +TEST(UriTests, ParseFromStringUrnDefaultPathDelimiter) { + Uri::Uri uri; + ASSERT_TRUE(uri.ParseFromString("urn:book:fantasy:Hobbit")); + ASSERT_EQ("urn", uri.GetScheme()); + ASSERT_EQ("", uri.GetHost()); + ASSERT_EQ( + (std::vector< std::string >{ + "book:fantasy:Hobbit", + }), + uri.GetPath() + ); +} + +TEST(UriTests, ParseFromStringUrnSingleCharacterPathDelimiter) { + Uri::Uri uri; + uri.SetPathDelimiter(":"); + ASSERT_TRUE(uri.ParseFromString("urn:book:fantasy:Hobbit")); + ASSERT_EQ("urn", uri.GetScheme()); + ASSERT_EQ("", uri.GetHost()); + ASSERT_EQ( + (std::vector< std::string >{ + "book", + "fantasy", + "Hobbit", + }), + uri.GetPath() + ); +} + +TEST(UriTests, ParseFromStringUrnMultiCharacterPathDelimiter) { + Uri::Uri uri; + uri.SetPathDelimiter("/-"); + ASSERT_TRUE(uri.ParseFromString("urn:bo-/ok/-fant/asy/-Hob-bit")); + ASSERT_EQ("urn", uri.GetScheme()); + ASSERT_EQ("", uri.GetHost()); + ASSERT_EQ( + (std::vector< std::string >{ + "bo-/ok", + "fant/asy", + "Hob-bit", + }), + uri.GetPath() + ); +} + +TEST(UriTests, ParseFromStringPathCornerCases) { + struct TestVector { + std::string pathIn; + std::vector< std::string > pathOut; + }; + const std::vector< TestVector > testVectors{ + {"", {}}, + {"/", {""}}, + {"/foo", {"", "foo"} }, + {"foo/", {"foo", ""} }, + }; + size_t index = 0; + for (const auto& testVector : testVectors) { + Uri::Uri uri; + ASSERT_TRUE(uri.ParseFromString(testVector.pathIn)) << index; + ASSERT_EQ(testVector.pathOut, uri.GetPath()) << index; + ++index; + } } |