comparison tests/src/plugins/history/main.cpp @ 773:8c44bbcbbab9

Misc: style, cleanup and update
author David Demelier <markand@malikania.fr>
date Fri, 26 Oct 2018 13:01:00 +0200
parents 791d7591eca7
children f362994133ca
comparison
equal deleted inserted replaced
772:f5ccf65ae929 773:8c44bbcbbab9
30 30
31 namespace { 31 namespace {
32 32
33 class history_test : public js_plugin_fixture { 33 class history_test : public js_plugin_fixture {
34 public: 34 public:
35 history_test() 35 history_test()
36 : js_plugin_fixture(PLUGIN_PATH) 36 : js_plugin_fixture(PLUGIN_PATH)
37 { 37 {
38 plugin_->set_formats({ 38 plugin_->set_formats({
39 { "error", "error=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}" }, 39 { "error", "error=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}" },
40 { "seen", "seen=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{target}:%H:%M" }, 40 { "seen", "seen=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{target}:%H:%M" },
41 { "said", "said=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{target}:#{message}:%H:%M" }, 41 { "said", "said=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{target}:#{message}:%H:%M" },
42 { "unknown", "unknown=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{target}" }, 42 { "unknown", "unknown=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{target}" },
43 }); 43 });
44 } 44 }
45 45
46 void load(plugin::map config = {}) 46 void load(plugin::map config = {})
47 { 47 {
48 // Add file if not there. 48 // Add file if not there.
49 if (config.count("file") == 0) 49 if (config.count("file") == 0)
50 config.emplace("file", CMAKE_CURRENT_SOURCE_DIR "/words.conf"); 50 config.emplace("file", CMAKE_CURRENT_SOURCE_DIR "/words.conf");
51 51
52 plugin_->set_options(config); 52 plugin_->set_options(config);
53 plugin_->handle_load(irccd_); 53 plugin_->handle_load(irccd_);
54 } 54 }
55 }; 55 };
56 56
57 BOOST_FIXTURE_TEST_SUITE(history_test_suite, history_test) 57 BOOST_FIXTURE_TEST_SUITE(history_test_suite, history_test)
58 58
59 BOOST_AUTO_TEST_CASE(format_error) 59 BOOST_AUTO_TEST_CASE(format_error)
60 { 60 {
61 load({{"file", CMAKE_CURRENT_SOURCE_DIR "/error.json"}}); 61 load({{"file", CMAKE_CURRENT_SOURCE_DIR "/error.json"}});
62 62
63 plugin_->handle_command(irccd_, { server_, "jean!jean@localhost", "#history", "seen francis" }); 63 plugin_->handle_command(irccd_, { server_, "jean!jean@localhost", "#history", "seen francis" });
64 64
65 const auto cmd = server_->find("message").front(); 65 const auto cmd = server_->find("message").front();
66 66
67 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history"); 67 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history");
68 BOOST_TEST(std::any_cast<std::string>(cmd[1]) == "error=history:!history:test:#history:jean!jean@localhost:jean"); 68 BOOST_TEST(std::any_cast<std::string>(cmd[1]) == "error=history:!history:test:#history:jean!jean@localhost:jean");
69 } 69 }
70 70
71 BOOST_AUTO_TEST_CASE(format_seen) 71 BOOST_AUTO_TEST_CASE(format_seen)
72 { 72 {
73 static const std::regex rule("seen=history:!history:test:#history:destructor!dst@localhost:destructor:jean:\\d{2}:\\d{2}"); 73 static const std::regex rule("seen=history:!history:test:#history:destructor!dst@localhost:destructor:jean:\\d{2}:\\d{2}");
74 74
75 remove(CMAKE_CURRENT_BINARY_DIR "/seen.json"); 75 remove(CMAKE_CURRENT_BINARY_DIR "/seen.json");
76 load({{ "file", CMAKE_CURRENT_BINARY_DIR "/seen.json" }}); 76 load({{ "file", CMAKE_CURRENT_BINARY_DIR "/seen.json" }});
77 77
78 plugin_->handle_message(irccd_, { server_, "jean!jean@localhost", "#history", "hello" }); 78 plugin_->handle_message(irccd_, { server_, "jean!jean@localhost", "#history", "hello" });
79 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#history", "seen jean" }); 79 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#history", "seen jean" });
80 80
81 auto cmd = server_->find("message").front(); 81 auto cmd = server_->find("message").front();
82 82
83 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history"); 83 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history");
84 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule)); 84 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule));
85 } 85 }
86 86
87 BOOST_AUTO_TEST_CASE(format_said) 87 BOOST_AUTO_TEST_CASE(format_said)
88 { 88 {
89 std::regex rule("said=history:!history:test:#history:destructor!dst@localhost:destructor:jean:hello:\\d{2}:\\d{2}"); 89 std::regex rule("said=history:!history:test:#history:destructor!dst@localhost:destructor:jean:hello:\\d{2}:\\d{2}");
90 90
91 remove(CMAKE_CURRENT_BINARY_DIR "/said.json"); 91 remove(CMAKE_CURRENT_BINARY_DIR "/said.json");
92 load({{ "file", CMAKE_CURRENT_BINARY_DIR "/said.json" }}); 92 load({{ "file", CMAKE_CURRENT_BINARY_DIR "/said.json" }});
93 93
94 plugin_->handle_message(irccd_, { server_, "jean!jean@localhost", "#history", "hello" }); 94 plugin_->handle_message(irccd_, { server_, "jean!jean@localhost", "#history", "hello" });
95 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#history", "said jean" }); 95 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#history", "said jean" });
96 96
97 const auto cmd = server_->find("message").front(); 97 const auto cmd = server_->find("message").front();
98 98
99 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history"); 99 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history");
100 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule)); 100 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule));
101 } 101 }
102 102
103 BOOST_AUTO_TEST_CASE(format_unknown) 103 BOOST_AUTO_TEST_CASE(format_unknown)
104 { 104 {
105 remove(CMAKE_CURRENT_BINARY_DIR "/unknown.json"); 105 remove(CMAKE_CURRENT_BINARY_DIR "/unknown.json");
106 load({{ "file", CMAKE_CURRENT_BINARY_DIR "/unknown.json" }}); 106 load({{ "file", CMAKE_CURRENT_BINARY_DIR "/unknown.json" }});
107 107
108 plugin_->handle_message(irccd_, { server_, "jean!jean@localhost", "#history", "hello" }); 108 plugin_->handle_message(irccd_, { server_, "jean!jean@localhost", "#history", "hello" });
109 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#history", "seen nobody" }); 109 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#history", "seen nobody" });
110 110
111 const auto cmd = server_->find("message").front(); 111 const auto cmd = server_->find("message").front();
112 112
113 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history"); 113 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history");
114 BOOST_TEST(std::any_cast<std::string>(cmd[1]) == "unknown=history:!history:test:#history:destructor!dst@localhost:destructor:nobody"); 114 BOOST_TEST(std::any_cast<std::string>(cmd[1]) == "unknown=history:!history:test:#history:destructor!dst@localhost:destructor:nobody");
115 } 115 }
116 116
117 BOOST_AUTO_TEST_CASE(issue_642) 117 BOOST_AUTO_TEST_CASE(issue_642)
118 { 118 {
119 static const std::regex rule("said=history:!history:test:#history:destructor!dst@localhost:destructor:jean:hello:\\d{2}:\\d{2}"); 119 static const std::regex rule("said=history:!history:test:#history:destructor!dst@localhost:destructor:jean:hello:\\d{2}:\\d{2}");
120 120
121 remove(CMAKE_CURRENT_BINARY_DIR "/issue-642.json"); 121 remove(CMAKE_CURRENT_BINARY_DIR "/issue-642.json");
122 load({{"file", CMAKE_CURRENT_BINARY_DIR "/issue-642.json"}}); 122 load({{"file", CMAKE_CURRENT_BINARY_DIR "/issue-642.json"}});
123 123
124 plugin_->handle_message(irccd_, { server_, "JeaN!JeaN@localhost", "#history", "hello" }); 124 plugin_->handle_message(irccd_, { server_, "JeaN!JeaN@localhost", "#history", "hello" });
125 125
126 // Full caps. 126 // Full caps.
127 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#HISTORY", "said JEAN" }); 127 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#HISTORY", "said JEAN" });
128 128
129 auto cmd = server_->find("message").front(); 129 auto cmd = server_->find("message").front();
130 130
131 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history"); 131 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history");
132 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule)); 132 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule));
133 133
134 // Random caps. 134 // Random caps.
135 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#HiSToRy", "said JeaN" }); 135 plugin_->handle_command(irccd_, { server_, "destructor!dst@localhost", "#HiSToRy", "said JeaN" });
136 cmd = server_->find("message").back(); 136 cmd = server_->find("message").back();
137 137
138 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history"); 138 BOOST_TEST(std::any_cast<std::string>(cmd[0]) == "#history");
139 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule)); 139 BOOST_TEST(std::regex_match(std::any_cast<std::string>(cmd[1]), rule));
140 } 140 }
141 141
142 BOOST_AUTO_TEST_SUITE_END() 142 BOOST_AUTO_TEST_SUITE_END()
143 143
144 } // !namespace 144 } // !namespace