mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-20 00:05:41 -05:00
Add more tests
This commit is contained in:
63
tests/test-utility.cpp
Normal file
63
tests/test-utility.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <utility.hpp>
|
||||
|
||||
TEST_CASE("ReplaceAll", "[utility]")
|
||||
{
|
||||
std::string input;
|
||||
auto result = advss::ReplaceAll(input, "", "");
|
||||
REQUIRE_FALSE(result);
|
||||
REQUIRE(input == "");
|
||||
|
||||
input = "testing";
|
||||
result = advss::ReplaceAll(input, "not there", "sleep");
|
||||
REQUIRE_FALSE(result);
|
||||
REQUIRE(input == "testing");
|
||||
|
||||
input = "testing";
|
||||
result = advss::ReplaceAll(input, "test", "sleep");
|
||||
REQUIRE(result);
|
||||
REQUIRE(input == "sleeping");
|
||||
}
|
||||
|
||||
TEST_CASE("GetJsonField", "[utility]")
|
||||
{
|
||||
auto result = advss::GetJsonField("{}", "");
|
||||
REQUIRE_FALSE(result);
|
||||
|
||||
result = advss::GetJsonField("{}", "not there");
|
||||
REQUIRE_FALSE(result);
|
||||
|
||||
result = advss::GetJsonField("invalid json", "not there");
|
||||
REQUIRE_FALSE(result);
|
||||
|
||||
result = advss::GetJsonField("{ \"test\": 1 }", "test");
|
||||
REQUIRE(*result == "1");
|
||||
}
|
||||
|
||||
TEST_CASE("CompareIgnoringLineEnding", "[utility]")
|
||||
{
|
||||
QString s1;
|
||||
QString s2;
|
||||
REQUIRE(advss::CompareIgnoringLineEnding(s1, s2));
|
||||
|
||||
s1 = "test";
|
||||
s2 = "test";
|
||||
REQUIRE(advss::CompareIgnoringLineEnding(s1, s2));
|
||||
|
||||
s1 = "test";
|
||||
s2 = "something else";
|
||||
REQUIRE_FALSE(advss::CompareIgnoringLineEnding(s1, s2));
|
||||
|
||||
s1 = "test\r\nwith line ending";
|
||||
s2 = "test\nwith line ending";
|
||||
REQUIRE(advss::CompareIgnoringLineEnding(s1, s2));
|
||||
}
|
||||
|
||||
TEST_CASE("ToString", "[utility]")
|
||||
{
|
||||
REQUIRE(advss::ToString(1.0) == "1");
|
||||
REQUIRE(advss::ToString(-1.0) == "-1");
|
||||
REQUIRE(advss::ToString(-1.0) == "-1");
|
||||
REQUIRE(advss::ToString(-1.23) == "-1.23");
|
||||
}
|
||||
Reference in New Issue
Block a user