utf8rewind  1.4.0
System library for processing UTF-8 encoded text
helpers-casemapping.hpp
Go to the documentation of this file.
1 #pragma once
2 
10 #include "helpers-base.hpp"
11 
12 #define EXPECT_CASEMAPPING_CODEPOINT_NUL_EQ(_codepoint, _name) { \
13  ::helpers::CaseMappingEntry e; \
14  e.codepoint = _codepoint; \
15  e.lowercase = std::string(1, '\0'); \
16  e.uppercase = std::string(1, '\0'); \
17  e.titlecase = std::string(1, '\0'); \
18  e.name = _name; \
19  ::helpers::CaseMappingEntry a; \
20  a.lowercase = ::helpers::lowercase(_codepoint); \
21  a.uppercase = ::helpers::uppercase(_codepoint); \
22  a.titlecase = ::helpers::titlecase(_codepoint); \
23  EXPECT_PRED_FORMAT2(::helpers::CompareCodepoint, e, a); \
24 }
25 
26 #define EXPECT_CASEMAPPING_CODEPOINT_EQ(_codepoint, _lowercase, _uppercase, _titlecase, _name) { \
27  ::helpers::CaseMappingEntry e; \
28  e.codepoint = _codepoint; \
29  e.lowercase = _lowercase; \
30  e.uppercase = _uppercase; \
31  e.titlecase = _titlecase; \
32  e.name = _name; \
33  ::helpers::CaseMappingEntry a; \
34  a.lowercase = ::helpers::lowercase(_codepoint); \
35  a.uppercase = ::helpers::uppercase(_codepoint); \
36  a.titlecase = ::helpers::titlecase(_codepoint); \
37  EXPECT_PRED_FORMAT2(::helpers::CompareCodepoint, e, a); \
38 }
39 
40 #define EXPECT_CASEMAPPING_EQ(_input, _lowercase, _uppercase, _titlecase) { \
41  ::helpers::CaseMappingEntry e; \
42  e.lowercase = _lowercase; \
43  e.uppercase = _uppercase; \
44  e.titlecase = _titlecase; \
45  ::helpers::CaseMappingEntry a; \
46  a.input = _input; \
47  a.lowercase = ::helpers::lowercase(_input); \
48  a.uppercase = ::helpers::uppercase(_input); \
49  a.titlecase = ::helpers::titlecase(_input); \
50  EXPECT_PRED_FORMAT2(::helpers::CompareCaseMapping, e, a); \
51 }
52 
53 #if UTF8_VERSION_GUARD(1, 4, 0)
54  #define EXPECT_CASEFOLDING_EQ(_codepoint, _folded, _name) { \
55  ::helpers::CaseFoldingEntry e; \
56  e.codePoint = _codepoint; \
57  e.folded = _folded; \
58  e.name = _name; \
59  ::helpers::CaseFoldingEntry a; \
60  a.folded = ::helpers::casefold(_codepoint); \
61  EXPECT_PRED_FORMAT2(::helpers::CompareCaseFolding, e, a); \
62  }
63 #endif
64 
65 namespace helpers {
66 
67  std::string uppercase(unicode_t codepoint);
68  std::string uppercase(const std::string& text);
69 
70  std::string lowercase(unicode_t codepoint);
71  std::string lowercase(const std::string& text);
72 
73  std::string titlecase(unicode_t codepoint);
74  std::string titlecase(const std::string& text);
75 
76 #if UTF8_VERSION_GUARD(1, 4, 0)
77  std::string casefold(unicode_t codepoint);
78  std::string casefold(const std::string& text);
79 #endif
80 
81  struct CaseMappingEntry
82  {
83  CaseMappingEntry()
84  : codepoint(0)
85  {
86  }
87 
88  unicode_t codepoint;
89  std::string name;
90  std::string input;
91  std::string lowercase;
92  std::string uppercase;
93  std::string titlecase;
94  };
95 
96  ::testing::AssertionResult CompareCodepoint(
97  const char* expressionExpected, const char* expressionActual,
98  const CaseMappingEntry& entryExpected, const CaseMappingEntry& entryActual);
99 
100  ::testing::AssertionResult CompareCaseMapping(
101  const char* expressionExpected, const char* expressionActual,
102  const CaseMappingEntry& entryExpected, const CaseMappingEntry& entryActual);
103 
104 #if UTF8_VERSION_GUARD(1, 4, 0)
105  struct CaseFoldingEntry
106  {
107  unicode_t codePoint;
108  std::string folded;
109  std::string name;
110  };
111 
112  ::testing::AssertionResult CompareCaseFolding(
113  const char* expressionExpected, const char* expressionActual,
114  const CaseFoldingEntry& entryExpected, const CaseFoldingEntry& entryActual);
115 #endif
116 
117 };
118 
uint32_t unicode_t
UTF-32 encoded code point.
Definition: utf8rewind.h:203
Base includes for helper methods.