explain
[ghsmtp.git] / Domain-test.cpp
blobb1397e42d9c1accc93c9bdd07e6c7dea1fa74117
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"};
38 Domain const norm1{"hi5.com"};
39 CHECK_EQ(norm0, norm1);
41 CHECK(Domain::validate("hi⒌com"));
42 CHECK(Domain::validate("hi5.com"));
44 // FIXME
45 // CHECK(!Domain::validate("$?%^&*("));
47 try {
48 Domain const junk{"$?%^&*("};
49 // idn2 allows this
50 // LOG(FATAL) << "should have thrown";
52 catch (std::exception const& ex) {
53 std::cout << ex.what() << '\n';
56 try {
57 Domain const ip_addr{"[127.0.0.1]"};
58 CHECK(ip_addr.is_address_literal());
60 catch (std::exception const& ex) {
61 LOG(FATAL) << "should not throw " << ex.what();
64 try {
65 Domain const ip_addr{"127.0.0.1"};
66 CHECK(ip_addr.is_address_literal());
68 catch (std::exception const& ex) {
69 LOG(FATAL) << "should not throw " << ex.what();
72 Domain const mixed_case{"ExAmPle.COM"};
73 CHECK_EQ(mixed_case.ascii(), "example.com");
75 for (auto arg{1}; arg < argc; ++arg) {
76 Domain const a{argv[arg]};
77 std::cout << a << '\n';