mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
AK: Allow printing wide characters using %ls modifier
This commit is contained in:
parent
824cf570d3
commit
704e1d13f4
4 changed files with 84 additions and 2 deletions
58
Tests/AK/TestPrint.cpp
Normal file
58
Tests/AK/TestPrint.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <wchar.h>
|
||||
|
||||
TEST_CASE(swprint_no_format)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
size_t len = swprintf(buffer, 64, L"Well, hello friends!");
|
||||
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
|
||||
VERIFY(wcslen(buffer) == len);
|
||||
}
|
||||
|
||||
TEST_CASE(swprint_single_wchar_argument)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
size_t len = swprintf(buffer, 64, L"Well, %ls friends!", L"hello");
|
||||
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
|
||||
VERIFY(wcslen(buffer) == len);
|
||||
}
|
||||
|
||||
TEST_CASE(swprint_single_char_argument)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
size_t len = swprintf(buffer, 64, L"Well, %s friends!", "hello");
|
||||
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
|
||||
VERIFY(wcslen(buffer) == len);
|
||||
}
|
||||
|
||||
TEST_CASE(swprint_single_narrow_char_argument)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
size_t len = swprintf(buffer, 64, L"Well, %hs friends!", "hello");
|
||||
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends!") == 0);
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends") != 0);
|
||||
VERIFY(wcslen(buffer) == len);
|
||||
}
|
||||
|
||||
TEST_CASE(swprint_mixed_arguments)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
size_t len = swprintf(buffer, 64, L"Well, %ls friends! %hs is less then %s.", L"hello", "10", "20");
|
||||
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends! 10 is less then 20.") == 0);
|
||||
VERIFY(wcscmp(buffer, L"Well, hello friends! 10 is less then 2.") != 0);
|
||||
VERIFY(wcslen(buffer) == len);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue