grouping.pass.cpp revision c0d0cbad9ed434267a7af9531bdeeae52eb6d706
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <locale> 11 12// class moneypunct_byname<charT, International> 13 14// string grouping() const; 15 16#include <locale> 17#include <limits> 18#include <cassert> 19 20#include "../../../../platform_support.h" // locale name macros 21 22class Fnf 23 : public std::moneypunct_byname<char, false> 24{ 25public: 26 explicit Fnf(const std::string& nm, std::size_t refs = 0) 27 : std::moneypunct_byname<char, false>(nm, refs) {} 28}; 29 30class Fnt 31 : public std::moneypunct_byname<char, true> 32{ 33public: 34 explicit Fnt(const std::string& nm, std::size_t refs = 0) 35 : std::moneypunct_byname<char, true>(nm, refs) {} 36}; 37 38class Fwf 39 : public std::moneypunct_byname<wchar_t, false> 40{ 41public: 42 explicit Fwf(const std::string& nm, std::size_t refs = 0) 43 : std::moneypunct_byname<wchar_t, false>(nm, refs) {} 44}; 45 46class Fwt 47 : public std::moneypunct_byname<wchar_t, true> 48{ 49public: 50 explicit Fwt(const std::string& nm, std::size_t refs = 0) 51 : std::moneypunct_byname<wchar_t, true>(nm, refs) {} 52}; 53 54int main() 55{ 56 // Monetary grouping strings may be terminated with 0 or CHAR_MAX, defining 57 // how the grouping is repeated. 58 std::string s = std::string(1, CHAR_MAX); 59 { 60 Fnf f("C", 1); 61 assert(f.grouping() == s || f.grouping() == ""); 62 } 63 { 64 Fnt f("C", 1); 65 assert(f.grouping() == s || f.grouping() == ""); 66 } 67 { 68 Fwf f("C", 1); 69 assert(f.grouping() == s || f.grouping() == ""); 70 } 71 { 72 Fwt f("C", 1); 73 assert(f.grouping() == s || f.grouping() == ""); 74 } 75 76 { 77 Fnf f(LOCALE_en_US_UTF_8, 1); 78 assert(f.grouping() == "\3\3"); 79 } 80 { 81 Fnt f(LOCALE_en_US_UTF_8, 1); 82 assert(f.grouping() == "\3\3"); 83 } 84 { 85 Fwf f(LOCALE_en_US_UTF_8, 1); 86 assert(f.grouping() == "\3\3"); 87 } 88 { 89 Fwt f(LOCALE_en_US_UTF_8, 1); 90 assert(f.grouping() == "\3\3"); 91 } 92 93 { 94 Fnf f(LOCALE_fr_FR_UTF_8, 1); 95 assert(f.grouping() == "\3\3"); 96 } 97 { 98 Fnt f(LOCALE_fr_FR_UTF_8, 1); 99 assert(f.grouping() == "\3\3"); 100 } 101 { 102 Fwf f(LOCALE_fr_FR_UTF_8, 1); 103 assert(f.grouping() == "\3\3"); 104 } 105 { 106 Fwt f(LOCALE_fr_FR_UTF_8, 1); 107 assert(f.grouping() == "\3\3"); 108 } 109 110 { 111 Fnf f(LOCALE_ru_RU_UTF_8, 1); 112 assert(f.grouping() == "\3\3"); 113 } 114 { 115 Fnt f(LOCALE_ru_RU_UTF_8, 1); 116 assert(f.grouping() == "\3\3"); 117 } 118 { 119 Fwf f(LOCALE_ru_RU_UTF_8, 1); 120 assert(f.grouping() == "\3\3"); 121 } 122 { 123 Fwt f(LOCALE_ru_RU_UTF_8, 1); 124 assert(f.grouping() == "\3\3"); 125 } 126 127 { 128 Fnf f(LOCALE_zh_CN_UTF_8, 1); 129 assert(f.grouping() == "\3\3"); 130 } 131 { 132 Fnt f(LOCALE_zh_CN_UTF_8, 1); 133 assert(f.grouping() == "\3\3"); 134 } 135 { 136 Fwf f(LOCALE_zh_CN_UTF_8, 1); 137 assert(f.grouping() == "\3\3"); 138 } 139 { 140 Fwt f(LOCALE_zh_CN_UTF_8, 1); 141 assert(f.grouping() == "\3\3"); 142 } 143} 144