From 45e9e943115badd1a10ce18dc660408564e4aac9 Mon Sep 17 00:00:00 2001 From: Treeston Date: Sun, 30 Aug 2020 02:50:25 +0200 Subject: Core/ChatCommands: C++17 cleanup (again) (PR #25323) (cherry picked from commit 2f7d2ef3e979ecd0536f3a3713e56c8e59652a47) --- tests/game/ChatCommand.cpp | 58 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/game/ChatCommand.cpp b/tests/game/ChatCommand.cpp index 5aab641deba..f484b5806c5 100644 --- a/tests/game/ChatCommand.cpp +++ b/tests/game/ChatCommand.cpp @@ -27,7 +27,7 @@ static void TestChatCommand(char const* c, F f, Optional expected = true) { bool r = ChatCommand("", 0, false, +f, "")(nullptr, c); if (expected) - ASSERT(r == *expected); + REQUIRE(r == *expected); } TEST_CASE("Command return pass-through", "[ChatCommand]") @@ -38,27 +38,51 @@ TEST_CASE("Command return pass-through", "[ChatCommand]") TEST_CASE("Command argument parsing", "[ChatCommand]") { - TestChatCommand("42", [](ChatHandler*, uint32 u) + SECTION("Single uint32 argument") { - REQUIRE(u == 42); - return true; - }); + TestChatCommand("42", [](ChatHandler*, uint32 u) + { + REQUIRE(u == 42); + return true; + }); + TestChatCommand("true", [](ChatHandler*, uint32) { return true; }, false); + } - TestChatCommand("true", [](ChatHandler*, uint32) { return true; }, false); + SECTION("std::vector") + { + TestChatCommand("1 2 3 4 5 6 7 8 9 10", [](ChatHandler*, std::vector v) + { + REQUIRE(v.size() == 10); + for (size_t i = 0; i < 10; ++i) + REQUIRE(v[i] == (i + 1)); + return true; + }); + } - TestChatCommand("1 2 3 4 5 6 7 8 9 10", [](ChatHandler*, std::vector v) + SECTION("Hyperlink") { - REQUIRE(v.size() == 10); - for (size_t i = 0; i < 10; ++i) - REQUIRE(v[i] == (i + 1)); - return true; - }); + TestChatCommand("|cffff0000|Hplayer:Test|h[Test]|h|r", + [](ChatHandler*, Hyperlink player) + { + REQUIRE("Test"sv == *player); + return true; + } + ); + } - TestChatCommand("|cffff0000|Hplayer:Test|h[Test]|h|r", - [](ChatHandler*, Hyperlink player) + SECTION("Two strings") + { + TestChatCommand("two strings", [](ChatHandler*, std::string_view v1, std::string_view v2) + { + REQUIRE(v1 == "two"); + REQUIRE(v2 == "strings"); + return true; + }); + TestChatCommand("two strings", [](ChatHandler*, std::string_view) { return true; }, false); + TestChatCommand("two strings", [](ChatHandler*, Tail t) { - REQUIRE("Test"sv == *player); + REQUIRE(t == "two strings"); return true; - } - ); + }); + } } -- cgit v1.2.3