From b57bf0b772c5cfef789363b9951f737d9e92a28a Mon Sep 17 00:00:00 2001
From: Richard Walters <rwalters@digitalstirling.com>
Date: Sat, 30 Jun 2018 23:35:15 -0700
Subject: Add code to check that scheme, if present, is legal

---
 test/src/UriTests.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

(limited to 'test')

diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 6ee57c4..b4be2d5 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -235,3 +235,42 @@ TEST(UriTests, ParseFromStringTwiceFirstUserInfoThenWithout) {
     ASSERT_TRUE(uri.ParseFromString("/foo/bar"));
     ASSERT_TRUE(uri.GetUserInfo().empty());
 }
+
+TEST(UriTests, ParseFromStringSchemeIllegalCharacters) {
+    const std::vector< std::string > testVectors{
+        {"://www.example.com/"},
+        {"0://www.example.com/"},
+        {"+://www.example.com/"},
+        {"@://www.example.com/"},
+        {".://www.example.com/"},
+        {"h@://www.example.com/"},
+    };
+    size_t index = 0;
+    for (const auto& testVector : testVectors) {
+        Uri::Uri uri;
+        ASSERT_FALSE(uri.ParseFromString(testVector)) << index;
+        ++index;
+    }
+}
+
+TEST(UriTests, ParseFromStringSchemeBarelyLegal) {
+    struct TestVector {
+        std::string uriString;
+        std::string scheme;
+    };
+    const std::vector< TestVector > testVectors{
+        {"h://www.example.com/", "h"},
+        {"x+://www.example.com/", "x+"},
+        {"y-://www.example.com/", "y-"},
+        {"z.://www.example.com/", "z."},
+        {"aa://www.example.com/", "aa"},
+        {"a0://www.example.com/", "a0"},
+    };
+    size_t index = 0;
+    for (const auto& testVector : testVectors) {
+        Uri::Uri uri;
+        ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index;
+        ASSERT_EQ(testVector.scheme, uri.GetScheme());
+        ++index;
+    }
+}
-- 
cgit v1.2.3