This repository was archived by the owner on Aug 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_is_validator_url.cpp
More file actions
126 lines (116 loc) · 5.63 KB
/
Copy pathtest_is_validator_url.cpp
File metadata and controls
126 lines (116 loc) · 5.63 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "wsjcpp_validators.h"
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
int found_errors = 0;
struct local {
local(const std::string &value, bool expected)
: value(value), expected(expected) {
};
std::string value;
bool expected;
};
std::vector<local> tests;
tests.push_back(local("https://google.com/?some=1&som24", true));
tests.push_back(local("https://google.com/?some=1&som24/", true));
tests.push_back(local("http://foo.com/blah_blah", true));
tests.push_back(local("http://foo.com/blah_blah/", true));
tests.push_back(local("http://foo.com/blah_blah_(wikipedia)", true));
tests.push_back(local("http://foo.com/blah_blah_(wikipedia)_(again)", true));
tests.push_back(local("http://www.example.com/wpstyle/?p=364", true));
tests.push_back(local("https://www.example.com/foo/?bar=baz&inga=42&quux", true));
// tests.push_back(local("http://✪df.ws/123", true));
tests.push_back(local("http://userid:password@example.com:8080", true));
tests.push_back(local("http://userid:password@example.com:8080/", true));
tests.push_back(local("http://userid@example.com", true));
tests.push_back(local("http://userid@example.com/", true));
tests.push_back(local("http://userid@example.com:8080", true));
tests.push_back(local("http://userid@example.com:8080/", true));
tests.push_back(local("http://userid:password@example.com", true));
tests.push_back(local("http://userid:password@example.com/", true));
tests.push_back(local("http://142.42.1.1/", true));
tests.push_back(local("http://142.42.1.1:8080/", true));
// tests.push_back(local("http://➡.ws/䨹", true));
// tests.push_back(local("http://⌘.ws", true));
// tests.push_back(local("http://⌘.ws/", true));
tests.push_back(local("http://foo.com/blah_(wikipedia)#cite-1", true));
tests.push_back(local("http://foo.com/blah_(wikipedia)_blah#cite-1", true));
tests.push_back(local("http://foo.com/unicode_(✪)_in_parens", true));
tests.push_back(local("http://foo.com/(something)?after=parens", true));
// tests.push_back(local("http://☺.damowmow.com/", true));
tests.push_back(local("http://code.google.com/events/#&product=browser", true));
tests.push_back(local("http://j.mp", true));
tests.push_back(local("ftp://foo.bar/baz", true));
tests.push_back(local("ws://foo.bar/baz", true));
tests.push_back(local("wss://foo.bar/baz", true));
tests.push_back(local("http://foo.bar/?q=Test%20URL-encoded%20stuff", true));
// tests.push_back(local("http://مثال.إختبار", true));
// tests.push_back(local("http://例子.测试", true));
// tests.push_back(local("http://उदाहरण.परीक्षा", true));
tests.push_back(local("http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", true));
tests.push_back(local("http://1337.net", true));
tests.push_back(local("http://a.b-c.de", true));
tests.push_back(local("http://223.255.255.254", true));
// incorrect
tests.push_back(local("https://foo_bar.example.com/", false));
tests.push_back(local("some", false));
tests.push_back(local("ABCD", false));
tests.push_back(local("http://", false));
tests.push_back(local("http://.", false));
tests.push_back(local("http://..", false));
tests.push_back(local("http://../", false));
tests.push_back(local("http://?", false));
tests.push_back(local("http://??", false));
tests.push_back(local("http://??/", false));
tests.push_back(local("http://#", false));
tests.push_back(local("http://##", false));
tests.push_back(local("http://##/", false));
tests.push_back(local("http://foo.bar?q=Spaces should be encoded", false));
tests.push_back(local("http://142.42.1.1:88888/", false));
tests.push_back(local("//", false));
tests.push_back(local("//a", false));
tests.push_back(local("///a", false));
tests.push_back(local("///", false));
tests.push_back(local("http:///a", false));
tests.push_back(local("foo.com", false));
tests.push_back(local("https://foo.com.", false));
tests.push_back(local("https://foo..com.", false));
tests.push_back(local("https://foo.com..", false));
tests.push_back(local("https://.foo.com", false));
tests.push_back(local("https://..foo.com", false));
tests.push_back(local("rdar://1234", false));
tests.push_back(local("some://1234", false));
tests.push_back(local("h://test", false));
tests.push_back(local("http:// shouldfail.com", false));
tests.push_back(local(":// should fail", false));
tests.push_back(local("http://foo.bar/foo(bar)baz quux", false));
tests.push_back(local("ftps://foo.bar/", false));
tests.push_back(local("http://-error-.invalid/", false));
tests.push_back(local("http://a.b--c.de/", false));
tests.push_back(local("http://-a.b.co", false));
tests.push_back(local("http://a.b-.co", false));
tests.push_back(local("http://1.1.1.1.1", false));
tests.push_back(local("http://123.123.123", false));
tests.push_back(local("http://3628126748", false));
tests.push_back(local("http://.www.foo.bar/", false));
tests.push_back(local("http://www.foo.bar./", false));
tests.push_back(local("http://.www.foo.bar./", false));
wsjcpp::validator_url *pValidator = new wsjcpp::validator_url();
for (int i = 0; i < tests.size(); i++) {
local t = tests[i];
std::string error;
bool got = pValidator->is_valid(t.value, error);
if (got != t.expected) {
found_errors++;
std::cerr << "Expected " << (t.expected ? "true" : "false") << ", but got " << (got ? "true" : "false") << " for "
<< t.value << "error: " << error << std::endl;
}
}
if (found_errors > 0) {
std::cerr << "FAILED" << std::endl;
return 1;
}
std::cout << "OK" << std::endl;
return 0;
}