nstr: include nstrmul test
i am very smart
This commit is contained in:
parent
87d0a30dab
commit
9b191d9b9a
5 changed files with 25 additions and 33 deletions
|
@ -40,14 +40,15 @@ struct _neo_nstr_init_info {
|
|||
#define nstr_raw(nstr) ((nstr)->_data)
|
||||
|
||||
/**
|
||||
* @brief Statically initialize a neo string (file scope only).
|
||||
* @brief Statically define an already declared neo string (file scope only).
|
||||
*
|
||||
* The string will be initialized before `main` is called.
|
||||
*
|
||||
* @param name Name of the (already declared) `nstr_t *` to initialize
|
||||
* @param content A `const char *` with the contents of the string
|
||||
* @see NSTR
|
||||
*/
|
||||
#define NSTR_INIT(name, content) \
|
||||
#define NSTR_DEFINE(name, content) \
|
||||
__neo_section(.data.__neo.nstr_array) \
|
||||
struct _neo_nstr_init_info __neo_nstr_init_info_##name = { \
|
||||
.dest = &name, \
|
||||
|
@ -62,9 +63,9 @@ struct _neo_nstr_init_info {
|
|||
* @param name Name of the `nstr_t *` variable to be declared
|
||||
* @param content A `const char *` with the contents of the string
|
||||
*/
|
||||
#define NSTR_DEFINE(name, content) \
|
||||
#define NSTR(name, content) \
|
||||
nstr_t *name = nil; \
|
||||
NSTR_INIT(name, content)
|
||||
NSTR_DEFINE(name, content)
|
||||
|
||||
/**
|
||||
* @brief Copy a regular C string to a neo string.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/** See the end of this file for copyright and license terms. */
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -60,9 +60,9 @@ TEST_CASE( "nnstr: Error if raw strig is nil", "[string/nstr,c]")
|
|||
errput(&err);
|
||||
}
|
||||
|
||||
NSTR_DEFINE(static_test_string_1, "i'm gay,,,");
|
||||
NSTR(static_test_string_1, "i'm gay,,,");
|
||||
|
||||
TEST_CASE( "_neo_nstr_init_array: Statically initialize ASCII string", "[string/nstr.c]" )
|
||||
TEST_CASE( "NSTR: Statically initialize ASCII string", "[string/nstr.c]" )
|
||||
{
|
||||
nstr_t *expected_s1 = nstr("i'm gay,,,", nil);
|
||||
|
||||
|
@ -70,9 +70,10 @@ TEST_CASE( "_neo_nstr_init_array: Statically initialize ASCII string", "[string/
|
|||
REQUIRE( nlen(static_test_string_1) == 10 );
|
||||
}
|
||||
|
||||
nstr_t *static_test_string_2;
|
||||
NSTR_DEFINE(static_test_string_2, "i'm gay\xf0\x9f\xa5\xba,,,");
|
||||
|
||||
TEST_CASE( "_neo_nstr_init_array: Statically initialize UTF-8 string", "[string/nstr.c]" )
|
||||
TEST_CASE( "NSTR_DEFINE: Statically initialize UTF-8 string", "[string/nstr.c]" )
|
||||
{
|
||||
nstr_t *expected_s2 = nstr("i'm gay\xf0\x9f\xa5\xba,,,", nil);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <neo.h>
|
||||
|
||||
TEST_CASE( "nstrmul: Repeat a string", "[string/nstrcat.c]" )
|
||||
TEST_CASE( "nstrmul: Repeat a string", "[string/nstrmul.c]" )
|
||||
{
|
||||
error err;
|
||||
nstr_t *s = nstr("aaaaa", nil);
|
||||
|
@ -23,14 +23,14 @@ TEST_CASE( "nstrmul: Repeat a string", "[string/nstrcat.c]" )
|
|||
nput(actual);
|
||||
}
|
||||
|
||||
TEST_CASE( "nstrmul: Duplicate a string if count is 1", "[string/nstrcat.c]" )
|
||||
TEST_CASE( "nstrmul: Duplicate a string if count is 1", "[string/nstrmull.c]" )
|
||||
{
|
||||
error err;
|
||||
nstr_t *s = nstr("aaaaa", nil);
|
||||
|
||||
nstr_t *mul = nstrmul(s, 1, &err);
|
||||
|
||||
REQUIRE( nul != nil );
|
||||
REQUIRE( mul != nil );
|
||||
REQUIRE( nlen(mul) == 5 );
|
||||
REQUIRE( nstreq(s, mul, nil) );
|
||||
REQUIRE( errnum(&err) == 0 );
|
||||
|
@ -39,36 +39,25 @@ TEST_CASE( "nstrmul: Duplicate a string if count is 1", "[string/nstrcat.c]" )
|
|||
nput(mul);
|
||||
}
|
||||
|
||||
TEST_CASE( "nstrmul: Error if string is nil", "[string/nstrcat.c]" )
|
||||
{
|
||||
error err;
|
||||
nstr_t *mul = nstrmul(nil, 1, &err);
|
||||
|
||||
nstr_t *expected_msg = nstr("String is nil", nil);
|
||||
|
||||
REQUIRE( mul == nil );
|
||||
REQUIRE( errnum(&err) == EFAULT );
|
||||
REQUIRE( nstreq(expected_msg, errmsg(&err), nil) );
|
||||
|
||||
errput(&err);
|
||||
}
|
||||
|
||||
TEST_CASE( "nstrmul: Return empty string if count is 0", "[string/nstrcat.c]" )
|
||||
TEST_CASE( "nstrmul: Return empty string if count is 0", "[string/nstrmul.c]" )
|
||||
{
|
||||
error err;
|
||||
nstr_t *s = nstr("aaaaa", nil);
|
||||
nstr_t *mul = nstrmul(s, 0, &err);
|
||||
|
||||
nstr_t *expected_msg = nstr("String is nil", nil);
|
||||
nstr_t *expected = nstr("", nil);
|
||||
nstr_t *actual = nstrmul(s, 0, &err);
|
||||
|
||||
REQUIRE( mul == nil );
|
||||
REQUIRE( errnum(&err) == EFAULT );
|
||||
REQUIRE( nstreq(expected_msg, errmsg(&err), nil) );
|
||||
REQUIRE( actual != nil );
|
||||
REQUIRE( nlen(actual) == 0 );
|
||||
REQUIRE( nstreq(expected, actual, nil) );
|
||||
REQUIRE( errnum(&err) == 0 );
|
||||
|
||||
errput(&err);
|
||||
nput(expected);
|
||||
nput(actual);
|
||||
nput(s);
|
||||
}
|
||||
|
||||
TEST_CASE( "nstrmul: Error if string is nil", "[string/nstrcat.c]" )
|
||||
TEST_CASE( "nstrmul: Error if string is nil", "[string/nstrmul.c]" )
|
||||
{
|
||||
error err;
|
||||
nstr_t *mul = nstrmul(nil, 3, &err);
|
||||
|
|
|
@ -9,6 +9,7 @@ target_sources(neo_test PRIVATE
|
|||
string/nstrcat.cpp
|
||||
string/nstrcmp.cpp
|
||||
string/nstrdup.cpp
|
||||
string/nstrmul.cpp
|
||||
string/u2nstr.cpp
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue