feat add string_view
All checks were successful
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m21s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m36s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m40s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m46s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m59s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m6s
All checks were successful
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m21s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m36s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m40s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m46s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m59s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m6s
This commit is contained in:
parent
3ff3323424
commit
e9a9a2ff72
@ -191,6 +191,8 @@ if(SLED_BUILD_TESTS)
|
|||||||
src/sled/debugging/symbolize_test.cc NO_MAIN)
|
src/sled/debugging/symbolize_test.cc NO_MAIN)
|
||||||
sled_add_test(NAME sled_sigslot_test SRCS src/sled/sigslot_test.cc)
|
sled_add_test(NAME sled_sigslot_test SRCS src/sled/sigslot_test.cc)
|
||||||
sled_add_test(NAME sled_rpc_test SRCS src/sled/network/rpc_test.cc)
|
sled_add_test(NAME sled_rpc_test SRCS src/sled/network/rpc_test.cc)
|
||||||
|
sled_add_test(NAME sled_string_view_test SRCS
|
||||||
|
src/sled/nonstd/string_view_test.cc)
|
||||||
endif(SLED_BUILD_TESTS)
|
endif(SLED_BUILD_TESTS)
|
||||||
|
|
||||||
if(SLED_BUILD_FUZZ)
|
if(SLED_BUILD_FUZZ)
|
||||||
|
1713
src/sled/nonstd/string_view.h
Normal file
1713
src/sled/nonstd/string_view.h
Normal file
File diff suppressed because it is too large
Load Diff
59
src/sled/nonstd/string_view_test.cc
Normal file
59
src/sled/nonstd/string_view_test.cc
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include <sled/nonstd/string_view.h>
|
||||||
|
|
||||||
|
using namespace sled;
|
||||||
|
using size_type = size_t;
|
||||||
|
|
||||||
|
TEST_SUITE("string_view")
|
||||||
|
{
|
||||||
|
TEST_CASE("string_view: Allows to default construct an empty string_view")
|
||||||
|
{
|
||||||
|
string_view sv;
|
||||||
|
|
||||||
|
// use parenthesis with data() to prevent lest from using sv.data() as C-string:
|
||||||
|
|
||||||
|
CHECK(sv.size() == size_type(0));
|
||||||
|
CHECK((sv.data() == nssv_nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("string_view: Allows to construct from pointer and size")
|
||||||
|
{
|
||||||
|
string_view sv("hello world", 5);
|
||||||
|
|
||||||
|
CHECK(sv.size() == size_type(5));
|
||||||
|
CHECK(*(sv.data() + 0) == 'h');
|
||||||
|
CHECK(*(sv.data() + 4) == 'o');
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("string_view: Allows to construct from C-string")
|
||||||
|
{
|
||||||
|
string_view sv("hello world");
|
||||||
|
|
||||||
|
CHECK(sv.size() == size_type(11));
|
||||||
|
CHECK(*(sv.data() + 0) == 'h');
|
||||||
|
CHECK(*(sv.data() + 10) == 'd');
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("string_view: Allows to copy-construct from empty string_view")
|
||||||
|
{
|
||||||
|
string_view sv1;
|
||||||
|
|
||||||
|
string_view sv2(sv1);
|
||||||
|
|
||||||
|
// use parenthesis with data() to prevent lest from using sv.data() as C-string:
|
||||||
|
|
||||||
|
CHECK(sv2.size() == size_type(0));
|
||||||
|
CHECK((sv2.data() == nssv_nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("string_view: Allows to copy-construct from non-empty string_view")
|
||||||
|
{
|
||||||
|
string_view sv1("hello world", 5);
|
||||||
|
|
||||||
|
string_view sv2(sv1);
|
||||||
|
|
||||||
|
CHECK(sv2.size() == sv1.size());
|
||||||
|
CHECK((sv2.data() == sv1.data()));
|
||||||
|
CHECK(*(sv2.data() + 0) == 'h');
|
||||||
|
CHECK(*(sv2.data() + 4) == 'o');
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,10 @@
|
|||||||
#define SLED_SLED_H
|
#define SLED_SLED_H
|
||||||
|
|
||||||
// thrid_party
|
// thrid_party
|
||||||
#include "async/async.h"
|
|
||||||
#include "inja.hpp"
|
#include "inja.hpp"
|
||||||
#include "rx.h"
|
#include "rx.h"
|
||||||
|
#include "sled/async/async.h"
|
||||||
|
#include "sled/nonstd/string_view.h"
|
||||||
#include "toml.hpp"
|
#include "toml.hpp"
|
||||||
|
|
||||||
// experimental
|
// experimental
|
||||||
@ -22,7 +23,7 @@
|
|||||||
// #include "sled/futures/promise.h"
|
// #include "sled/futures/promise.h"
|
||||||
|
|
||||||
// lang
|
// lang
|
||||||
#include "lang/attributes.h"
|
#include "sled/lang/attributes.h"
|
||||||
|
|
||||||
// log
|
// log
|
||||||
#include "sled/log/log.h"
|
#include "sled/log/log.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user