mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(string): add SStrToInt
This commit is contained in:
parent
e51d4cdaa1
commit
3d59699e1b
3 changed files with 70 additions and 0 deletions
|
|
@ -217,3 +217,47 @@ TEST_CASE("SStrStr", "[string]") {
|
|||
REQUIRE(substring == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SStrToInt", "[string]") {
|
||||
SECTION("converts empty string to int") {
|
||||
auto string = "";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == 0);
|
||||
}
|
||||
|
||||
SECTION("converts whitespace string to int") {
|
||||
auto string = " ";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == 0);
|
||||
}
|
||||
|
||||
SECTION("converts string with positive number to int") {
|
||||
auto string = "123";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == 123);
|
||||
}
|
||||
|
||||
SECTION("converts string with negative number to int") {
|
||||
auto string = "-123";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == -123);
|
||||
}
|
||||
|
||||
SECTION("converts string with zero to int") {
|
||||
auto string = "0";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == 0);
|
||||
}
|
||||
|
||||
SECTION("converts string with leading zero to int") {
|
||||
auto string = "01";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == 1);
|
||||
}
|
||||
|
||||
SECTION("converts string with two whitespace-separated numbers to int") {
|
||||
auto string = "123 456";
|
||||
auto result = SStrToInt(string);
|
||||
REQUIRE(result == 123);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue