Skip to content

Commit

Permalink
[17_1] unit tests for as_int
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Oct 30, 2023
1 parent cb478dd commit be2bcca
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/Kernel/Types/string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ TEST_CASE ("test as bool") {
// implicit conversion from char*
}

TEST_CASE ("as_int") {
SUBCASE ("normal conversion") {
CHECK_EQ (as_int ("1"), 1);
CHECK_EQ (as_int ("-1"), -1);
CHECK_EQ (as_int ("0"), 0);
}

// assuming int is 32bit
SUBCASE ("min and max") {
CHECK_EQ (as_int ("-2147483648"), -2147483648);
CHECK_EQ (as_int ("2147483647"), 2147483647);
}

SUBCASE ("int overflow") {
CHECK_EQ (as_int ("-2147483649"), 2147483647);
CHECK_EQ (as_int ("2147483648"), -2147483648);
}

SUBCASE ("int overflow") {
CHECK_EQ (as_int ("not a int"), 0);
}
}

TEST_CASE ("test as strig bool") {
CHECK_EQ (as_string_bool (true) == string ("true"), true);
CHECK_EQ (as_string_bool (false) == string ("false"), true);
Expand Down

0 comments on commit be2bcca

Please sign in to comment.