|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
| 9 | +#include "hdr/types/wchar_t.h" |
9 | 10 | #include "src/stdio/printf_core/converter.h" |
10 | 11 | #include "src/stdio/printf_core/core_structs.h" |
11 | 12 | #include "src/stdio/printf_core/writer.h" |
12 | | - |
13 | 13 | #include "test/UnitTest/Test.h" |
14 | 14 |
|
15 | 15 | class LlvmLibcPrintfConverterTest : public LIBC_NAMESPACE::testing::Test { |
@@ -255,3 +255,56 @@ TEST_F(LlvmLibcPrintfConverterTest, OctConversion) { |
255 | 255 | ASSERT_STREQ(str, "1234"); |
256 | 256 | ASSERT_EQ(writer.get_chars_written(), size_t{4}); |
257 | 257 | } |
| 258 | + |
| 259 | +TEST_F(LlvmLibcPrintfConverterTest, WideCharConversion) { |
| 260 | + |
| 261 | + LIBC_NAMESPACE::printf_core::FormatSection section; |
| 262 | + section.has_conv = true; |
| 263 | + section.raw_string = "%c"; |
| 264 | + section.conv_name = 'c'; |
| 265 | + section.length_modifier = LIBC_NAMESPACE::printf_core::LengthModifier::l; |
| 266 | + section.conv_val_raw = static_cast<wchar_t>(L'S'); |
| 267 | + |
| 268 | + LIBC_NAMESPACE::printf_core::convert(&writer, section); |
| 269 | + |
| 270 | + wb.buff[wb.buff_cur] = '\0'; |
| 271 | + |
| 272 | + ASSERT_STREQ(str, "S"); |
| 273 | + ASSERT_EQ(writer.get_chars_written(), size_t{1}); |
| 274 | +} |
| 275 | + |
| 276 | +TEST_F(LlvmLibcPrintfConverterTest, WideCharConversionLeftJustified) { |
| 277 | + LIBC_NAMESPACE::printf_core::FormatSection left_justified_conv; |
| 278 | + left_justified_conv.has_conv = true; |
| 279 | + left_justified_conv.raw_string = "%-4c"; |
| 280 | + left_justified_conv.conv_name = 'c'; |
| 281 | + left_justified_conv.length_modifier = |
| 282 | + LIBC_NAMESPACE::printf_core::LengthModifier::l; |
| 283 | + left_justified_conv.flags = |
| 284 | + LIBC_NAMESPACE::printf_core::FormatFlags::LEFT_JUSTIFIED; |
| 285 | + left_justified_conv.min_width = 4; |
| 286 | + left_justified_conv.conv_val_raw = static_cast<wchar_t>(L'S'); |
| 287 | + |
| 288 | + LIBC_NAMESPACE::printf_core::convert(&writer, left_justified_conv); |
| 289 | + wb.buff[wb.buff_cur] = '\0'; |
| 290 | + |
| 291 | + ASSERT_STREQ(str, "S "); |
| 292 | + ASSERT_EQ(writer.get_chars_written(), size_t{4}); |
| 293 | +} |
| 294 | + |
| 295 | +TEST_F(LlvmLibcPrintfConverterTest, WideCharConversionRightJustified) { |
| 296 | + LIBC_NAMESPACE::printf_core::FormatSection right_justified_conv; |
| 297 | + right_justified_conv.has_conv = true; |
| 298 | + right_justified_conv.raw_string = "%4c"; |
| 299 | + right_justified_conv.conv_name = 'c'; |
| 300 | + right_justified_conv.length_modifier = |
| 301 | + LIBC_NAMESPACE::printf_core::LengthModifier::l; |
| 302 | + right_justified_conv.min_width = 4; |
| 303 | + right_justified_conv.conv_val_raw = static_cast<wchar_t>(L'S'); |
| 304 | + |
| 305 | + LIBC_NAMESPACE::printf_core::convert(&writer, right_justified_conv); |
| 306 | + wb.buff[wb.buff_cur] = '\0'; |
| 307 | + |
| 308 | + ASSERT_STREQ(str, " S"); |
| 309 | + ASSERT_EQ(writer.get_chars_written(), size_t{4}); |
| 310 | +} |
0 commit comments