1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "url_builder.h"
#include <library/cpp/testing/unittest/registar.h>
using namespace NYql;
Y_UNIT_TEST_SUITE(TUrlBuilder) {
Y_UNIT_TEST(UriOnly) {
TUrlBuilder builder("https://localhost/abc");
UNIT_ASSERT_VALUES_EQUAL(builder.Build(), "https://localhost/abc");
}
Y_UNIT_TEST(Basic) {
TUrlBuilder builder("https://localhost/abc");
builder.AddUrlParam("param1", "val1");
builder.AddUrlParam("param2", "val2");
UNIT_ASSERT_VALUES_EQUAL(builder.Build(), "https://localhost/abc?param1=val1¶m2=val2");
}
Y_UNIT_TEST(BasicWithEncoding) {
auto url = TUrlBuilder("https://localhost/abc")
.AddUrlParam("param1", "=!@#$%^&*(){}[]\" ")
.AddUrlParam("param2", "val2")
.Build();
UNIT_ASSERT_VALUES_EQUAL(url, "https://localhost/abc?param1=%3D!@%23$%25%5E%26*%28%29%7B%7D%5B%5D%22+¶m2=val2");
}
Y_UNIT_TEST(EmptyPathComponent) {
TUrlBuilder builder("https://localhost/abc");
UNIT_ASSERT_EXCEPTION_CONTAINS(builder.AddPathComponent(""), std::exception, "Empty path component is not allowed");
auto url = builder.Build();
// not changed
UNIT_ASSERT_VALUES_EQUAL(url, "https://localhost/abc");
}
Y_UNIT_TEST(SeveralPathComponents) {
auto url = TUrlBuilder("https://localhost/abc")
.AddPathComponent("oops")
.AddPathComponent("long oops")
.AddUrlParam("param1", "val1")
.AddUrlParam("param1", "long param")
.Build();
UNIT_ASSERT_VALUES_EQUAL(url, "https://localhost/abc/oops/long%20oops?param1=val1¶m1=long+param");
}
Y_UNIT_TEST(SeveralPathComponentsWithSlashInBaseUri) {
// base uri ends with '/'
auto url = TUrlBuilder("https://localhost/abc/")
.AddPathComponent("oops%1234")
.AddPathComponent("long&oops=xxx")
.AddUrlParam("param1", "a&b=cdef")
.Build();
UNIT_ASSERT_VALUES_EQUAL(url, "https://localhost/abc/oops%251234/long&oops=xxx?param1=a%26b%3Dcdef");
}
}
|