fix: change the behavior of printf in string op.
- add compiler hint for checking the arguments of printf. - change the return value of printf. from std::expected to normal value. use C++ exception to indicate error. * the error of printf usually caused by programmer. so it can be found when testing program. * so i use std::logic_error to indicate this and programmer should fix this before releasing program. - change the use of encoding convertion. for those cases that convertion must be safe, we unwrap it directly.
This commit is contained in:
0
testbench/yycc/carton/clap.cpp
Normal file
0
testbench/yycc/carton/clap.cpp
Normal file
@ -10,12 +10,11 @@ namespace yycctest::patch::ptr_pad {
|
||||
|
||||
TEST(PatchPtrPad, Normal) {
|
||||
auto rv = OP::printf(u8"0x%" PRIXPTR_LPAD PRIXPTR, nullptr);
|
||||
EXPECT_TRUE(rv.has_value());
|
||||
|
||||
#if defined(YYCC_PTRSIZE_32)
|
||||
EXPECT_EQ(rv.value(), u8"0x00000000");
|
||||
EXPECT_EQ(rv, u8"0x00000000");
|
||||
#else
|
||||
EXPECT_EQ(rv.value(), u8"0x0000000000000000");
|
||||
EXPECT_EQ(rv, u8"0x0000000000000000");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,16 @@ using namespace std::literals::string_view_literals;
|
||||
namespace yycctest::string::op {
|
||||
|
||||
TEST(StringOp, Printf) {
|
||||
auto rv = OP::printf(u8"%s == %s", u8"Hello World", u8"Hello, world");
|
||||
EXPECT_EQ(rv, u8"Hello World == Hello, world");
|
||||
// UTF8 string
|
||||
{
|
||||
auto rv = OP::printf(u8"%s == %s", u8"Hello World", u8"Hello, world");
|
||||
EXPECT_EQ(rv, u8"Hello World == Hello, world");
|
||||
}
|
||||
// Ordinary string
|
||||
{
|
||||
auto rv = OP::printf("%s == %s", "Hello World", "Hello, world");
|
||||
EXPECT_EQ(rv, "Hello World == Hello, world");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringOp, Replace) {
|
||||
|
Reference in New Issue
Block a user