refactor: continue refactor to make the project can be built
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/constraint.hpp>
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
|
||||
#define CONSTRAINT ::yycc::constraint::Constraint
|
||||
|
||||
|
@ -2,9 +2,10 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/constraint/builder.hpp>
|
||||
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
|
||||
#define BUILDER ::yycc::constraint::builder
|
||||
using namespace std::literals::string_view_literals;
|
||||
|
||||
namespace yycctest::constraint::builder {
|
||||
|
||||
@ -56,8 +57,7 @@ namespace yycctest::constraint::builder {
|
||||
enum class TestEnum : u8 { Entry1 = 0, Entry2 = 1, Entry3 = 2 };
|
||||
|
||||
TEST(ConstraintBuilder, EnumConstraint) {
|
||||
auto c = BUILDER::enum_constraint({TestEnum::Entry1, TestEnum::Entry2, TestEnum::Entry3},
|
||||
1u);
|
||||
auto c = BUILDER::enum_constraint({TestEnum::Entry1, TestEnum::Entry2, TestEnum::Entry3}, 1u);
|
||||
ASSERT_TRUE(c.support_check());
|
||||
ASSERT_TRUE(c.support_clamp());
|
||||
TEST_SUCCESS(c, TestEnum::Entry1);
|
||||
@ -67,16 +67,13 @@ namespace yycctest::constraint::builder {
|
||||
}
|
||||
|
||||
TEST(ConstraintBuilder, StrEnumConstraint) {
|
||||
auto c = BUILDER::strenum_constraint({YYCC_U8("first-entry"),
|
||||
YYCC_U8("second-entry"),
|
||||
YYCC_U8("third-entry")},
|
||||
1u);
|
||||
auto c = BUILDER::strenum_constraint({u8"first-entry"sv, u8"second-entry"sv, u8"third-entry"sv}, 1u);
|
||||
ASSERT_TRUE(c.support_check());
|
||||
ASSERT_TRUE(c.support_clamp());
|
||||
TEST_SUCCESS(c, YYCC_U8("first-entry"));
|
||||
TEST_SUCCESS(c, YYCC_U8("second-entry"));
|
||||
TEST_SUCCESS(c, YYCC_U8("third-entry"));
|
||||
TEST_FAIL(c, YYCC_U8("wtf?"), YYCC_U8("second-entry"));
|
||||
TEST_SUCCESS(c, u8"first-entry");
|
||||
TEST_SUCCESS(c, u8"second-entry");
|
||||
TEST_SUCCESS(c, u8"third-entry");
|
||||
TEST_FAIL(c, u8"wtf?", u8"second-entry");
|
||||
}
|
||||
|
||||
} // namespace yycctest::constraint::builder
|
||||
|
0
testbench/yycc/encoding/utf_literal.hpp
Normal file
0
testbench/yycc/encoding/utf_literal.hpp
Normal file
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/num/parse.hpp>
|
||||
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
|
||||
#define PARSE ::yycc::num::parse
|
||||
|
||||
@ -11,25 +11,71 @@ namespace yycctest::num::parse {
|
||||
// These 2 test macros build string container via given string.
|
||||
// Check `try_parse` first, and then check `parse`.
|
||||
|
||||
#define TEST_NS NumParse
|
||||
|
||||
#define TEST_SUCCESS(type_t, value, string_value, ...) \
|
||||
#define TEST_SUCCESS(type_t, expected_value, string_value, ...) \
|
||||
{ \
|
||||
u8string cache_string(YYCC_U8(string_value)); \
|
||||
type_t cache; \
|
||||
ASSERT_TRUE(PARSE::try_parse<type_t>(cache_string, cache, ##__VA_ARGS__)); \
|
||||
EXPECT_EQ(cache, value); \
|
||||
EXPECT_EQ(PARSE::parse<type_t>(cache_string, ##__VA_ARGS__), value); \
|
||||
std::u8string cache_string(string_value); \
|
||||
auto rv = PARSE::parse<type_t>(cache_string __VA_OPT__(, ) __VA_ARGS__); \
|
||||
ASSERT_TRUE(rv.has_value()); \
|
||||
EXPECT_EQ(rv.value(), expected_value); \
|
||||
}
|
||||
|
||||
#define TEST_FAIL(type_t, string_value, ...) \
|
||||
{ \
|
||||
u8string cache_string(YYCC_U8(string_value)); \
|
||||
type_t cache; \
|
||||
EXPECT_FALSE(PARSE::try_parse<type_t>(cache_string, cache, ##__VA_ARGS__)); \
|
||||
EXPECT_ANY_THROW(PARSE::parse<type_t>(cache_string, ##__VA_ARGS__)); \
|
||||
std::u8string cache_string(string_value); \
|
||||
auto rv = PARSE::parse<type_t>(cache_string __VA_OPT__(, ) __VA_ARGS__); \
|
||||
EXPECT_FALSE(rv.has_value()); \
|
||||
}
|
||||
|
||||
#include "../../shared/parse_template.hpp"
|
||||
TEST(NumParse, Common) {
|
||||
TEST_SUCCESS(i8, INT8_C(-61), u8"-61");
|
||||
TEST_SUCCESS(u8, UINT8_C(200), u8"200");
|
||||
TEST_SUCCESS(i16, INT16_C(6161), u8"6161");
|
||||
TEST_SUCCESS(u16, UINT16_C(32800), u8"32800");
|
||||
TEST_SUCCESS(i32, INT32_C(61616161), u8"61616161");
|
||||
TEST_SUCCESS(u32, UINT32_C(4294967293), u8"4294967293");
|
||||
TEST_SUCCESS(i64, INT64_C(616161616161), u8"616161616161");
|
||||
TEST_SUCCESS(u64, UINT64_C(9223372036854775807), u8"9223372036854775807");
|
||||
|
||||
TEST_SUCCESS(float, 1.0f, u8"1.0");
|
||||
TEST_SUCCESS(double, 1.0, u8"1.0");
|
||||
|
||||
TEST_SUCCESS(bool, true, u8"true");
|
||||
TEST_SUCCESS(bool, false, u8"false");
|
||||
}
|
||||
|
||||
TEST(NumParse, Radix) {
|
||||
TEST_SUCCESS(u32, UINT32_C(0xffff), u8"ffff", 16);
|
||||
TEST_SUCCESS(u32, UINT32_C(032), u8"032", 8);
|
||||
TEST_SUCCESS(u32, UINT32_C(0B1011), u8"1011", 2);
|
||||
}
|
||||
|
||||
TEST(NumParse, CaseInsensitive) {
|
||||
TEST_SUCCESS(bool, true, u8"tRUE");
|
||||
}
|
||||
|
||||
TEST(NumParse, Overflow) {
|
||||
TEST_FAIL(i8, u8"6161");
|
||||
TEST_FAIL(u8, u8"32800");
|
||||
TEST_FAIL(i16, u8"61616161");
|
||||
TEST_FAIL(u16, u8"4294967293");
|
||||
TEST_FAIL(i32, u8"616161616161");
|
||||
TEST_FAIL(u32, u8"9223372036854775807");
|
||||
TEST_FAIL(i64, u8"616161616161616161616161");
|
||||
TEST_FAIL(u64, u8"92233720368547758079223372036854775807");
|
||||
|
||||
TEST_FAIL(float, u8"1e40");
|
||||
TEST_FAIL(double, u8"1e114514");
|
||||
}
|
||||
|
||||
TEST(NumParse, BadRadix) {
|
||||
TEST_FAIL(u32, u8"fghj", 16);
|
||||
TEST_FAIL(u32, u8"099", 8);
|
||||
TEST_FAIL(u32, u8"12345", 2);
|
||||
}
|
||||
|
||||
TEST(NumParse, InvalidWords) {
|
||||
TEST_FAIL(u32, u8"hello, world!");
|
||||
TEST_FAIL(bool, u8"hello, world!");
|
||||
}
|
||||
|
||||
} // namespace yycctest::num::parse
|
||||
|
@ -2,21 +2,40 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/num/stringify.hpp>
|
||||
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
|
||||
#define STRINGIFY ::yycc::num::stringify
|
||||
|
||||
namespace yycctest::num::stringify {
|
||||
|
||||
#define TEST_NS NumStringify
|
||||
|
||||
#define TEST_SUCCESS(type_t, value, string_value, ...) \
|
||||
{ \
|
||||
type_t cache = value; \
|
||||
u8string ret = STRINGIFY::stringify<type_t>(cache, ##__VA_ARGS__); \
|
||||
EXPECT_EQ(ret, YYCC_U8(string_value)); \
|
||||
std::u8string ret = STRINGIFY::stringify<type_t>(cache __VA_OPT__(, ) __VA_ARGS__); \
|
||||
EXPECT_EQ(ret, string_value); \
|
||||
}
|
||||
|
||||
#include "../../shared/stringify_template.hpp"
|
||||
TEST(NumStringify, Common) {
|
||||
TEST_SUCCESS(i8, INT8_C(-61), u8"-61");
|
||||
TEST_SUCCESS(u8, UINT8_C(200), u8"200");
|
||||
TEST_SUCCESS(i16, INT16_C(6161), u8"6161");
|
||||
TEST_SUCCESS(u16, UINT16_C(32800), u8"32800");
|
||||
TEST_SUCCESS(i32, INT32_C(61616161), u8"61616161");
|
||||
TEST_SUCCESS(u32, UINT32_C(4294967293), u8"4294967293");
|
||||
TEST_SUCCESS(i64, INT64_C(616161616161), u8"616161616161");
|
||||
TEST_SUCCESS(u64, UINT64_C(9223372036854775807), u8"9223372036854775807");
|
||||
|
||||
} // namespace yycctest::string::stringify
|
||||
TEST_SUCCESS(float, 1.0f, u8"1.0", std::chars_format::fixed, 1);
|
||||
TEST_SUCCESS(double, 1.0, u8"1.0", std::chars_format::fixed, 1);
|
||||
|
||||
TEST_SUCCESS(bool, true, u8"true");
|
||||
TEST_SUCCESS(bool, false, u8"false");
|
||||
}
|
||||
|
||||
TEST(NumStringify, Radix) {
|
||||
TEST_SUCCESS(u32, UINT32_C(0xffff), u8"ffff", 16);
|
||||
TEST_SUCCESS(u32, UINT32_C(032), u8"32", 8);
|
||||
TEST_SUCCESS(u32, UINT32_C(0B1011), u8"1011", 2);
|
||||
}
|
||||
|
||||
} // namespace yycctest::num::stringify
|
||||
|
@ -1,58 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/patch/contains.hpp>
|
||||
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
|
||||
#define FN_CONTAINS ::yycc::patch::contains::contains
|
||||
|
||||
namespace yycctest::patch::contains {
|
||||
|
||||
TEST(PatchContains, Contains) {
|
||||
// Set
|
||||
{
|
||||
std::set<u32> collection{
|
||||
UINT32_C(1),
|
||||
UINT32_C(3),
|
||||
UINT32_C(5),
|
||||
};
|
||||
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||
}
|
||||
// Unordered set
|
||||
{
|
||||
std::unordered_set<u32> collection{
|
||||
UINT32_C(1),
|
||||
UINT32_C(3),
|
||||
UINT32_C(5),
|
||||
};
|
||||
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||
}
|
||||
// Map
|
||||
{
|
||||
std::map<u32, u32> collection{
|
||||
{UINT32_C(1), UINT32_C(2)},
|
||||
{UINT32_C(3), UINT32_C(4)},
|
||||
{UINT32_C(5), UINT32_C(6)},
|
||||
};
|
||||
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||
}
|
||||
// Unordered Map
|
||||
{
|
||||
std::unordered_map<u32, u32> collection{
|
||||
{UINT32_C(1), UINT32_C(2)},
|
||||
{UINT32_C(3), UINT32_C(4)},
|
||||
{UINT32_C(5), UINT32_C(6)},
|
||||
};
|
||||
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace yycctest::patch::contains
|
@ -1,59 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/patch/starts_ends_with.hpp>
|
||||
|
||||
#define FN_STARTS_WITH ::yycc::patch::starts_ends_with::starts_with
|
||||
#define FN_ENDS_WITH ::yycc::patch::starts_ends_with::ends_with
|
||||
using namespace std::literals;
|
||||
|
||||
namespace yycctest::patch::starts_ends_with {
|
||||
|
||||
#define TEST_STARTS_WITH(prefix) \
|
||||
{ \
|
||||
const auto that = prefix##"Hello, C++20!"s; \
|
||||
EXPECT_TRUE(FN_STARTS_WITH(that, prefix##"He"sv)); \
|
||||
EXPECT_FALSE(FN_STARTS_WITH(that, prefix##"he"sv)); \
|
||||
EXPECT_TRUE(FN_STARTS_WITH(that, prefix##'H')); \
|
||||
EXPECT_FALSE(FN_STARTS_WITH(that, prefix##'h')); \
|
||||
EXPECT_TRUE(FN_STARTS_WITH(that, prefix##"He")); \
|
||||
EXPECT_FALSE(FN_STARTS_WITH(that, prefix##"he")); \
|
||||
}
|
||||
|
||||
TEST(PatchStartsEndsWith, StartsWith) {
|
||||
// Ordinary string
|
||||
TEST_STARTS_WITH();
|
||||
// Wide string
|
||||
TEST_STARTS_WITH(L);
|
||||
// UTF8 string
|
||||
TEST_STARTS_WITH(u8);
|
||||
// UTF-16 string
|
||||
TEST_STARTS_WITH(u);
|
||||
// UTF-32 string
|
||||
TEST_STARTS_WITH(U);
|
||||
}
|
||||
|
||||
#define TEST_ENDS_WITH(prefix) \
|
||||
{ \
|
||||
const auto that = prefix##"Hello, C++20!"s; \
|
||||
EXPECT_TRUE(FN_ENDS_WITH(that, prefix##"C++20!"sv)); \
|
||||
EXPECT_FALSE(FN_ENDS_WITH(that, prefix##"c++20!"sv)); \
|
||||
EXPECT_TRUE(FN_ENDS_WITH(that, prefix##'!')); \
|
||||
EXPECT_FALSE(FN_ENDS_WITH(that, prefix##'?')); \
|
||||
EXPECT_TRUE(FN_ENDS_WITH(that, prefix##"C++20!")); \
|
||||
EXPECT_FALSE(FN_ENDS_WITH(that, prefix##"c++20!")); \
|
||||
}
|
||||
|
||||
TEST(PatchStartsEndsWith, EndsWith) {
|
||||
// Ordinary string
|
||||
TEST_ENDS_WITH();
|
||||
// Wide string
|
||||
TEST_ENDS_WITH(L);
|
||||
// UTF8 string
|
||||
TEST_ENDS_WITH(u8);
|
||||
// UTF-16 string
|
||||
TEST_ENDS_WITH(u);
|
||||
// UTF-32 string
|
||||
TEST_ENDS_WITH(U);
|
||||
}
|
||||
|
||||
} // namespace yycctest::patch::starts_ends_with
|
@ -1,35 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/rust/num/parse.hpp>
|
||||
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
|
||||
#define PARSE ::yycc::rust::num::parse
|
||||
|
||||
namespace yycctest::rust::num::parse {
|
||||
|
||||
// We only want to test it if C++ support it.
|
||||
#if defined(YYCC_CPPFEAT_EXPECTED)
|
||||
|
||||
#define TEST_NS RustNumParse
|
||||
|
||||
#define TEST_SUCCESS(type_t, expected_value, string_value, ...) \
|
||||
{ \
|
||||
u8string cache_string(YYCC_U8(string_value)); \
|
||||
auto rv = PARSE::parse<type_t>(cache_string, ##__VA_ARGS__); \
|
||||
ASSERT_TRUE(rv.has_value()); \
|
||||
EXPECT_EQ(rv.value(), expected_value); \
|
||||
}
|
||||
|
||||
#define TEST_FAIL(type_t, string_value, ...) \
|
||||
{ \
|
||||
u8string cache_string(YYCC_U8(string_value)); \
|
||||
auto rv = PARSE::parse<type_t>(cache_string, ##__VA_ARGS__); \
|
||||
EXPECT_FALSE(rv.has_value()); \
|
||||
}
|
||||
|
||||
#include "../../../shared/parse_template.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace yycctest::rust::parse
|
@ -1,22 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/rust/num/stringify.hpp>
|
||||
|
||||
#include <yycc/prelude/rust.hpp>
|
||||
|
||||
#define STRINGIFY ::yycc::rust::num::stringify
|
||||
|
||||
namespace yycctest::rust::num::stringify {
|
||||
|
||||
#define TEST_NS RustNumStringify
|
||||
|
||||
#define TEST_SUCCESS(type_t, value, string_value, ...) \
|
||||
{ \
|
||||
type_t cache = value; \
|
||||
u8string ret = STRINGIFY::stringify<type_t>(cache, ##__VA_ARGS__); \
|
||||
EXPECT_EQ(ret, YYCC_U8(string_value)); \
|
||||
}
|
||||
|
||||
#include "../../../shared/stringify_template.hpp"
|
||||
|
||||
}
|
@ -2,91 +2,92 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/string/op.hpp>
|
||||
|
||||
#include <yycc/prelude/core.hpp>
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
|
||||
#define OP ::yycc::string::op
|
||||
using namespace std::literals::string_view_literals;
|
||||
|
||||
namespace yycctest::string::op {
|
||||
|
||||
TEST(StringOp, Printf) {
|
||||
auto rv = OP::printf(YYCC_U8("%s == %s"), YYCC_U8("Hello World"), YYCC_U8("Hello, world"));
|
||||
EXPECT_EQ(rv, YYCC_U8("Hello World == Hello, world"));
|
||||
auto rv = OP::printf(u8"%s == %s", u8"Hello World", u8"Hello, world");
|
||||
EXPECT_EQ(rv, u8"Hello World == Hello, world");
|
||||
}
|
||||
|
||||
TEST(StringOp, Replace) {
|
||||
// Normal case
|
||||
{
|
||||
auto rv = OP::replace(YYCC_U8("aabbcc"), YYCC_U8("bb"), YYCC_U8("dd"));
|
||||
EXPECT_EQ(rv, YYCC_U8("aaddcc"));
|
||||
auto rv = OP::replace(u8"aabbcc", u8"bb", u8"dd");
|
||||
EXPECT_EQ(rv, u8"aaddcc");
|
||||
}
|
||||
// No matched expected string
|
||||
{
|
||||
auto rv = OP::replace(YYCC_U8("aabbcc"), YYCC_U8("zz"), YYCC_U8("yy"));
|
||||
EXPECT_EQ(rv, YYCC_U8("aabbcc"));
|
||||
auto rv = OP::replace(u8"aabbcc", u8"zz", u8"yy");
|
||||
EXPECT_EQ(rv, u8"aabbcc");
|
||||
}
|
||||
// Empty expected string
|
||||
{
|
||||
auto rv = OP::replace(YYCC_U8("aabbcc"), u8string_view(), YYCC_U8("zz"));
|
||||
EXPECT_EQ(rv, YYCC_U8("aabbcc"));
|
||||
auto rv = OP::replace(u8"aabbcc", std::u8string_view(), u8"zz");
|
||||
EXPECT_EQ(rv, u8"aabbcc");
|
||||
}
|
||||
// Empty replace string
|
||||
{
|
||||
auto rv = OP::replace(YYCC_U8("aaaabbaa"), YYCC_U8("aa"), YYCC_U8(""));
|
||||
EXPECT_EQ(rv, YYCC_U8("bb"));
|
||||
auto rv = OP::replace(u8"aaaabbaa", u8"aa", u8"");
|
||||
EXPECT_EQ(rv, u8"bb");
|
||||
}
|
||||
// Nested replacing
|
||||
{
|
||||
auto rv = OP::replace(YYCC_U8("aaxcc"), YYCC_U8("x"), YYCC_U8("yx"));
|
||||
EXPECT_EQ(rv, YYCC_U8("aayxcc"));
|
||||
auto rv = OP::replace(u8"aaxcc", u8"x", u8"yx");
|
||||
EXPECT_EQ(rv, u8"aayxcc");
|
||||
}
|
||||
// Empty source string
|
||||
{
|
||||
auto rv = OP::replace(u8string_view(), YYCC_U8(""), YYCC_U8("xy"));
|
||||
EXPECT_EQ(rv, YYCC_U8(""));
|
||||
auto rv = OP::replace(std::u8string_view(), u8"", u8"xy");
|
||||
EXPECT_EQ(rv, u8"");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringOp, Lower) {
|
||||
auto rv = OP::to_lower(YYCC_U8("LOWER"));
|
||||
EXPECT_EQ(rv, YYCC_U8("lower"));
|
||||
auto rv = OP::to_lower(u8"LOWER");
|
||||
EXPECT_EQ(rv, u8"lower");
|
||||
}
|
||||
|
||||
TEST(StringOp, Upper) {
|
||||
auto rv = OP::to_upper(YYCC_U8("upper"));
|
||||
EXPECT_EQ(rv, YYCC_U8("UPPER"));
|
||||
auto rv = OP::to_upper(u8"upper");
|
||||
EXPECT_EQ(rv, u8"UPPER");
|
||||
}
|
||||
|
||||
TEST(StringOp, Join) {
|
||||
std::vector<u8string> datas{YYCC_U8(""), YYCC_U8("1"), YYCC_U8("2"), YYCC_U8("")};
|
||||
auto rv = OP::join(datas.begin(), datas.end(), YYCC_U8(", "));
|
||||
EXPECT_EQ(rv, YYCC_U8(", 1, 2, "));
|
||||
std::vector<std::u8string_view> datas{u8""sv, u8"1"sv, u8"2"sv, u8""sv};
|
||||
auto rv = OP::join(datas.begin(), datas.end(), u8", ");
|
||||
EXPECT_EQ(rv, u8", 1, 2, ");
|
||||
}
|
||||
|
||||
TEST(StringOp, Split) {
|
||||
// Normal
|
||||
{
|
||||
auto rv = OP::split(YYCC_U8(", 1, 2, "), YYCC_U8(", "));
|
||||
auto rv = OP::split(u8", 1, 2, ", u8", ");
|
||||
ASSERT_EQ(rv.size(), 4u);
|
||||
EXPECT_EQ(rv[0], YYCC_U8(""));
|
||||
EXPECT_EQ(rv[1], YYCC_U8("1"));
|
||||
EXPECT_EQ(rv[2], YYCC_U8("2"));
|
||||
EXPECT_EQ(rv[3], YYCC_U8(""));
|
||||
EXPECT_EQ(rv[0], u8"");
|
||||
EXPECT_EQ(rv[1], u8"1");
|
||||
EXPECT_EQ(rv[2], u8"2");
|
||||
EXPECT_EQ(rv[3], u8"");
|
||||
}
|
||||
// No matched delimiter
|
||||
{
|
||||
auto rv = OP::split(YYCC_U8("test"), YYCC_U8("-"));
|
||||
auto rv = OP::split(u8"test", u8"-");
|
||||
ASSERT_EQ(rv.size(), 1u);
|
||||
EXPECT_EQ(rv[0], YYCC_U8("test"));
|
||||
EXPECT_EQ(rv[0], u8"test");
|
||||
}
|
||||
// Empty delimiter
|
||||
{
|
||||
auto rv = OP::split(YYCC_U8("test"), u8string_view());
|
||||
auto rv = OP::split(u8"test", std::u8string_view());
|
||||
ASSERT_EQ(rv.size(), 1u);
|
||||
EXPECT_EQ(rv[0], YYCC_U8("test"));
|
||||
EXPECT_EQ(rv[0], u8"test");
|
||||
}
|
||||
// Empty source string
|
||||
{
|
||||
auto rv = OP::split(u8string_view(), YYCC_U8(""));
|
||||
auto rv = OP::split(std::u8string_view(), u8"");
|
||||
ASSERT_EQ(rv.size(), 1u);
|
||||
EXPECT_TRUE(rv[0].empty());
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/string/reinterpret.hpp>
|
||||
|
||||
#include <yycc/prelude/core.hpp>
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
|
||||
#define REINTERPRET ::yycc::string::reinterpret
|
||||
#define CONST_VOID_PTR(p) reinterpret_cast<const void*>(p)
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
namespace yycctest::string::reinterpret {
|
||||
|
||||
static u8string PROBE(YYCC_U8("Test"));
|
||||
static std::u8string PROBE(u8"Test");
|
||||
|
||||
TEST(StringReinterpret, ConstPointer) {
|
||||
const auto* src = PROBE.data();
|
||||
@ -34,7 +34,7 @@ namespace yycctest::string::reinterpret {
|
||||
}
|
||||
|
||||
TEST(StringReinterpret, String) {
|
||||
auto src = u8string(PROBE);
|
||||
auto src = std::u8string(PROBE);
|
||||
auto dst = REINTERPRET::as_ordinary(src);
|
||||
auto new_src = REINTERPRET::as_utf8(dst);
|
||||
|
||||
@ -46,7 +46,7 @@ namespace yycctest::string::reinterpret {
|
||||
}
|
||||
|
||||
TEST(StringReinterpret, StringView) {
|
||||
auto src = u8string_view(PROBE);
|
||||
auto src = std::u8string_view(PROBE);
|
||||
auto dst = REINTERPRET::as_ordinary_view(src);
|
||||
auto new_src = REINTERPRET::as_utf8_view(dst);
|
||||
|
||||
|
Reference in New Issue
Block a user