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