File indexing completed on 2024-04-14 03:52:20
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "isocodes_p.h" 0008 0009 #include <limits> 0010 0011 // "unit tests" for the low-level encoding functions 0012 static_assert(IsoCodes::mapToUpper(QLatin1Char('a')) == 'A'); 0013 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('A')) == 11); 0014 static_assert(IsoCodes::mapToAlphaNumKey('A') == IsoCodes::mapToAlphaNumKey('a')); 0015 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('z')) < IsoCodes::AlphaNumKeyFactor); 0016 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('0')) == 1); 0017 static_assert(IsoCodes::mapToAlphaNumKey(QLatin1Char('9')) == 10); 0018 static_assert(IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor * IsoCodes::AlphaNumKeyFactor < std::numeric_limits<uint16_t>::max()); 0019 0020 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('0')) == '0'); 0021 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('9')) == '9'); 0022 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('a')) == 'A'); 0023 static_assert(IsoCodes::mapFromAlphaNumKey(IsoCodes::mapToAlphaNumKey('Z')) == 'Z'); 0024 0025 static_assert(IsoCodes::alpha2CodeToKey("AZ") == 0x415a); 0026 static_assert(IsoCodes::alpha2CodeToKey("az") == 0x415a); 0027 static_assert(IsoCodes::alpha2CodeToKey("Az") == 0x415a); 0028 static_assert(IsoCodes::alpha2CodeToKey("ZA") == 0x5a41); 0029 static_assert(IsoCodes::alpha2CodeToKey("NZ") == IsoCodes::alpha2CodeToKey(u"NZ")); 0030 0031 static_assert(IsoCodes::alpha2CodeToKey("") == 0); 0032 static_assert(IsoCodes::alpha2CodeToKey("12") == 0); 0033 static_assert(IsoCodes::alpha2CodeToKey("A") == 0); 0034 static_assert(IsoCodes::alpha2CodeToKey("ABC") == 0); 0035 static_assert(IsoCodes::alpha2CodeToKey("A@") == 0); 0036 0037 static_assert(IsoCodes::alpha2CodeToKey("AA") < IsoCodes::alpha2CodeToKey("AB")); 0038 static_assert(IsoCodes::alpha2CodeToKey("AZ") < IsoCodes::alpha2CodeToKey("BA")); 0039 0040 static_assert(IsoCodes::alpha3CodeToKey("ZZZ") < std::numeric_limits<uint16_t>::max()); 0041 static_assert(IsoCodes::alpha3CodeToKey("AAA") > 0); 0042 static_assert(IsoCodes::alpha3CodeToKey("AAA") < IsoCodes::alpha3CodeToKey("AAB")); 0043 static_assert(IsoCodes::alpha3CodeToKey("AAB") < IsoCodes::alpha3CodeToKey("BAA")); 0044 static_assert(IsoCodes::alpha3CodeToKey("NZL") == IsoCodes::alpha3CodeToKey(u"NZL")); 0045 0046 static_assert(IsoCodes::alpha3CodeToKey("") == 0); 0047 static_assert(IsoCodes::alpha3CodeToKey("AA") == 0); 0048 static_assert(IsoCodes::alpha3CodeToKey("ABCD") == 0); 0049 static_assert(IsoCodes::alpha3CodeToKey("AB1") == 0); 0050 static_assert(IsoCodes::alpha3CodeToKey("A@C") == 0); 0051 0052 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") > 0); 0053 static_assert(IsoCodes::subdivisionCodeToKey("ZZ-ZZZ") > 0); 0054 static_assert(IsoCodes::subdivisionCodeToKey("ZZ-999") < std::numeric_limits<uint32_t>::max()); 0055 static_assert(IsoCodes::subdivisionCodeToKey("AA-A") < IsoCodes::subdivisionCodeToKey("AA-AA")); 0056 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") < IsoCodes::subdivisionCodeToKey("AA-AAB")); 0057 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAA") < IsoCodes::subdivisionCodeToKey("AA-AB")); 0058 static_assert(IsoCodes::subdivisionCodeToKey("AA-AAB") < IsoCodes::subdivisionCodeToKey("AA-BAA")); 0059 static_assert(IsoCodes::subdivisionCodeToKey("AA-AA1") < IsoCodes::subdivisionCodeToKey("AA-AAZ")); 0060 static_assert(IsoCodes::subdivisionCodeToKey("FR-99") < IsoCodes::subdivisionCodeToKey("FR-RE")); 0061 static_assert(IsoCodes::subdivisionCodeToKey("AB-cd1") == IsoCodes::subdivisionCodeToKey("AB-CD1")); 0062 0063 static_assert(IsoCodes::subdivisionCodeToKey("") == 0); 0064 static_assert(IsoCodes::subdivisionCodeToKey("AA-") == 0); 0065 static_assert(IsoCodes::subdivisionCodeToKey("12-ABC") == 0); 0066 static_assert(IsoCodes::subdivisionCodeToKey("AA-@") == 0); 0067 static_assert(IsoCodes::subdivisionCodeToKey("AB") == 0); 0068 static_assert(IsoCodes::subdivisionCodeToKey("ABC") == 0);