diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-09-17 01:14:17 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-09-18 02:57:56 +0000 |
commit | b8c756a53a181ab386808169be4c674b1e42c0ca (patch) | |
tree | 68d5acf3eae2ac46ee8037ae7cabac284e107449 /Tests | |
parent | 8043fcd4665e019f30b9b26eb141120fe8d815f8 (diff) | |
download | serenity-b8c756a53a181ab386808169be4c674b1e42c0ca.zip |
LibC: Primitively implement wcscoll
At the moment, sorting like LC_COLLATE=C would do is better than
nothing.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibC/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/LibC/TestWchar.cpp | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/Tests/LibC/CMakeLists.txt b/Tests/LibC/CMakeLists.txt index ca4570358d..c309b233a3 100644 --- a/Tests/LibC/CMakeLists.txt +++ b/Tests/LibC/CMakeLists.txt @@ -15,6 +15,7 @@ set(TEST_SOURCES TestStackSmash.cpp TestStrlcpy.cpp TestStrtodAccuracy.cpp + TestWchar.cpp TestWctype.cpp ) diff --git a/Tests/LibC/TestWchar.cpp b/Tests/LibC/TestWchar.cpp new file mode 100644 index 0000000000..d4e84725d3 --- /dev/null +++ b/Tests/LibC/TestWchar.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021, the SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibTest/TestCase.h> + +#include <wchar.h> + +TEST_CASE(wcscoll) +{ + // Check if wcscoll is sorting correctly. At the moment we are doing raw char comparisons, + // so it's digits, then uppercase letters, then lowercase letters. + + // Equalness between equal strings. + EXPECT(wcscoll(L"", L"") == 0); + EXPECT(wcscoll(L"0", L"0") == 0); + + // Shorter strings before longer strings. + EXPECT(wcscoll(L"", L"0") < 0); + EXPECT(wcscoll(L"0", L"") > 0); + EXPECT(wcscoll(L"123", L"1234") < 0); + EXPECT(wcscoll(L"1234", L"123") > 0); + + // Order within digits. + EXPECT(wcscoll(L"0", L"9") < 0); + EXPECT(wcscoll(L"9", L"0") > 0); + + // Digits before uppercase letters. + EXPECT(wcscoll(L"9", L"A") < 0); + EXPECT(wcscoll(L"A", L"9") > 0); + + // Order within uppercase letters. + EXPECT(wcscoll(L"A", L"Z") < 0); + EXPECT(wcscoll(L"Z", L"A") > 0); + + // Uppercase letters before lowercase letters. + EXPECT(wcscoll(L"Z", L"a") < 0); + EXPECT(wcscoll(L"a", L"Z") > 0); + + // Uppercase letters before lowercase letters. + EXPECT(wcscoll(L"a", L"z") < 0); + EXPECT(wcscoll(L"z", L"a") > 0); +} |