mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-12-11 21:13:00 +01:00
feat: add assert
module
This commit is contained in:
parent
1be12c2a97
commit
336bbf6197
@ -1,7 +1,7 @@
|
||||
#include "test.h"
|
||||
#include "assert.h"
|
||||
|
||||
bool assert_string_equal(const string_t actual, const string_t expected) {
|
||||
if (strcmp(expected, actual) != 0) {
|
||||
if (!string_equals(actual, expected)) {
|
||||
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
|
||||
return false;
|
||||
}
|
||||
@ -9,7 +9,7 @@ bool assert_string_equal(const string_t actual, const string_t expected) {
|
||||
}
|
||||
|
||||
bool assert_string_not_equal(const string_t actual, const string_t expected) {
|
||||
if (strcmp(expected, actual) == 0) {
|
||||
if (string_equals(actual, expected)) {
|
||||
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
|
||||
return false;
|
||||
}
|
30
lib/assert.h
Normal file
30
lib/assert.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef __LIBCPROJECT_ASSERT__
|
||||
#define __LIBCPROJECT_ASSERT__
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "string.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @brief Check if the two strings are equal. If they are not equal, print the expected and actual strings.
|
||||
*
|
||||
* @param character
|
||||
* @return bool
|
||||
* @since v5.0.0
|
||||
*/
|
||||
bool assert_string_equal(const string_t actual, const string_t expected);
|
||||
|
||||
/**
|
||||
* @brief Check if the two strings are not equal. If they are equal, print the expected and actual strings.
|
||||
*
|
||||
* @param character
|
||||
* @return bool
|
||||
* @since v5.0.0
|
||||
*/
|
||||
bool assert_string_not_equal(const string_t actual, const string_t expected);
|
||||
|
||||
#endif
|
@ -48,8 +48,7 @@ char character_to_lower(const char character);
|
||||
* @brief Check if the character is a digit ('0', '1', '2', '3', '4', '5', '6', '7, '8' or '9').
|
||||
*
|
||||
* @param character
|
||||
* @return true
|
||||
* @return false
|
||||
* @return bool
|
||||
* @since v1.0.0
|
||||
*/
|
||||
bool character_get_is_digit(const char character);
|
||||
|
@ -43,8 +43,7 @@ int filesystem_write(string_t path, byte_t *file_content, size_t file_size);
|
||||
* @brief Check if a path exists.
|
||||
*
|
||||
* @param path
|
||||
* @return true
|
||||
* @return false
|
||||
* @return bool
|
||||
* @since v3.1.0
|
||||
*/
|
||||
bool filesystem_exists(string_t path);
|
||||
|
@ -85,8 +85,7 @@ void *hash_map_get(struct hash_map *hash_map, string_t key);
|
||||
*
|
||||
* @param hash_map
|
||||
* @param key
|
||||
* @return true
|
||||
* @return false
|
||||
* @return bool
|
||||
* @since v2.0.0
|
||||
*/
|
||||
bool hash_map_contains_key(struct hash_map *hash_map, string_t key);
|
||||
|
@ -14,8 +14,7 @@
|
||||
*
|
||||
* @param number1
|
||||
* @param number2
|
||||
* @return true
|
||||
* @return false
|
||||
* @return bool
|
||||
* @since v1.0.0
|
||||
*/
|
||||
bool mathematics_equals(const float64_t number1, const float64_t number2);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __LIBCPROJECT__
|
||||
|
||||
#include "lib/array_list.h"
|
||||
#include "lib/assert.h"
|
||||
#include "lib/character.h"
|
||||
#include "lib/convert.h"
|
||||
#include "lib/date.h"
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
#include "test.h"
|
||||
|
||||
void character_test();
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
#include "test.h"
|
||||
|
||||
void convert_test();
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
#include "test.h"
|
||||
|
||||
void date_test();
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
#include "test.h"
|
||||
|
||||
void string_test();
|
||||
|
||||
|
14
test/test.h
14
test/test.h
@ -1,14 +0,0 @@
|
||||
#ifndef __TEST__
|
||||
#define __TEST__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
|
||||
bool assert_string_equal(const string_t actual, const string_t expected);
|
||||
|
||||
bool assert_string_not_equal(const string_t actual, const string_t expected);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user