summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-09-20 15:12:23 (GMT)
committerBrad King <brad.king@kitware.com>2022-09-20 16:00:08 (GMT)
commit31f158e4c881bea2b526102b2024b0fb34ade42d (patch)
tree5013888d1c3c2dd765c641946e82fc8468c6485c /Tests
parent5d80d7cb6a76e92ac5b0fa5352cdda64415124b7 (diff)
downloadCMake-31f158e4c881bea2b526102b2024b0fb34ade42d.zip
CMake-31f158e4c881bea2b526102b2024b0fb34ade42d.tar.gz
CMake-31f158e4c881bea2b526102b2024b0fb34ade42d.tar.bz2
cmStringAlgorithms: Add functions to parse strings to long long integers
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLib/testStringAlgorithms.cxx35
1 files changed, 35 insertions, 0 deletions
diff --git a/Tests/CMakeLib/testStringAlgorithms.cxx b/Tests/CMakeLib/testStringAlgorithms.cxx
index c2706c1..1e6b611 100644
--- a/Tests/CMakeLib/testStringAlgorithms.cxx
+++ b/Tests/CMakeLib/testStringAlgorithms.cxx
@@ -227,6 +227,41 @@ int testStringAlgorithms(int /*unused*/, char* /*unused*/ [])
}
// ----------------------------------------------------------------------
+ // Test cmStrToLongLong
+ {
+ long long value;
+ assert_ok(cmStrToLongLong("1", &value) && value == 1,
+ "cmStrToLongLong parses a positive decimal integer.");
+ assert_ok(cmStrToLongLong(" 1", &value) && value == 1,
+ "cmStrToLongLong parses a decimal integer after whitespace.");
+
+ assert_ok(cmStrToLongLong("-1", &value) && value == -1,
+ "cmStrToLongLong parses a negative decimal integer.");
+ assert_ok(
+ cmStrToLongLong(" -1", &value) && value == -1,
+ "cmStrToLongLong parses a negative decimal integer after whitespace.");
+
+ assert_ok(!cmStrToLongLong("1x", &value),
+ "cmStrToLongLong rejects trailing content.");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test cmStrToULongLong
+ {
+ unsigned long long value;
+ assert_ok(cmStrToULongLong("1", &value) && value == 1,
+ "cmStrToULongLong parses a decimal integer.");
+ assert_ok(cmStrToULongLong(" 1", &value) && value == 1,
+ "cmStrToULongLong parses a decimal integer after whitespace.");
+ assert_ok(!cmStrToULongLong("-1", &value),
+ "cmStrToULongLong rejects a negative number.");
+ assert_ok(!cmStrToULongLong(" -1", &value),
+ "cmStrToULongLong rejects a negative number after whitespace.");
+ assert_ok(!cmStrToULongLong("1x", &value),
+ "cmStrToULongLong rejects trailing content.");
+ }
+
+ // ----------------------------------------------------------------------
// Test cmStrLen
{
constexpr auto len = cmStrLen("Hello world!");