Debian Codegraph @

LspCpp/third_party/uri/test/uri_parse_path_test.cpp

raw
1 // Copyright 2016 Glyn Matthews.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt of copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <gtest/gtest.h>
7 #include "test_uri.hpp"
8 #include "string_utility.hpp"
9
10 // path = path-abempty ; begins with "/" or is empty
11 // / path-absolute ; begins with "/" but not "//"
12 // / path-noscheme ; begins with a non-colon segment
13 // / path-rootless ; begins with a segment
14 // / path-empty ; zero characters
15 //
16 // path-abempty = *( "/" segment )
17 // path-absolute = "/" [ segment-nz *( "/" segment ) ]
18 // path-noscheme = segment-nz-nc *( "/" segment )
19 // path-rootless = segment-nz *( "/" segment )
20 // path-empty = 0<pchar>
21 //
22 // segment = *pchar
23 // segment-nz = 1*pchar
24 // segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
25 // ; non-zero-length segment without any colon ":"
26 //
27 // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
28
29
30 TEST(uri_parse_path_test, test_empty_path) {
31 test::uri uri("http://123.34.23.56");
32 EXPECT_TRUE(uri.parse_uri());
33 ASSERT_TRUE(uri.has_path());
34 EXPECT_TRUE(uri.path().empty());
35 }
36
37 TEST(uri_parse_path_test, test_empty_path_with_query) {
38 test::uri uri("http://123.34.23.56?query");
39 EXPECT_TRUE(uri.parse_uri());
40 ASSERT_TRUE(uri.has_path());
41 EXPECT_TRUE(uri.path().empty());
42 }
43
44 TEST(uri_parse_path_test, test_empty_path_with_fragment) {
45 test::uri uri("http://123.34.23.56#fragment");
46 EXPECT_TRUE(uri.parse_uri());
47 ASSERT_TRUE(uri.has_path());
48 EXPECT_TRUE(uri.path().empty());
49 }
50
51 TEST(uri_parse_path_test, test_single_slash) {
52 test::uri uri("http://123.34.23.56/");
53 EXPECT_TRUE(uri.parse_uri());
54 ASSERT_TRUE(uri.has_path());
55 EXPECT_EQ("/", uri.path());
56 }
57
58 TEST(uri_parse_path_test, test_single_slash_with_query) {
59 test::uri uri("http://123.34.23.56/?query");
60 EXPECT_TRUE(uri.parse_uri());
61 ASSERT_TRUE(uri.has_path());
62 EXPECT_EQ("/", uri.path());
63 }
64
65 TEST(uri_parse_path_test, test_single_slash_with_fragment) {
66 test::uri uri("http://123.34.23.56/#fragment");
67 EXPECT_TRUE(uri.parse_uri());
68 ASSERT_TRUE(uri.has_path());
69 EXPECT_EQ("/", uri.path());
70 }
71
72 TEST(uri_parse_path_test, test_double_slash_empty_path_empty_everything) {
73 test::uri uri("file://");
74 EXPECT_FALSE(uri.parse_uri());
75 }
76
77 TEST(uri_parse_path_test, test_triple_slash_empty_everything) {
78 test::uri uri("file:///");
79 EXPECT_TRUE(uri.parse_uri());
80 ASSERT_TRUE(uri.has_path());
81 EXPECT_EQ("/", uri.path());
82 }
83
84 TEST(uri_parse_path_test, test_triple_slash_with_path_name) {
85 test::uri uri("file:///path");
86 EXPECT_TRUE(uri.parse_uri());
87 ASSERT_TRUE(uri.has_path());
88 EXPECT_EQ("/path", uri.path());
89 }
90
91 TEST(uri_parse_path_test, test_rootless_1) {
92 test::uri uri("mailto:[email protected]");
93 EXPECT_TRUE(uri.parse_uri());
94 ASSERT_TRUE(uri.has_path());
95 EXPECT_EQ("[email protected]", uri.path());
96 }
97
98 TEST(uri_parse_path_test, test_invalid_characters_in_path) {
99 test::uri uri("mailto:jo%[email protected]");
100 EXPECT_FALSE(uri.parse_uri());
101 EXPECT_EQ("mailto:jo", uri.parsed_till());
102 }
103
104 TEST(uri_parse_path_test, test_valid_percent_encoded_characters_in_path) {
105 test::uri uri("mailto:john.doe@example%F0.com");
106 EXPECT_TRUE(uri.parse_uri());
107 ASSERT_TRUE(uri.has_path());
108 EXPECT_EQ("john.doe@example%F0.com", uri.path());
109 }
110
111 TEST(uri_parse_path_test, test_invalid_percent_encoded_characters_in_path_1) {
112 test::uri uri("mailto:john.doe@example%G0.com");
113 EXPECT_FALSE(uri.parse_uri());
114 EXPECT_EQ("mailto:john.doe@example", uri.parsed_till());
115 }
116
117 TEST(uri_parse_path_test, test_invalid_percent_encoded_characters_in_path_2) {
118 test::uri uri("mailto:john.doe@example%0G.com");
119 EXPECT_FALSE(uri.parse_uri());
120 EXPECT_EQ("mailto:john.doe@example", uri.parsed_till());
121 }