KI18n

isocodes.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "isocodes_p.h"
8
9#include <limits>
10
11// "unit tests" for the low-level encoding functions
12static_assert(IsoCodes::mapToUpper(QLatin1Char('a')) == 'A');
13static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('A')) == 11);
14static_assert(IsoCodes::mapToAlphaNumKey('A') == IsoCodes::mapToAlphaNumKey('a'));
15static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('z')) < IsoCodes::AlphaNumKeyFactor);
16static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('0')) == 1);
17static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('9')) == 10);
18static_assert(IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor < std::numeric_limits<uint16_t>::max());
19
20static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('0')) == '0');
21static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('9')) == '9');
22static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('a')) == 'A');
23static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('Z')) == 'Z');
24
25static_assert(IsoCodes::alpha2CodeToKey("AZ") == 0x415a);
26static_assert(IsoCodes::alpha2CodeToKey("az") == 0x415a);
27static_assert(IsoCodes::alpha2CodeToKey("Az") == 0x415a);
28static_assert(IsoCodes::alpha2CodeToKey("ZA") == 0x5a41);
29static_assert(IsoCodes::alpha2CodeToKey("NZ") == IsoCodes::alpha2CodeToKey(u"NZ"));
30
31static_assert(IsoCodes::alpha2CodeToKey("") == 0);
32static_assert(IsoCodes::alpha2CodeToKey("12") == 0);
33static_assert(IsoCodes::alpha2CodeToKey("A") == 0);
34static_assert(IsoCodes::alpha2CodeToKey("ABC") == 0);
35static_assert(IsoCodes::alpha2CodeToKey("A@") == 0);
36
37static_assert(IsoCodes::alpha2CodeToKey("AA") < IsoCodes::alpha2CodeToKey("AB"));
38static_assert(IsoCodes::alpha2CodeToKey("AZ") < IsoCodes::alpha2CodeToKey("BA"));
39
40static_assert(IsoCodes::alpha3CodeToKey("ZZZ") < std::numeric_limits<uint16_t>::max());
41static_assert(IsoCodes::alpha3CodeToKey("AAA") > 0);
42static_assert(IsoCodes::alpha3CodeToKey("AAA") < IsoCodes::alpha3CodeToKey("AAB"));
43static_assert(IsoCodes::alpha3CodeToKey("AAB") < IsoCodes::alpha3CodeToKey("BAA"));
44static_assert(IsoCodes::alpha3CodeToKey("NZL") == IsoCodes::alpha3CodeToKey(u"NZL"));
45
46static_assert(IsoCodes::alpha3CodeToKey("") == 0);
47static_assert(IsoCodes::alpha3CodeToKey("AA") == 0);
48static_assert(IsoCodes::alpha3CodeToKey("ABCD") == 0);
49static_assert(IsoCodes::alpha3CodeToKey("AB1") == 0);
50static_assert(IsoCodes::alpha3CodeToKey("A@C") == 0);
51
52static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") > 0);
53static_assert(IsoCodes::subdivisionCodeToKey("ZZ-ZZZ") > 0);
54static_assert(IsoCodes::subdivisionCodeToKey("ZZ-999") < std::numeric_limits<uint32_t>::max());
55static_assert(IsoCodes::subdivisionCodeToKey("AA-A") < IsoCodes::subdivisionCodeToKey("AA-AA"));
56static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") < IsoCodes::subdivisionCodeToKey("AA-AAB"));
57static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") < IsoCodes::subdivisionCodeToKey("AA-AB"));
58static_assert(IsoCodes::subdivisionCodeToKey("AA-AAB") < IsoCodes::subdivisionCodeToKey("AA-BAA"));
59static_assert(IsoCodes::subdivisionCodeToKey("AA-AA1") < IsoCodes::subdivisionCodeToKey("AA-AAZ"));
60static_assert(IsoCodes::subdivisionCodeToKey("FR-99") < IsoCodes::subdivisionCodeToKey("FR-RE"));
61static_assert(IsoCodes::subdivisionCodeToKey("AB-cd1") == IsoCodes::subdivisionCodeToKey("AB-CD1"));
62
63static_assert(IsoCodes::subdivisionCodeToKey("") == 0);
64static_assert(IsoCodes::subdivisionCodeToKey("AA-") == 0);
65static_assert(IsoCodes::subdivisionCodeToKey("12-ABC") == 0);
66static_assert(IsoCodes::subdivisionCodeToKey("AA-@") == 0);
67static_assert(IsoCodes::subdivisionCodeToKey("AB") == 0);
68static_assert(IsoCodes::subdivisionCodeToKey("ABC") == 0);
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.