empty statement
[ghsmtp.git] / Domain-test.cpp
blobeedbd6e1ca68b52126fa96c6c3dbad92bc01847f
1 #include "Domain.hpp"
3 #include <iostream>
5 #include <glog/logging.h>
7 int main(int argc, char const* argv[])
9 std::string const d{"example.com."};
11 CHECK(Domain::match(d, "EXAMPLE.COM"));
12 CHECK(Domain::match(d, "example.com."));
14 CHECK(!Domain::match(d, "example.co"));
15 CHECK(!Domain::match(d, "example.com.."));
16 CHECK(!Domain::match(d, ""));
17 CHECK(!Domain::match(d, "."));
19 std::string const d3{""};
21 CHECK(Domain::match(d3, ""));
22 CHECK(Domain::match(d3, "."));
24 CHECK(!Domain::match(d3, "example.com"));
26 Domain const dom{"example.com"};
27 CHECK_EQ(dom, Domain("EXAMPLE.COM"));
29 Domain const dom2{"黒川.日本"};
30 Domain const dom3{"xn--5rtw95l.xn--wgv71a"};
31 CHECK_EQ(dom2, dom3);
33 Domain const poop1{"💩.la"};
34 Domain const poop2{"xn--ls8h.la"};
35 CHECK_EQ(poop1, poop2);
37 Domain const norm0{"hi⒌com"}; // non-ascii "dot" before "com"
38 Domain const norm1{"hi5.com"};
40 CHECK_EQ(norm0, norm1);
42 CHECK(Domain::validate("hi⒌com"));
43 CHECK(Domain::validate("hi5.com"));
45 // FIXME
46 // CHECK(!Domain::validate("$?%^&*("));
48 try {
49 Domain const junk{"$?%^&*("};
50 // idn2 allows this
51 // LOG(FATAL) << "should have thrown";
53 catch (std::exception const& ex) {
54 std::cout << ex.what() << '\n';
57 try {
58 Domain const ip_addr{"[127.0.0.1]"};
59 CHECK(ip_addr.is_address_literal());
61 catch (std::exception const& ex) {
62 LOG(FATAL) << "should not throw " << ex.what();
65 try {
66 Domain const ip_addr{"127.0.0.1"};
67 CHECK(ip_addr.is_address_literal());
69 catch (std::exception const& ex) {
70 LOG(FATAL) << "should not throw " << ex.what();
73 Domain const mixed_case{"ExAmPle.COM"};
74 CHECK_EQ(mixed_case.ascii(), "example.com");
76 for (auto arg{1}; arg < argc; ++arg) {
77 Domain const a{argv[arg]};
78 std::cout << a << '\n';