7026a17a48
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@111024 91177308-0d34-0410-b5e6-96231b3b80d8
126 lines
3.6 KiB
C++
126 lines
3.6 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <regex>
|
|
|
|
// template <class charT> struct regex_traits;
|
|
|
|
// int value(charT ch, int radix) const;
|
|
|
|
#include <regex>
|
|
#include <cassert>
|
|
|
|
int main()
|
|
{
|
|
{
|
|
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) == c - '0');
|
|
assert(t.value(c, 10) == c - '0');
|
|
assert(t.value(c, 16) == c - '0');
|
|
}
|
|
for (wchar_t 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 (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) == 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) == c - 'a' +10);
|
|
}
|
|
for (int c = 'g'; c < 0xFFFF; ++c)
|
|
{
|
|
assert(t.value(c, 8) == -1);
|
|
assert(t.value(c, 10) == -1);
|
|
assert(t.value(c, 16) == -1);
|
|
}
|
|
}
|
|
}
|