| Howard Hinnant | 7050530 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Howard Hinnant | 7050530 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <regex> |
| 10 | |
| 11 | // template <class charT> struct regex_traits; |
| 12 | |
| 13 | // int value(charT ch, int radix) const; |
| 14 | |
| 15 | #include <regex> |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 16 | #include <cassert> |
| Marshall Clow | fd5ceb2 | 2016-04-26 16:24:44 +0000 | [diff] [blame] | 17 | #include "test_macros.h" |
| Howard Hinnant | 7050530 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 18 | |
| 19 | int main() |
| 20 | { |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 21 | { |
| 22 | std::regex_traits<char> t; |
| 23 | |
| 24 | for (char c = 0; c < '0'; ++c) |
| 25 | { |
| 26 | assert(t.value(c, 8) == -1); |
| 27 | assert(t.value(c, 10) == -1); |
| 28 | assert(t.value(c, 16) == -1); |
| 29 | } |
| 30 | for (char c = '0'; c < '8'; ++c) |
| 31 | { |
| 32 | assert(t.value(c, 8) == c - '0'); |
| 33 | assert(t.value(c, 10) == c - '0'); |
| 34 | assert(t.value(c, 16) == c - '0'); |
| 35 | } |
| 36 | for (char c = '8'; c < ':'; ++c) |
| 37 | { |
| 38 | assert(t.value(c, 8) == -1); |
| 39 | assert(t.value(c, 10) == c - '0'); |
| 40 | assert(t.value(c, 16) == c - '0'); |
| 41 | } |
| 42 | for (char c = ':'; c < 'A'; ++c) |
| 43 | { |
| 44 | assert(t.value(c, 8) == -1); |
| 45 | assert(t.value(c, 10) == -1); |
| 46 | assert(t.value(c, 16) == -1); |
| 47 | } |
| 48 | for (char c = 'A'; c < 'G'; ++c) |
| 49 | { |
| 50 | assert(t.value(c, 8) == -1); |
| 51 | assert(t.value(c, 10) == -1); |
| 52 | assert(t.value(c, 16) == c - 'A' +10); |
| 53 | } |
| 54 | for (char c = 'G'; c < 'a'; ++c) |
| 55 | { |
| 56 | assert(t.value(c, 8) == -1); |
| 57 | assert(t.value(c, 10) == -1); |
| 58 | assert(t.value(c, 16) == -1); |
| 59 | } |
| 60 | for (char c = 'a'; c < 'g'; ++c) |
| 61 | { |
| 62 | assert(t.value(c, 8) == -1); |
| 63 | assert(t.value(c, 10) == -1); |
| 64 | assert(t.value(c, 16) == c - 'a' +10); |
| 65 | } |
| 66 | for (int c = 'g'; c < 256; ++c) |
| 67 | { |
| 68 | assert(t.value(char(c), 8) == -1); |
| 69 | assert(t.value(char(c), 10) == -1); |
| 70 | assert(t.value(char(c), 16) == -1); |
| 71 | } |
| 72 | } |
| 73 | { |
| 74 | std::regex_traits<wchar_t> t; |
| 75 | |
| 76 | for (wchar_t c = 0; c < '0'; ++c) |
| 77 | { |
| 78 | assert(t.value(c, 8) == -1); |
| 79 | assert(t.value(c, 10) == -1); |
| 80 | assert(t.value(c, 16) == -1); |
| 81 | } |
| 82 | for (wchar_t c = '0'; c < '8'; ++c) |
| 83 | { |
| Eric Fiselier | b0bbd8a | 2016-12-24 03:09:00 +0000 | [diff] [blame] | 84 | assert(t.value(c, 8) == static_cast<int>(c - '0')); |
| 85 | assert(t.value(c, 10) == static_cast<int>(c - '0')); |
| 86 | assert(t.value(c, 16) == static_cast<int>(c - '0')); |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 87 | } |
| 88 | for (wchar_t c = '8'; c < ':'; ++c) |
| 89 | { |
| 90 | assert(t.value(c, 8) == -1); |
| Eric Fiselier | b0bbd8a | 2016-12-24 03:09:00 +0000 | [diff] [blame] | 91 | assert(t.value(c, 10) == static_cast<int>(c - '0')); |
| 92 | assert(t.value(c, 16) == static_cast<int>(c - '0')); |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 93 | } |
| 94 | for (wchar_t c = ':'; c < 'A'; ++c) |
| 95 | { |
| 96 | assert(t.value(c, 8) == -1); |
| 97 | assert(t.value(c, 10) == -1); |
| 98 | assert(t.value(c, 16) == -1); |
| 99 | } |
| 100 | for (wchar_t c = 'A'; c < 'G'; ++c) |
| 101 | { |
| 102 | assert(t.value(c, 8) == -1); |
| 103 | assert(t.value(c, 10) == -1); |
| Eric Fiselier | b0bbd8a | 2016-12-24 03:09:00 +0000 | [diff] [blame] | 104 | assert(t.value(c, 16) == static_cast<int>(c - 'A' +10)); |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 105 | } |
| 106 | for (wchar_t c = 'G'; c < 'a'; ++c) |
| 107 | { |
| 108 | assert(t.value(c, 8) == -1); |
| 109 | assert(t.value(c, 10) == -1); |
| 110 | assert(t.value(c, 16) == -1); |
| 111 | } |
| 112 | for (wchar_t c = 'a'; c < 'g'; ++c) |
| 113 | { |
| 114 | assert(t.value(c, 8) == -1); |
| 115 | assert(t.value(c, 10) == -1); |
| Eric Fiselier | b0bbd8a | 2016-12-24 03:09:00 +0000 | [diff] [blame] | 116 | assert(t.value(c, 16) == static_cast<int>(c - 'a' +10)); |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 117 | } |
| Stephan T. Lavavej | f2e24f5 | 2016-12-08 21:38:57 +0000 | [diff] [blame] | 118 | for (wchar_t c = 'g'; c < 0xFFFF; ++c) |
| Howard Hinnant | 24757ff | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 119 | { |
| 120 | assert(t.value(c, 8) == -1); |
| 121 | assert(t.value(c, 10) == -1); |
| 122 | assert(t.value(c, 16) == -1); |
| 123 | } |
| 124 | } |
| Howard Hinnant | 7050530 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 125 | } |