diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-06-30 15:26:33 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-06-30 15:26:33 -0700 |
commit | a84a28c61ff44f714edf31e77500d796e3bd4ce4 (patch) | |
tree | c09edfc1355cb036e98ce1aaf25c8e65b2d53c44 /test | |
parent | 9ead8935e92119369f7d82c1514d390b18822c90 (diff) |
Kick off Uri component
* Can now parse URIs from strings.
* This supports scheme, host, and path.
* Path separator defaults to "/" but may be customized.
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; + } } |