-
Notifications
You must be signed in to change notification settings - Fork 7
Adds regex_equal/regex_not_equal #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright 2025 CMakePP | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| include_guard() | ||
| include("cmakepp_lang/asserts/signature") | ||
|
|
||
| #[[[ | ||
| # Asserts that the contents of the provided variable matches the given regular | ||
| # expression. | ||
| # | ||
| # :code:`var` must be a non-empty string, otherwise an :code:`ASSERTION_FAILED` | ||
| # exception is raised. | ||
| # | ||
| # :param var: The variable to apply the RegEx to. | ||
| # :type var: str* | ||
| # :param regex: The RegEx to apply to var. | ||
| # :type regex: str | ||
| #]] | ||
| function(ct_assert_regex_equal _are_var _are_regex) | ||
| cpp_assert_signature("${ARGV}" str* str) | ||
ryanmrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Check separately for empty string | ||
| # since it will blow up the next if statement | ||
| # otherwise | ||
| if (_are_var STREQUAL "") | ||
| cpp_raise( | ||
| ASSERTION_FAILED | ||
| "ct_assert_regex_equal() given empty string as parameter" | ||
| ) | ||
| endif() | ||
|
|
||
| if(NOT (${_are_var} MATCHES "${_are_regex}")) | ||
| cpp_raise( | ||
| ASSERTION_FAILED | ||
| "${_are_var} does not match RegEx ${_are_regex}." | ||
| ) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| #[[[ | ||
| # Asserts that the contents of the provided variable don't match the given | ||
| # regular expression. | ||
| # | ||
| # :code:`var` must be a non-empty string, otherwise an :code:`ASSERTION_FAILED` | ||
| # exception is raised. | ||
| # | ||
| # :param var: The variable to apply the regex to. | ||
| # :type var: str* | ||
| # :param regex: The regex to apply. | ||
| # :type regex: str | ||
ryanmrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #]] | ||
| function(ct_assert_regex_not_equal _arne_var _arne_regex) | ||
| cpp_assert_signature("${ARGV}" str* str) | ||
ryanmrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Check separately for empty string | ||
| # since it will blow up the next if statement | ||
| # otherwise | ||
| if (_arne_var STREQUAL "") | ||
| cpp_raise( | ||
| ASSERTION_FAILED | ||
| "ct_assert_regex_not_equal() given empty string as parameter" | ||
| ) | ||
| endif() | ||
|
|
||
| if(${_arne_var} MATCHES "${_arne_regex}") | ||
| cpp_raise( | ||
| ASSERTION_FAILED | ||
| "${_arne_var} satisfies regex: ${_arne_regex}." | ||
| ) | ||
| endif() | ||
| endfunction() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| include(cmake_test/cmake_test) | ||
|
|
||
| ct_add_test(NAME "assert_regex_equal") | ||
| function(${assert_regex_equal}) | ||
| include(cmake_test/asserts/regex_equal) | ||
|
|
||
| set(is_true "TRUE") | ||
| set(contains_a_number "Pi is 3.14") | ||
| set(no_number "Pi is a Greek letter.") | ||
|
|
||
| ct_add_section(NAME truthy_value_match) | ||
| function(${truthy_value_match}) | ||
| ct_assert_regex_equal(is_true "TRUE") | ||
| ct_assert_regex_equal(contains_a_number "[0-9]+\.[0-9]+") | ||
| endfunction() | ||
|
|
||
| ct_add_section(NAME truthy_value_no_match EXPECTFAIL) | ||
| function(${truthy_value_no_match}) | ||
| ct_assert_regex_equal(is_true "FALSE") | ||
| ct_assert_regex_equal(no_number "[0-9]+\.[0-9]+") | ||
| endfunction() | ||
|
|
||
| endfunction() | ||
|
|
||
| ct_add_test(NAME "assert_regex_not_equal") | ||
| function(${assert_regex_not_equal}) | ||
| include(cmake_test/asserts/regex_equal) | ||
|
|
||
| set(is_true "TRUE") | ||
| set(contains_a_number "Pi is 3.14") | ||
| set(no_number "Pi is a Greek letter.") | ||
|
|
||
| ct_add_section(NAME truthy_value_no_match) | ||
| function(${truthy_value_no_match}) | ||
| ct_assert_regex_not_equal(is_true "FALSE") | ||
| ct_assert_regex_not_equal(no_number "[0-9]+\.[0-9]+") | ||
| endfunction() | ||
|
|
||
| ct_add_section(NAME truthy_value EXPECTFAIL) | ||
| function(${truthy_value}) | ||
| ct_assert_regex_not_equal(is_true "TRUE") | ||
| ct_assert_regex_not_equal(contains_a_number "[0-9]+\.[0-9]+") | ||
| endfunction() | ||
|
|
||
| endfunction() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.