string: Add new HEX sub-command

This commit is contained in:
Kyle Edwards
2020-02-18 10:49:02 -05:00
parent 952945813c
commit 5395bf05eb
11 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
function(assert_strequal input actual expected)
if(NOT expected STREQUAL actual)
message(SEND_ERROR "Output did not match expected\nInput string:\n ${input}\nExpected:\n ${expected}\nActual:\n ${actual}")
endif()
endfunction()
set(_input1 "The quick brown fox jumps over the lazy dog.")
string(HEX "${_input1}" _result1)
assert_strequal("${_input1}" "${_result1}" "54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f672e")
set(_input2 "Hello world!")
string(HEX "${_input2}" _result2)
assert_strequal("${_input2}" "${_result2}" "48656c6c6f20776f726c6421")
set(_input3 "Ash nazg durbatulûk\nAsh nazg gimbatul\nAsh nazg thrakatulûk\nAgh burzum-ishi krimpatul")
string(HEX "${_input3}" _result3)
assert_strequal("${_input3}" "${_result3}" "417368206e617a6720647572626174756cc3bb6b0a417368206e617a672067696d626174756c0a417368206e617a6720746872616b6174756cc3bb6b0a416768206275727a756d2d69736869206b72696d706174756c")
string(HEX "" _result_empty)
assert_strequal("" "${_result_empty}" "")

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
^CMake Error at HexNotEnoughArgs\.cmake:[0-9]+ \(string\):
string Incorrect number of arguments
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)$

View File

@@ -0,0 +1 @@
string(HEX "Hello world!")

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
^CMake Error at HexTooManyArgs\.cmake:[0-9]+ \(string\):
string Incorrect number of arguments
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)$

View File

@@ -0,0 +1 @@
string(HEX "Hello world!" _output bad)

View File

@@ -37,3 +37,7 @@ run_cmake(UTF-32LE)
run_cmake(Repeat)
run_cmake(RepeatNoArgs)
run_cmake(RepeatNegativeCount)
run_cmake(Hex)
run_cmake(HexTooManyArgs)
run_cmake(HexNotEnoughArgs)