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