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(c: QLatin1Char('a')) == 'A');
13static_assert(IsoCodes::mapToAlphaNumKey(c: QLatin1Char('A')) == 11);
14static_assert(IsoCodes::mapToAlphaNumKey(c: 'A') == IsoCodes::mapToAlphaNumKey(c: 'a'));
15static_assert(IsoCodes::mapToAlphaNumKey(c: QLatin1Char('z')) < IsoCodes::AlphaNumKeyFactor);
16static_assert(IsoCodes::mapToAlphaNumKey(c: QLatin1Char('0')) == 1);
17static_assert(IsoCodes::mapToAlphaNumKey(c: QLatin1Char('9')) == 10);
18static_assert(IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor < std::numeric_limits<uint16_t>::max());
19
20static_assert(IsoCodes::mapFromAlphaNumKey(key: IsoCodes::mapToAlphaNumKey(c: '0')) == '0');
21static_assert(IsoCodes::mapFromAlphaNumKey(key: IsoCodes::mapToAlphaNumKey(c: '9')) == '9');
22static_assert(IsoCodes::mapFromAlphaNumKey(key: IsoCodes::mapToAlphaNumKey(c: 'a')) == 'A');
23static_assert(IsoCodes::mapFromAlphaNumKey(key: IsoCodes::mapToAlphaNumKey(c: 'Z')) == 'Z');
24
25static_assert(IsoCodes::alpha2CodeToKey(code: "AZ") == 0x415a);
26static_assert(IsoCodes::alpha2CodeToKey(code: "az") == 0x415a);
27static_assert(IsoCodes::alpha2CodeToKey(code: "Az") == 0x415a);
28static_assert(IsoCodes::alpha2CodeToKey(code: "ZA") == 0x5a41);
29static_assert(IsoCodes::alpha2CodeToKey(code: "NZ") == IsoCodes::alpha2CodeToKey(code: u"NZ"));
30
31static_assert(IsoCodes::alpha2CodeToKey(code: "") == 0);
32static_assert(IsoCodes::alpha2CodeToKey(code: "12") == 0);
33static_assert(IsoCodes::alpha2CodeToKey(code: "A") == 0);
34static_assert(IsoCodes::alpha2CodeToKey(code: "ABC") == 0);
35static_assert(IsoCodes::alpha2CodeToKey(code: "A@") == 0);
36
37static_assert(IsoCodes::alpha2CodeToKey(code: "AA") < IsoCodes::alpha2CodeToKey(code: "AB"));
38static_assert(IsoCodes::alpha2CodeToKey(code: "AZ") < IsoCodes::alpha2CodeToKey(code: "BA"));
39
40static_assert(IsoCodes::alpha3CodeToKey(code: "ZZZ") < std::numeric_limits<uint16_t>::max());
41static_assert(IsoCodes::alpha3CodeToKey(code: "AAA") > 0);
42static_assert(IsoCodes::alpha3CodeToKey(code: "AAA") < IsoCodes::alpha3CodeToKey(code: "AAB"));
43static_assert(IsoCodes::alpha3CodeToKey(code: "AAB") < IsoCodes::alpha3CodeToKey(code: "BAA"));
44static_assert(IsoCodes::alpha3CodeToKey(code: "NZL") == IsoCodes::alpha3CodeToKey(code: u"NZL"));
45
46static_assert(IsoCodes::alpha3CodeToKey(code: "") == 0);
47static_assert(IsoCodes::alpha3CodeToKey(code: "AA") == 0);
48static_assert(IsoCodes::alpha3CodeToKey(code: "ABCD") == 0);
49static_assert(IsoCodes::alpha3CodeToKey(code: "AB1") == 0);
50static_assert(IsoCodes::alpha3CodeToKey(code: "A@C") == 0);
51
52static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-AAA") > 0);
53static_assert(IsoCodes::subdivisionCodeToKey(code: "ZZ-ZZZ") > 0);
54static_assert(IsoCodes::subdivisionCodeToKey(code: "ZZ-999") < std::numeric_limits<uint32_t>::max());
55static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-A") < IsoCodes::subdivisionCodeToKey(code: "AA-AA"));
56static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-AAA") < IsoCodes::subdivisionCodeToKey(code: "AA-AAB"));
57static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-AAA") < IsoCodes::subdivisionCodeToKey(code: "AA-AB"));
58static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-AAB") < IsoCodes::subdivisionCodeToKey(code: "AA-BAA"));
59static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-AA1") < IsoCodes::subdivisionCodeToKey(code: "AA-AAZ"));
60static_assert(IsoCodes::subdivisionCodeToKey(code: "FR-99") < IsoCodes::subdivisionCodeToKey(code: "FR-RE"));
61static_assert(IsoCodes::subdivisionCodeToKey(code: "AB-cd1") == IsoCodes::subdivisionCodeToKey(code: "AB-CD1"));
62
63static_assert(IsoCodes::subdivisionCodeToKey(code: "") == 0);
64static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-") == 0);
65static_assert(IsoCodes::subdivisionCodeToKey(code: "12-ABC") == 0);
66static_assert(IsoCodes::subdivisionCodeToKey(code: "AA-@") == 0);
67static_assert(IsoCodes::subdivisionCodeToKey(code: "AB") == 0);
68static_assert(IsoCodes::subdivisionCodeToKey(code: "ABC") == 0);
69

source code of ki18n/src/localedata/isocodes.cpp