185 lines · cpp
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9// <regex>10 11// template <class charT> struct regex_traits;12 13// template <class ForwardIterator>14// string_type15// lookup_collatename(ForwardIterator first, ForwardIterator last) const;16 17#include <regex>18#include <iterator>19#include <cassert>20 21#include "test_macros.h"22#include "test_iterators.h"23 24template <class char_type>25void26test(const char_type* A, const std::basic_string<char_type>& expected)27{28 std::regex_traits<char_type> t;29 typedef forward_iterator<const char_type*> F;30 assert(t.lookup_collatename(F(A), F(A + t.length(A))) == expected);31}32 33int main(int, char**)34{35 test("NUL", std::string("\x00", 1));36 test("alert", std::string("\x07"));37 test("backspace", std::string("\x08"));38 test("tab", std::string("\x09"));39 test("carriage-return", std::string("\x0D"));40 test("newline", std::string("\x0A"));41 test("vertical-tab", std::string("\x0B"));42 test("form-feed", std::string("\x0C"));43 test("space", std::string(" "));44 test("exclamation-mark", std::string("!"));45 test("quotation-mark", std::string("\""));46 test("number-sign", std::string("#"));47 test("dollar-sign", std::string("$"));48 test("percent-sign", std::string("%"));49 test("ampersand", std::string("&"));50 test("apostrophe", std::string("\'"));51 test("left-parenthesis", std::string("("));52 test("right-parenthesis", std::string(")"));53 test("asterisk", std::string("*"));54 test("plus-sign", std::string("+"));55 test("comma", std::string(","));56 test("hyphen-minus", std::string("-"));57 test("hyphen", std::string("-"));58 test("full-stop", std::string("."));59 test("period", std::string("."));60 test("slash", std::string("/"));61 test("solidus", std::string("/"));62 test("zero", std::string("0"));63 test("one", std::string("1"));64 test("two", std::string("2"));65 test("three", std::string("3"));66 test("four", std::string("4"));67 test("five", std::string("5"));68 test("six", std::string("6"));69 test("seven", std::string("7"));70 test("eight", std::string("8"));71 test("nine", std::string("9"));72 test("colon", std::string(":"));73 test("semicolon", std::string(";"));74 test("less-than-sign", std::string("<"));75 test("equals-sign", std::string("="));76 test("greater-than-sign", std::string(">"));77 test("question-mark", std::string("?"));78 test("commercial-at", std::string("@"));79 for (char c = 'A'; c <= 'Z'; ++c)80 {81 const char a[2] = {c};82 test(a, std::string(a));83 }84 test("left-square-bracket", std::string("["));85 test("backslash", std::string("\\"));86 test("reverse-solidus", std::string("\\"));87 test("right-square-bracket", std::string("]"));88 test("circumflex-accent", std::string("^"));89 test("circumflex", std::string("^"));90 test("low-line", std::string("_"));91 test("underscore", std::string("_"));92 test("grave-accent", std::string("`"));93 for (char c = 'a'; c <= 'z'; ++c)94 {95 const char a[2] = {c};96 test(a, std::string(a));97 }98 test("left-brace", std::string("{"));99 test("left-curly-bracket", std::string("{"));100 test("vertical-line", std::string("|"));101 test("right-brace", std::string("}"));102 test("right-curly-bracket", std::string("}"));103 test("tilde", std::string("~"));104 105 test("tild", std::string(""));106 test("ch", std::string(""));107 108#ifndef TEST_HAS_NO_WIDE_CHARACTERS109 test(L"NUL", std::wstring(L"\x00", 1));110 test(L"alert", std::wstring(L"\x07"));111 test(L"backspace", std::wstring(L"\x08"));112 test(L"tab", std::wstring(L"\x09"));113 test(L"carriage-return", std::wstring(L"\x0D"));114 test(L"newline", std::wstring(L"\x0A"));115 test(L"vertical-tab", std::wstring(L"\x0B"));116 test(L"form-feed", std::wstring(L"\x0C"));117 test(L"space", std::wstring(L" "));118 test(L"exclamation-mark", std::wstring(L"!"));119 test(L"quotation-mark", std::wstring(L"\""));120 test(L"number-sign", std::wstring(L"#"));121 test(L"dollar-sign", std::wstring(L"$"));122 test(L"percent-sign", std::wstring(L"%"));123 test(L"ampersand", std::wstring(L"&"));124 test(L"apostrophe", std::wstring(L"\'"));125 test(L"left-parenthesis", std::wstring(L"("));126 test(L"right-parenthesis", std::wstring(L")"));127 test(L"asterisk", std::wstring(L"*"));128 test(L"plus-sign", std::wstring(L"+"));129 test(L"comma", std::wstring(L","));130 test(L"hyphen-minus", std::wstring(L"-"));131 test(L"hyphen", std::wstring(L"-"));132 test(L"full-stop", std::wstring(L"."));133 test(L"period", std::wstring(L"."));134 test(L"slash", std::wstring(L"/"));135 test(L"solidus", std::wstring(L"/"));136 test(L"zero", std::wstring(L"0"));137 test(L"one", std::wstring(L"1"));138 test(L"two", std::wstring(L"2"));139 test(L"three", std::wstring(L"3"));140 test(L"four", std::wstring(L"4"));141 test(L"five", std::wstring(L"5"));142 test(L"six", std::wstring(L"6"));143 test(L"seven", std::wstring(L"7"));144 test(L"eight", std::wstring(L"8"));145 test(L"nine", std::wstring(L"9"));146 test(L"colon", std::wstring(L":"));147 test(L"semicolon", std::wstring(L";"));148 test(L"less-than-sign", std::wstring(L"<"));149 test(L"equals-sign", std::wstring(L"="));150 test(L"greater-than-sign", std::wstring(L">"));151 test(L"question-mark", std::wstring(L"?"));152 test(L"commercial-at", std::wstring(L"@"));153 for (wchar_t c = L'A'; c <= L'Z'; ++c)154 {155 const wchar_t a[2] = {c};156 test(a, std::wstring(a));157 }158 test(L"left-square-bracket", std::wstring(L"["));159 test(L"backslash", std::wstring(L"\\"));160 test(L"reverse-solidus", std::wstring(L"\\"));161 test(L"right-square-bracket", std::wstring(L"]"));162 test(L"circumflex-accent", std::wstring(L"^"));163 test(L"circumflex", std::wstring(L"^"));164 test(L"low-line", std::wstring(L"_"));165 test(L"underscore", std::wstring(L"_"));166 test(L"grave-accent", std::wstring(L"`"));167 for (wchar_t c = L'a'; c <= L'z'; ++c)168 {169 const wchar_t a[2] = {c};170 test(a, std::wstring(a));171 }172 test(L"left-brace", std::wstring(L"{"));173 test(L"left-curly-bracket", std::wstring(L"{"));174 test(L"vertical-line", std::wstring(L"|"));175 test(L"right-brace", std::wstring(L"}"));176 test(L"right-curly-bracket", std::wstring(L"}"));177 test(L"tilde", std::wstring(L"~"));178 179 test(L"tild", std::wstring(L""));180 test(L"ch", std::wstring(L""));181#endif // TEST_HAS_NO_WIDE_CHARACTERS182 183 return 0;184}185