|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
/** 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>
|
|
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|