summaryrefslogtreecommitdiff
path: root/Tests/CMakeLib
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-09-20 11:12:23 -0400
committerBrad King <brad.king@kitware.com>2022-09-20 12:00:08 -0400
commit31f158e4c881bea2b526102b2024b0fb34ade42d (patch)
tree5013888d1c3c2dd765c641946e82fc8468c6485c /Tests/CMakeLib
parent5d80d7cb6a76e92ac5b0fa5352cdda64415124b7 (diff)
downloadcmake-31f158e4c881bea2b526102b2024b0fb34ade42d.tar.gz
cmStringAlgorithms: Add functions to parse strings to long long integers
Diffstat (limited to 'Tests/CMakeLib')
-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 c2706c1f92..1e6b6118ee 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!");