A string assumption/assertion verifies that a string of characters matches a specific pattern, length, or expected content. This type of assumption is frequently used in input validation, ensuring that strings adhere to formatting rules, such as for email addresses, file paths, or passwords. String assertions also help detect anomalies like unexpected null characters or incorrect encodings, ensuring proper handling of text data in applications.
Code reference for C, C++, or Python APIs for a respective Fossil Logic Project.
C, C++ REFERENCE #
/**
* @brief Assumes that the given C strings are equal.
*
* @param actual The actual C string.
* @param expected The expected C string.
*/
#define ASSUME_ITS_EQUAL_CSTR(actual, expected) \
FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected)
/**
* @brief Assumes that the given C strings are not equal.
*
* @param actual The actual C string.
* @param expected The expected C string.
*/
#define ASSUME_NOT_EQUAL_CSTR(actual, expected) \
FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected)
/**
* @brief Assumes that the length of the given C string is equal to the expected length.
*
* @param actual The actual C string.
* @param expected_len The expected length of the C string.
*/
#define ASSUME_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \
FOSSIL_TEST_ASSUME(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len)
/**
* @brief Assumes that the length of the given C string is not equal to the expected length.
*
* @param actual The actual C string.
* @param expected_len The expected length of the C string.
*/
#define ASSUME_NOT_LENGTH_EQUAL_CSTR(actual, expected_len) \
FOSSIL_TEST_ASSUME(strlen((actual)) != (expected_len), "Expected length of C string " #actual " to not be equal to " #expected_len)
/**
* @brief Assumes that the given cstr starts with the specified prefix.
*
* @param str The cstr to be checked.
* @param prefix The prefix to check for.
*/
#define ASSUME_ITS_CSTR_STARTS_WITH(str, prefix) \
FOSSIL_TEST_ASSUME(pizza_io_cstr_starts_with((str), (prefix)), "Expected cstr " #str " to start with prefix " #prefix)
/**
* @brief Assumes that the given cstr does not start with the specified prefix.
*
* @param str The cstr to be checked.
* @param prefix The prefix to check for.
*/
#define ASSUME_NOT_CSTR_STARTS_WITH(str, prefix) \
FOSSIL_TEST_ASSUME(!pizza_io_cstr_starts_with((str), (prefix)), "Expected cstr " #str " to not start with prefix " #prefix)
/**
* @brief Assumes that the given cstr ends with the specified suffix.
*
* @param str The cstr to be checked.
* @param suffix The suffix to check for.
*/
#define ASSUME_ITS_CSTR_ENDS_WITH(str, suffix) \
FOSSIL_TEST_ASSUME(pizza_io_cstr_ends_with((str), (suffix)), "Expected cstr " #str " to end with suffix " #suffix)
/**
* @brief Assumes that the given cstr does not end with the specified suffix.
*
* @param str The cstr to be checked.
* @param suffix The suffix to check for.
*/
#define ASSUME_NOT_CSTR_ENDS_WITH(str, suffix) \
FOSSIL_TEST_ASSUME(!pizza_io_cstr_ends_with((str), (suffix)), "Expected cstr " #str " to not end with suffix " #suffix)
/**
* @brief Assumes that the given cstr contains the specified substring.
*
* @param str The cstr to be checked.
* @param substr The substring to check for.
*/
#define ASSUME_ITS_CSTR_CONTAINS(str, substr) \
FOSSIL_TEST_ASSUME(pizza_io_cstr_contains((str), (substr)), "Expected cstr " #str " to contain substring " #substr)
/**
* @brief Assumes that the given cstr does not contain the specified substring.
*
* @param str The cstr to be checked.
* @param substr The substring to check for.
*/
#define ASSUME_NOT_CSTR_CONTAINS(str, substr) \
FOSSIL_TEST_ASSUME(!pizza_io_cstr_contains((str), (substr)), "Expected cstr " #str " to not contain substring " #substr)
/**
* @brief Assumes that the given cstr contains the specified number of occurrences of a substring.
*
* @param str The cstr to be searched.
* @param substr The substring to search for.
* @param count The expected number of occurrences.
*/
#define ASSUME_ITS_CSTR_COUNT(str, substr, count) \
FOSSIL_TEST_ASSUME(pizza_io_cstr_count((str), (substr)) == (count), "Expected cstr " #str " to contain " #count " occurrences of substring " #substr)
/**
* @brief Assumes that the given cstr does not contain the specified number of occurrences of a substring.
*
* @param str The cstr to be searched.
* @param substr The substring to search for.
* @param count The expected number of occurrences.
*/
#define ASSUME_NOT_CSTR_COUNT(str, substr, count) \
FOSSIL_TEST_ASSUME(pizza_io_cstr_count((str), (substr)) != (count), "Expected cstr " #str " to not contain " #count " occurrences of substring " #substr)PYTHON REFERENCE #
# TODO: add code here