KI18n

isocodes.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
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(QLatin1Char('a')) == 'A');
13 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('A')) == 11);
14 static_assert(IsoCodes::mapToAlphaNumKey('A') == IsoCodes::mapToAlphaNumKey('a'));
15 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('z')) < IsoCodes::AlphaNumKeyFactor);
16 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('0')) == 1);
17 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('9')) == 10);
18 static_assert(IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor < std::numeric_limits<uint16_t>::max());
19 
20 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('0')) == '0');
21 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('9')) == '9');
22 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('a')) == 'A');
23 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('Z')) == 'Z');
24 
25 static_assert(IsoCodes::alpha2CodeToKey("AZ") == 0x415a);
26 static_assert(IsoCodes::alpha2CodeToKey("az") == 0x415a);
27 static_assert(IsoCodes::alpha2CodeToKey("Az") == 0x415a);
28 static_assert(IsoCodes::alpha2CodeToKey("ZA") == 0x5a41);
29 static_assert(IsoCodes::alpha2CodeToKey("NZ") == IsoCodes::alpha2CodeToKey(u"NZ"));
30 
31 static_assert(IsoCodes::alpha2CodeToKey("") == 0);
32 static_assert(IsoCodes::alpha2CodeToKey("12") == 0);
33 static_assert(IsoCodes::alpha2CodeToKey("A") == 0);
34 static_assert(IsoCodes::alpha2CodeToKey("ABC") == 0);
35 static_assert(IsoCodes::alpha2CodeToKey("[email protected]") == 0);
36 
37 static_assert(IsoCodes::alpha2CodeToKey("AA") < IsoCodes::alpha2CodeToKey("AB"));
38 static_assert(IsoCodes::alpha2CodeToKey("AZ") < IsoCodes::alpha2CodeToKey("BA"));
39 
40 static_assert(IsoCodes::alpha3CodeToKey("ZZZ") < std::numeric_limits<uint16_t>::max());
41 static_assert(IsoCodes::alpha3CodeToKey("AAA") > 0);
42 static_assert(IsoCodes::alpha3CodeToKey("AAA") < IsoCodes::alpha3CodeToKey("AAB"));
43 static_assert(IsoCodes::alpha3CodeToKey("AAB") < IsoCodes::alpha3CodeToKey("BAA"));
44 static_assert(IsoCodes::alpha3CodeToKey("NZL") == IsoCodes::alpha3CodeToKey(u"NZL"));
45 
46 static_assert(IsoCodes::alpha3CodeToKey("") == 0);
47 static_assert(IsoCodes::alpha3CodeToKey("AA") == 0);
48 static_assert(IsoCodes::alpha3CodeToKey("ABCD") == 0);
49 static_assert(IsoCodes::alpha3CodeToKey("AB1") == 0);
50 static_assert(IsoCodes::alpha3CodeToKey("[email protected]") == 0);
51 
52 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") > 0);
53 static_assert(IsoCodes::subdivisionCodeToKey("ZZ-ZZZ") > 0);
54 static_assert(IsoCodes::subdivisionCodeToKey("ZZ-999") < std::numeric_limits<uint32_t>::max());
55 static_assert(IsoCodes::subdivisionCodeToKey("AA-A") < IsoCodes::subdivisionCodeToKey("AA-AA"));
56 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") < IsoCodes::subdivisionCodeToKey("AA-AAB"));
57 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") < IsoCodes::subdivisionCodeToKey("AA-AB"));
58 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAB") < IsoCodes::subdivisionCodeToKey("AA-BAA"));
59 static_assert(IsoCodes::subdivisionCodeToKey("AA-AA1") < IsoCodes::subdivisionCodeToKey("AA-AAZ"));
60 static_assert(IsoCodes::subdivisionCodeToKey("FR-99") < IsoCodes::subdivisionCodeToKey("FR-RE"));
61 static_assert(IsoCodes::subdivisionCodeToKey("AB-cd1") == IsoCodes::subdivisionCodeToKey("AB-CD1"));
62 
63 static_assert(IsoCodes::subdivisionCodeToKey("") == 0);
64 static_assert(IsoCodes::subdivisionCodeToKey("AA-") == 0);
65 static_assert(IsoCodes::subdivisionCodeToKey("12-ABC") == 0);
66 static_assert(IsoCodes::subdivisionCodeToKey("[email protected]") == 0);
67 static_assert(IsoCodes::subdivisionCodeToKey("AB") == 0);
68 static_assert(IsoCodes::subdivisionCodeToKey("ABC") == 0);
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:07:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.