Skip to content

Commit f8507a1

Browse files
authored
why are our examples so complicated? (#856)
1 parent ff92faa commit f8507a1

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ components (path, host, and so forth).
131131
- Parse and validate a URL from an ASCII or a valid UTF-8 string.
132132
133133
```cpp
134-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
134+
auto url = ada::parse("https://www.google.com");
135135
if (url) { /* URL is valid */ }
136136
```
137137

@@ -140,14 +140,14 @@ accessing it when you are not sure that it will succeed. The following
140140
code is unsafe:
141141

142142
```cpp
143-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("some bad url");
143+
auto url = ada::parse("some bad url");
144144
url->get_href();
145145
```
146146

147147
You should do...
148148

149149
```cpp
150-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("some bad url");
150+
auto url = ada::parse("some bad url");
151151
if(url) {
152152
// next line is now safe:
153153
url->get_href();
@@ -165,7 +165,7 @@ UTF-8 strings.
165165
- Get/Update credentials
166166

167167
```cpp
168-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
168+
auto url = ada::parse("https://www.google.com");
169169
url->set_username("username");
170170
url->set_password("password");
171171
// ada->get_href() will return "https://username:[email protected]/"
@@ -174,7 +174,7 @@ url->set_password("password");
174174
- Get/Update Protocol
175175
176176
```cpp
177-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
177+
auto url = ada::parse("https://www.google.com");
178178
url->set_protocol("wss");
179179
// url->get_protocol() will return "wss:"
180180
// url->get_href() will return "wss://www.google.com/"
@@ -183,7 +183,7 @@ url->set_protocol("wss");
183183
- Get/Update host
184184

185185
```cpp
186-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
186+
auto url = ada::parse("https://www.google.com");
187187
url->set_host("github.com");
188188
// url->get_host() will return "github.com"
189189
// you can use `url.set_hostname` depending on your usage.
@@ -192,31 +192,31 @@ url->set_host("github.com");
192192
- Get/Update port
193193
194194
```cpp
195-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
195+
auto url = ada::parse("https://www.google.com");
196196
url->set_port("8080");
197197
// url->get_port() will return "8080"
198198
```
199199

200200
- Get/Update pathname
201201

202202
```cpp
203-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
203+
auto url = ada::parse("https://www.google.com");
204204
url->set_pathname("/my-super-long-path")
205205
// url->get_pathname() will return "/my-super-long-path"
206206
```
207207
208208
- Get/Update search/query
209209
210210
```cpp
211-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
211+
auto url = ada::parse("https://www.google.com");
212212
url->set_search("target=self");
213213
// url->get_search() will return "?target=self"
214214
```
215215

216216
- Get/Update hash/fragment
217217

218218
```cpp
219-
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
219+
auto url = ada::parse("https://www.google.com");
220220
url->set_hash("is-this-the-real-life");
221221
// url->get_hash() will return "#is-this-the-real-life"
222222
```

tests/basic_tests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ TYPED_TEST(basic_tests, readme) {
9494
SUCCEED();
9595
}
9696

97+
TYPED_TEST(basic_tests, readmefree) {
98+
auto url = ada::parse("https://www.google.com");
99+
ASSERT_TRUE(bool(url));
100+
SUCCEED();
101+
}
102+
97103
TYPED_TEST(basic_tests, readme2) {
98104
auto url = ada::parse<TypeParam>("https://www.google.com");
99105
url->set_username("username");
@@ -102,6 +108,14 @@ TYPED_TEST(basic_tests, readme2) {
102108
SUCCEED();
103109
}
104110

111+
TYPED_TEST(basic_tests, readme2free) {
112+
auto url = ada::parse("https://www.google.com");
113+
url->set_username("username");
114+
url->set_password("password");
115+
ASSERT_EQ(url->get_href(), "https://username:[email protected]/");
116+
SUCCEED();
117+
}
118+
105119
TYPED_TEST(basic_tests, readme3) {
106120
auto url = ada::parse<TypeParam>("https://www.google.com");
107121
ASSERT_EQ(url->set_protocol("wss"), true);
@@ -110,6 +124,14 @@ TYPED_TEST(basic_tests, readme3) {
110124
SUCCEED();
111125
}
112126

127+
TYPED_TEST(basic_tests, readme3free) {
128+
auto url = ada::parse("https://www.google.com");
129+
ASSERT_EQ(url->set_protocol("wss"), true);
130+
ASSERT_EQ(url->get_protocol(), "wss:");
131+
ASSERT_EQ(url->get_href(), "wss://www.google.com/");
132+
SUCCEED();
133+
}
134+
113135
TYPED_TEST(basic_tests, set_protocol_should_return_false_sometimes) {
114136
auto url = ada::parse<TypeParam>("file:");
115137
ASSERT_EQ(url->set_protocol("https"), false);

0 commit comments

Comments
 (0)