gcc - GNU Compiler Collection (original) (raw)

libstdc++: Replace _CharT template parameter with CharT in format tests.HEADtrunkmaster

As pointed out by Daniel Krügler we do not need to use reserved name in tests. libstdc++-v3/ChangeLog: * testsuite/23_containers/vector/bool/format.cc: Replaced _CharT with CharT. * testsuite/std/format/debug.cc: Likewise. * testsuite/std/format/ranges/adaptors.cc: Likewise. * testsuite/std/format/ranges/formatter.cc: Likewise. * testsuite/std/format/ranges/map.cc: Likewise. * testsuite/std/format/ranges/sequence.cc: Likewise. * testsuite/std/format/ranges/string.cc: Likewise. * testsuite/std/format/tuple.cc: Likewise. * testsuite/std/time/format/empty_spec.cc: Likewise. * testsuite/std/time/format/pr120114.cc: Likewise. * testsuite/std/time/format/pr120481.cc: Likewise. * testsuite/std/time/format/precision.cc: Likewise.

@@ -21,7 +21,7 @@ is_format_string_for(const char* str, Args&&... args)

21

}

21

}

22

22

23

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

23

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

24

#define WIDEN(S) WIDEN_(_CharT, S)

24

#define WIDEN(S) WIDEN_(CharT, S)

25

25

26

void

26

void

27

test_format_string()

27

test_format_string()

@@ -34,11 +34,11 @@ test_format_string()

34

VERIFY( !is_format_string_for("{:{}}", v[0], 1.0f) );

34

VERIFY( !is_format_string_for("{:{}}", v[0], 1.0f) );

35

}

35

}

36

36

37

template<typename _CharT>

37

template

38

void

38

void

39

test_output()

39

test_output()

40

{

40

{

41

std::basic_string<_CharT> res;

41

std::basic_string res;

42

size_t size = 0;

42

size_t size = 0;

43

std::vector v{true, false};

43

std::vector v{true, false};

44

44

@@ -26,13 +26,13 @@ fdebug(std::wstring_view t)

26

26

27

27

28

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

28

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

29

#define WIDEN(S) WIDEN_(_CharT, S)

29

#define WIDEN(S) WIDEN_(CharT, S)

30

30

31

template<typename _CharT>

31

template

32

void

32

void

33

test_basic_escapes()

33

test_basic_escapes()

34

{

34

{

35

std::basic_string<_CharT> res;

35

std::basic_string res;

36

36

37

const auto tab = WIDEN("\t");

37

const auto tab = WIDEN("\t");

38

res = fdebug(tab);

38

res = fdebug(tab);

@@ -71,11 +71,11 @@ test_basic_escapes()

71

VERIFY( res == WIDEN(R"('\'')") );

71

VERIFY( res == WIDEN(R"('\'')") );

72

}

72

}

73

73

74

template<typename _CharT>

74

template

75

void

75

void

76

test_ascii_escapes()

76

test_ascii_escapes()

77

{

77

{

78

std::basic_string<_CharT> res;

78

std::basic_string res;

79

79

80

const auto in = WIDEN("\x10 abcde\x7f\t0123");

80

const auto in = WIDEN("\x10 abcde\x7f\t0123");

81

res = fdebug(in);

81

res = fdebug(in);

@@ -88,11 +88,11 @@ test_ascii_escapes()

88

VERIFY( res == WIDEN(R"('a')") );

88

VERIFY( res == WIDEN(R"('a')") );

89

}

89

}

90

90

91

template<typename _CharT>

91

template

92

void

92

void

93

test_extended_ascii()

93

test_extended_ascii()

94

{

94

{

95

std::basic_string<_CharT> res;

95

std::basic_string res;

96

96

97

const auto in = WIDEN("Åëÿ");

97

const auto in = WIDEN("Åëÿ");

98

res = fdebug(in);

98

res = fdebug(in);

@@ -100,7 +100,7 @@ test_extended_ascii()

100

100

101

static constexpr bool __test_characters

101

static constexpr bool __test_characters

102

#if UNICODE_ENC

102

#if UNICODE_ENC

103

= sizeof(_CharT) >= 2;

103

= sizeof(CharT) >= 2;

104

#else // ISO8859-1

104

#else // ISO8859-1

105

= true;

105

= true;

106

#endif // UNICODE_ENC

106

#endif // UNICODE_ENC

@@ -116,12 +116,12 @@ test_extended_ascii()

116

}

116

}

117

}

117

}

118

118

119

template<typename _CharT>

119

template

120

void

120

void

121

test_unicode_escapes()

121

test_unicode_escapes()

122

{

122

{

123

#if UNICODE_ENC

123

#if UNICODE_ENC

124

std::basic_string<_CharT> res;

124

std::basic_string res;

125

125

126

const auto in = WIDEN(

126

const auto in = WIDEN(

127

"\u008a" // Cc, Control, Line Tabulation Set,

127

"\u008a" // Cc, Control, Line Tabulation Set,

@@ -143,7 +143,7 @@ test_unicode_escapes()

143

res = fdebug(in);

143

res = fdebug(in);

144

VERIFY( res == out );

144

VERIFY( res == out );

145

145

146

if constexpr (sizeof(_CharT) >= 2)

146

if constexpr (sizeof(CharT) >= 2)

147

{

147

{

148

res = fdebug(in[0]);

148

res = fdebug(in[0]);

149

VERIFY( res == WIDEN(R"('\u{8a}')") );

149

VERIFY( res == WIDEN(R"('\u{8a}')") );

@@ -157,7 +157,7 @@ test_unicode_escapes()

157

VERIFY( res == WIDEN(R"('\u{2029}')") );

157

VERIFY( res == WIDEN(R"('\u{2029}')") );

158

}

158

}

159

159

160

if constexpr (sizeof(_CharT) >= 4)

160

if constexpr (sizeof(CharT) >= 4)

161

{

161

{

162

res = fdebug(in[5]);

162

res = fdebug(in[5]);

163

VERIFY( res == WIDEN("'\U0001f984'") );

163

VERIFY( res == WIDEN("'\U0001f984'") );

@@ -165,25 +165,25 @@ test_unicode_escapes()

165

#endif // UNICODE_ENC

165

#endif // UNICODE_ENC

166

}

166

}

167

167

168

template<typename _CharT>

168

template

169

void

169

void

170

test_grapheme_extend()

170

test_grapheme_extend()

171

{

171

{

172

#if UNICODE_ENC

172

#if UNICODE_ENC

173

std::basic_string<_CharT> res;

173

std::basic_string res;

174

174

175

const auto vin = WIDEN("o\u0302\u0323");

175

const auto vin = WIDEN("o\u0302\u0323");

176

res = fdebug(vin);

176

res = fdebug(vin);

177

VERIFY( res == WIDEN("\"o\u0302\u0323\"") );

177

VERIFY( res == WIDEN("\"o\u0302\u0323\"") );

178

178

179

std::basic_string_view<_CharT> in = WIDEN("\t\u0302\u0323");

179

std::basic_string_view in = WIDEN("\t\u0302\u0323");

180

res = fdebug(in);

180

res = fdebug(in);

181

VERIFY( res == WIDEN(R"("\t\u{302}\u{323}")") );

181

VERIFY( res == WIDEN(R"("\t\u{302}\u{323}")") );

182

182

183

res = fdebug(in.substr(1));

183

res = fdebug(in.substr(1));

184

VERIFY( res == WIDEN(R"("\u{302}\u{323}")") );

184

VERIFY( res == WIDEN(R"("\u{302}\u{323}")") );

185

185

186

if constexpr (sizeof(_CharT) >= 2)

186

if constexpr (sizeof(CharT) >= 2)

187

{

187

{

188

res = fdebug(in[1]);

188

res = fdebug(in[1]);

189

VERIFY( res == WIDEN(R"('\u{302}')") );

189

VERIFY( res == WIDEN(R"('\u{302}')") );

@@ -191,13 +191,13 @@ test_grapheme_extend()

191

#endif // UNICODE_ENC

191

#endif // UNICODE_ENC

192

}

192

}

193

193

194

template<typename _CharT>

194

template

195

void

195

void

196

test_replacement_char()

196

test_replacement_char()

197

{

197

{

198

#if UNICODE_ENC

198

#if UNICODE_ENC

199

std::basic_string<_CharT> repl = WIDEN("\uFFFD");

199

std::basic_string repl = WIDEN("\uFFFD");

200

std::basic_string<_CharT> res = fdebug(repl);

200

std::basic_string res = fdebug(repl);

201

VERIFY( res == WIDEN("\"\uFFFD\"") );

201

VERIFY( res == WIDEN("\"\uFFFD\"") );

202

202

203

repl = WIDEN("\uFFFD\uFFFD");

203

repl = WIDEN("\uFFFD\uFFFD");

@@ -268,13 +268,13 @@ test_ill_formed_utf32()

268

#endif // UNICODE_ENC

268

#endif // UNICODE_ENC

269

}

269

}

270

270

271

template<typename _CharT>

271

template

272

void

272

void

273

test_fill()

273

test_fill()

274

{

274

{

275

std::basic_string<_CharT> res;

275

std::basic_string res;

276

276

277

std::basic_string_view<_CharT> in = WIDEN("a\t\x10\u00ad");

277

std::basic_string_view in = WIDEN("a\t\x10\u00ad");

278

res = std::format(WIDEN("{:10?}"), in.substr(0, 1));

278

res = std::format(WIDEN("{:10?}"), in.substr(0, 1));

279

VERIFY( res == WIDEN(R"("a" )") );

279

VERIFY( res == WIDEN(R"("a" )") );

280

280

@@ -299,11 +299,11 @@ test_fill()

299

VERIFY( res == WIDEN(R"(="\u{ad}"=)") );

299

VERIFY( res == WIDEN(R"(="\u{ad}"=)") );

300

300

301

// width is 2

301

// width is 2

302

std::basic_string_view<_CharT> in2 = WIDEN("\u1100");

302

std::basic_string_view in2 = WIDEN("\u1100");

303

res = std::format(WIDEN("{:*^10?}"), in2);

303

res = std::format(WIDEN("{:*^10?}"), in2);

304

VERIFY( res == WIDEN("***\"\u1100\"***") );

304

VERIFY( res == WIDEN("***\"\u1100\"***") );

305

305

306

if constexpr (sizeof(_CharT) >= 2)

306

if constexpr (sizeof(CharT) >= 2)

307

{

307

{

308

res = std::format(WIDEN("{:=^10?}"), in[3]);

308

res = std::format(WIDEN("{:=^10?}"), in[3]);

309

VERIFY( res == WIDEN(R"(='\u{ad}'=)") );

309

VERIFY( res == WIDEN(R"(='\u{ad}'=)") );

@@ -314,14 +314,14 @@ test_fill()

314

#endif // UNICODE_ENC

314

#endif // UNICODE_ENC

315

}

315

}

316

316

317

template<typename _CharT>

317

template

318

void

318

void

319

test_prec()

319

test_prec()

320

{

320

{

321

std::basic_string<_CharT> res;

321

std::basic_string res;

322

// with ? escpaed presentation is copied to ouput, same as source

322

// with ? escpaed presentation is copied to ouput, same as source

323

323

324

std::basic_string_view<_CharT> in = WIDEN("a\t\x10\u00ad");

324

std::basic_string_view in = WIDEN("a\t\x10\u00ad");

325

res = std::format(WIDEN("{:.2?}"), in.substr(0, 1));

325

res = std::format(WIDEN("{:.2?}"), in.substr(0, 1));

326

VERIFY( res == WIDEN(R"("a)") );

326

VERIFY( res == WIDEN(R"("a)") );

327

327

@@ -335,7 +335,7 @@ test_prec()

335

res = std::format(WIDEN("{:.10?}"), in.substr(3));

335

res = std::format(WIDEN("{:.10?}"), in.substr(3));

336

VERIFY( res == WIDEN(R"("\u{ad}")") );

336

VERIFY( res == WIDEN(R"("\u{ad}")") );

337

337

338

std::basic_string_view<_CharT> in2 = WIDEN("\u1100");

338

std::basic_string_view in2 = WIDEN("\u1100");

339

res = std::format(WIDEN("{:.3?}"), in2);

339

res = std::format(WIDEN("{:.3?}"), in2);

340

VERIFY( res == WIDEN("\"\u1100") );

340

VERIFY( res == WIDEN("\"\u1100") );

341

#endif // UNICODE_ENC

341

#endif // UNICODE_ENC

@@ -759,38 +759,38 @@ private:

759

std::formatter<T, CharT> under;

759

std::formatter<T, CharT> under;

760

};

760

};

761

761

762

template<typename _CharT, typename StrT>

762

template<typename CharT, typename StrT>

763

void

763

void

764

test_formatter_str()

764

test_formatter_str()

765

{

765

{

766

_CharT buf[]{ 'a', 'b', 'c', 0 };

766

CharT buf[]{ 'a', 'b', 'c', 0 };

767

DebugWrapper in{ buf };

767

DebugWrapper in{ buf };

768

std::basic_string<_CharT> res = std::format(WIDEN("{:?}"), in );

768

std::basic_string res = std::format(WIDEN("{:?}"), in );

769

VERIFY( res == WIDEN(R"("abc")") );

769

VERIFY( res == WIDEN(R"("abc")") );

770

}

770

}

771

771

772

template<typename _CharT>

772

template

773

void

773

void

774

test_formatter_arr()

774

test_formatter_arr()

775

{

775

{

776

std::basic_string<_CharT> res;

776

std::basic_string res;

777

777

778

DebugWrapper<_CharT[3]> in3{ 'a', 'b', 'c' };

778

DebugWrapper<CharT[3]> in3{ 'a', 'b', 'c' };

779

res = std::format(WIDEN("{:?}"), in3 );

779

res = std::format(WIDEN("{:?}"), in3 );

780

VERIFY( res == WIDEN(R"("abc")") );

780

VERIFY( res == WIDEN(R"("abc")") );

781

781

782

// We print all characters, including null-terminator

782

// We print all characters, including null-terminator

783

DebugWrapper<_CharT[4]> in4{ 'a', 'b', 'c', 0 };

783

DebugWrapper<CharT[4]> in4{ 'a', 'b', 'c', 0 };

784

res = std::format(WIDEN("{:?}"), in4 );

784

res = std::format(WIDEN("{:?}"), in4 );

785

VERIFY( res == WIDEN(R"("abc\u{0}")") );

785

VERIFY( res == WIDEN(R"("abc\u{0}")") );

786

}

786

}

787

787

788

template<typename _CharT, typename SrcT>

788

template<typename CharT, typename SrcT>

789

void

789

void

790

test_formatter_char()

790

test_formatter_char()

791

{

791

{

792

DebugWrapper in{ 'a' };

792

DebugWrapper in{ 'a' };

793

std::basic_string<_CharT> res = std::format(WIDEN("{:?}"), in);

793

std::basic_string res = std::format(WIDEN("{:?}"), in);

794

VERIFY( res == WIDEN(R"('a')") );

794

VERIFY( res == WIDEN(R"('a')") );

795

}

795

}

796

796

@@ -19,7 +19,7 @@ is_format_string_for(const char* str, Args&&... args)

19

}

19

}

20

20

21

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

21

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

22

#define WIDEN(S) WIDEN_(_CharT, S)

22

#define WIDEN(S) WIDEN_(CharT, S)

23

23

24

template<template class Adaptor>

24

template<template class Adaptor>

25

void

25

void

@@ -66,13 +66,13 @@ template

66

constexpr auto std::format_kind<NotFormattableCont>

66

constexpr auto std::format_kind<NotFormattableCont>

67

= std::range_format::disabled;

67

= std::range_format::disabled;

68

68

69

template<typename _CharT,

69

template<typename CharT,

70

template<typename Tp, typename Cont = std::vector> class Adaptor>

70

template<typename Tp, typename Cont = std::vector> class Adaptor>

71

void

71

void

72

test_output()

72

test_output()

73

{

73

{

74

const std::vector v{3, 2, 1};

74

const std::vector v{3, 2, 1};

75

std::basic_string<_CharT> res;

75

std::basic_string res;

76

Adaptor<int, std::vector> q(std::from_range, v);

76

Adaptor<int, std::vector> q(std::from_range, v);

77

77

78

res = std::format(WIDEN("{}"), q);

78

res = std::format(WIDEN("{}"), q);

@@ -88,9 +88,9 @@ test_output()

88

VERIFY( res == WIDEN("==[0x03, 0x02, 0x01]===") );

88

VERIFY( res == WIDEN("==[0x03, 0x02, 0x01]===") );

89

89

90

// Sequence output is always used

90

// Sequence output is always used

91

Adaptor<_CharT, std::basic_string<_CharT>> qs(

91

Adaptor<CharT, std::basic_string> qs(

92

std::from_range,

92

std::from_range,

93

std::basic_string_view<_CharT>(WIDEN("321")));

93

std::basic_string_view(WIDEN("321")));

94

94

95

res = std::format(WIDEN("{}"), qs);

95

res = std::format(WIDEN("{}"), qs);

96

VERIFY( res == WIDEN("['3', '2', '1']") );

96

VERIFY( res == WIDEN("['3', '2', '1']") );

@@ -114,13 +114,13 @@ test_output()

114

res = std::format(WIDEN("{}"), mq);

114

res = std::format(WIDEN("{}"), mq);

115

VERIFY( res == WIDEN("[3, 2, 1]") );

115

VERIFY( res == WIDEN("[3, 2, 1]") );

116

116

117

static_assert(!std::formattable<const Adaptor, _CharT>);

117

static_assert(!std::formattable<const Adaptor, CharT>);

118

118

119

static_assert(!std::formattable<Adaptor, _CharT>);

119

static_assert(!std::formattable<Adaptor, CharT>);

120

static_assert(!std::formattable<const Adaptor, _CharT>);

120

static_assert(!std::formattable<const Adaptor, CharT>);

121

121

122

// Formatter check if container is formattable, not container elements.

122

// Formatter check if container is formattable, not container elements.

123

static_assert(!std::formattable<Adaptor<int, NotFormattableCont>, _CharT>);

123

static_assert(!std::formattable<Adaptor<int, NotFormattableCont>, CharT>);

124

}

124

}

125

125

126

template<template<typename Tp, typename Cont = std::vector> class Adaptor>

126

template<template<typename Tp, typename Cont = std::vector> class Adaptor>

@@ -135,12 +135,12 @@ test_adaptor()

135

static_assert(!std::formattable<Adaptor, char32_t>);

135

static_assert(!std::formattable<Adaptor, char32_t>);

136

}

136

}

137

137

138

template<typename _CharT>

138

template

139

void

139

void

140

test_compare()

140

test_compare()

141

{

141

{

142

const std::vector v{3, 2, 1};

142

const std::vector v{3, 2, 1};

143

std::basic_string<_CharT> res;

143

std::basic_string res;

144

std::priority_queue<int, std::vector, std::greater<>> q(

144

std::priority_queue<int, std::vector, std::greater<>> q(

145

std::from_range, v);

145

std::from_range, v);

146

146

@@ -6,7 +6,7 @@

6

#include

6

#include

7

7

8

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

8

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

9

#define WIDEN(S) WIDEN_(_CharT, S)

9

#define WIDEN(S) WIDEN_(CharT, S)

10

10

11

template<typename T,

11

template<typename T,

12

template<typename, typename> class Formatter = std::range_formatter>

12

template<typename, typename> class Formatter = std::range_formatter>

@@ -22,7 +22,6 @@ struct std::formatter<MyVector<T, Formatter>, CharT>

22

{

22

{

23

constexpr formatter() noexcept

23

constexpr formatter() noexcept

24

{

24

{

25

using _CharT = CharT;

26

_formatter.set_brackets(WIDEN("<"), WIDEN(">"));

25

_formatter.set_brackets(WIDEN("<"), WIDEN(">"));

27

_formatter.set_separator(WIDEN("; "));

26

_formatter.set_separator(WIDEN("; "));

28

}

27

}

@@ -41,12 +40,12 @@ private:

41

Formatter<T, CharT> _formatter;

40

Formatter<T, CharT> _formatter;

42

};

41

};

43

42

44

template<typename _CharT, template<typename, typename> class Formatter>

43

template<typename CharT, template<typename, typename> class Formatter>

45

void

44

void

46

test_default()

45

test_default()

47

{

46

{

48

MyVector<int, Formatter> vec{1, 2, 3};

47

MyVector<int, Formatter> vec{1, 2, 3};

49

std::basic_string<_CharT> res;

48

std::basic_string res;

50

49

51

res = std::format(WIDEN("{}"), vec);

50

res = std::format(WIDEN("{}"), vec);

52

VERIFY( res == WIDEN("<1; 2; 3>") );

51

VERIFY( res == WIDEN("<1; 2; 3>") );

@@ -93,13 +92,13 @@ test_default()

93

VERIFY( res == WIDEN("< +1 ; +2 ; +3 >") );

92

VERIFY( res == WIDEN("< +1 ; +2 ; +3 >") );

94

}

93

}

95

94

96

template<typename _CharT, template<typename, typename> class Formatter>

95

template<typename CharT, template<typename, typename> class Formatter>

97

void

96

void

98

test_override()

97

test_override()

99

{

98

{

100

MyVector<_CharT, Formatter> vc{'a', 'b', 'c', 'd'};

99

MyVector<CharT, Formatter> vc{'a', 'b', 'c', 'd'};

101

MyVector<std::pair<int, int>, Formatter> vp{{1, 11}, {2, 21}};

100

MyVector<std::pair<int, int>, Formatter> vp{{1, 11}, {2, 21}};

102

std::basic_string<_CharT> res;

101

std::basic_string res;

103

102

104

res = std::format(WIDEN("{:s}"), vc);

103

res = std::format(WIDEN("{:s}"), vc);

105

VERIFY( res == WIDEN("abcd") );

104

VERIFY( res == WIDEN("abcd") );

@@ -57,7 +57,7 @@ bool is_range_formatter_spec_for(CharT const* spec, Rg&& rg)

57

}

57

}

58

58

59

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

59

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

60

#define WIDEN(S) WIDEN_(_CharT, S)

60

#define WIDEN(S) WIDEN_(CharT, S)

61

61

62

void

62

void

63

test_format_string()

63

test_format_string()

@@ -83,10 +83,10 @@ test_format_string()

83

VERIFY( !is_format_string_for("{:{}m}", std::vector<std::pair<int, int>>(), 1.0f) );

83

VERIFY( !is_format_string_for("{:{}m}", std::vector<std::pair<int, int>>(), 1.0f) );

84

}

84

}

85

85

86

template<typename _CharT, typename Range>

86

template<typename CharT, typename Range>

87

void test_output(bool mapIsDefault)

87

void test_output(bool mapIsDefault)

88

{

88

{

89

using Sv = std::basic_string_view<_CharT>;

89

using Sv = std::basic_string_view;

90

using Pt = std::ranges::range_value_t;

90

using Pt = std::ranges::range_value_t;

91

using Ft = std::remove_cvref_t<std::tuple_element_t<0, Pt>>;

91

using Ft = std::remove_cvref_t<std::tuple_element_t<0, Pt>>;

92

using St = std::remove_cvref_t<std::tuple_element_t<1, Pt>>;

92

using St = std::remove_cvref_t<std::tuple_element_t<1, Pt>>;

@@ -94,7 +94,7 @@ void test_output(bool mapIsDefault)

94

return Range(s.data(), s.data() + s.size());

94

return Range(s.data(), s.data() + s.size());

95

};

95

};

96

96

97

std::basic_string<_CharT> res;

97

std::basic_string res;

98

size_t size = 0;

98

size_t size = 0;

99

99

100

Ft f1[]{1, 2, 3};

100

Ft f1[]{1, 2, 3};

@@ -76,12 +76,12 @@ test_format_string()

76

}

76

}

77

77

78

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

78

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

79

#define WIDEN(S) WIDEN_(_CharT, S)

79

#define WIDEN(S) WIDEN_(CharT, S)

80

80

81

template<typename _CharT, typename Range, typename Storage>

81

template<typename CharT, typename Range, typename Storage>

82

void test_output()

82

void test_output()

83

{

83

{

84

using Sv = std::basic_string_view<_CharT>;

84

using Sv = std::basic_string_view;

85

using T = std::ranges::range_value_t;

85

using T = std::ranges::range_value_t;

86

auto makeRange = [](Storage& s) -> Range {

86

auto makeRange = [](Storage& s) -> Range {

87

if constexpr (std::is_same_v<std::remove_cvref_t, Storage>)

87

if constexpr (std::is_same_v<std::remove_cvref_t, Storage>)

@@ -91,7 +91,7 @@ void test_output()

91

std::ranges::data(s) + std::ranges::size(s));

91

std::ranges::data(s) + std::ranges::size(s));

92

};

92

};

93

93

94

std::basic_string<_CharT> res;

94

std::basic_string res;

95

size_t size = 0;

95

size_t size = 0;

96

96

97

Storage v1{1, 2, 3};

97

Storage v1{1, 2, 3};

@@ -48,7 +48,7 @@ bool is_range_formatter_spec_for(CharT const* spec, Rg&& rg)

48

}

48

}

49

49

50

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

50

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

51

#define WIDEN(S) WIDEN_(_CharT, S)

51

#define WIDEN(S) WIDEN_(CharT, S)

52

52

53

void

53

void

54

test_format_string()

54

test_format_string()

@@ -81,14 +81,14 @@ test_format_string()

81

template

81

template

82

void test_output()

82

void test_output()

83

{

83

{

84

using _CharT = std::ranges::range_value_t;

84

using CharT = std::ranges::range_value_t;

85

auto makeRange = [](std::basic_string<_CharT>& s) {

85

auto makeRange = [](std::basic_string& s) {

86

return Range(s.data(), s.data() + s.size());

86

return Range(s.data(), s.data() + s.size());

87

};

87

};

88

std::basic_string<_CharT> res;

88

std::basic_string res;

89

size_t size = 0;

89

size_t size = 0;

90

90

91

std::basic_string<_CharT> s1 = WIDEN("abcd");

91

std::basic_string s1 = WIDEN("abcd");

92

res = std::format(WIDEN("{}"), makeRange(s1));

92

res = std::format(WIDEN("{}"), makeRange(s1));

93

VERIFY( res == WIDEN("['a', 'b', 'c', 'd']") );

93

VERIFY( res == WIDEN("['a', 'b', 'c', 'd']") );

94

94

@@ -122,7 +122,7 @@ void test_output()

122

res = std::format(WIDEN("{:=^8s}"), makeRange(s1));

122

res = std::format(WIDEN("{:=^8s}"), makeRange(s1));

123

VERIFY( res == WIDEN("==abcd==") );

123

VERIFY( res == WIDEN("==abcd==") );

124

124

125

std::basic_string<_CharT> s2(512, static_cast<_CharT>('a'));

125

std::basic_string s2(512, static_cast('a'));

126

res = std::format(WIDEN("{:=^8s}"), makeRange(s2));

126

res = std::format(WIDEN("{:=^8s}"), makeRange(s2));

127

VERIFY( res == s2 );

127

VERIFY( res == s2 );

128

128

@@ -39,7 +39,7 @@ is_format_string_for(const wchar_t* str, Args&&... args)

39

}

39

}

40

40

41

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

41

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

42

#define WIDEN(S) WIDEN_(_CharT, S)

42

#define WIDEN(S) WIDEN_(CharT, S)

43

43

44

void

44

void

45

test_format_string()

45

test_format_string()

@@ -62,13 +62,13 @@ test_format_string()

62

VERIFY( !is_format_string_for("{:{}}", std::tuple<>(), 1.0f) );

62

VERIFY( !is_format_string_for("{:{}}", std::tuple<>(), 1.0f) );

63

}

63

}

64

64

65

template<typename _CharT>

65

template

66

void test_multi()

66

void test_multi()

67

{

67

{

68

using Sv = std::basic_string_view<_CharT>;

68

using Sv = std::basic_string_view;

69

using Str = std::basic_string<_CharT>;

69

using Str = std::basic_string;

70

70

71

std::basic_string<_CharT> res;

71

std::basic_string res;

72

std::size_t size = 0;

72

std::size_t size = 0;

73

std::tuple<int, Str, float> t1(1, WIDEN("test"), 2.1);

73

std::tuple<int, Str, float> t1(1, WIDEN("test"), 2.1);

74

74

@@ -122,10 +122,10 @@ void test_multi()

122

122

123

}

123

}

124

124

125

template<typename _CharT, typename Tuple>

125

template<typename CharT, typename Tuple>

126

void test_empty()

126

void test_empty()

127

{

127

{

128

std::basic_string<_CharT> res;

128

std::basic_string res;

129

129

130

Tuple e1;

130

Tuple e1;

131

res = std::format(WIDEN("{}"), e1);

131

res = std::format(WIDEN("{}"), e1);

@@ -141,13 +141,13 @@ void test_empty()

141

VERIFY( res == WIDEN(R"(^^^^())") );

141

VERIFY( res == WIDEN(R"(^^^^())") );

142

}

142

}

143

143

144

template<typename _CharT, typename Pair>

144

template<typename CharT, typename Pair>

145

void test_pair()

145

void test_pair()

146

{

146

{

147

using Ft = std::remove_cvref_t<std::tuple_element_t<0, Pair>>;

147

using Ft = std::remove_cvref_t<std::tuple_element_t<0, Pair>>;

148

using St = std::remove_cvref_t<std::tuple_element_t<1, Pair>>;

148

using St = std::remove_cvref_t<std::tuple_element_t<1, Pair>>;

149

149

150

std::basic_string<_CharT> res;

150

std::basic_string res;

151

151

152

Ft f1 = 1;

152

Ft f1 = 1;

153

St s1 = WIDEN("abc");

153

St s1 = WIDEN("abc");

@@ -187,7 +187,6 @@ struct std::formatter<MyPair, CharT>

187

{

187

{

188

constexpr formatter() noexcept

188

constexpr formatter() noexcept

189

{

189

{

190

using _CharT = CharT;

191

_formatter.set_brackets(WIDEN("<"), WIDEN(">"));

190

_formatter.set_brackets(WIDEN("<"), WIDEN(">"));

192

_formatter.set_separator(WIDEN("; "));

191

_formatter.set_separator(WIDEN("; "));

193

}

192

}

@@ -206,11 +205,11 @@ private:

206

std::formatter<Pair, CharT> _formatter;

205

std::formatter<Pair, CharT> _formatter;

207

};

206

};

208

207

209

template<typename _CharT, template<typename, typename> class PairT>

208

template<typename CharT, template<typename, typename> class PairT>

210

void test_custom()

209

void test_custom()

211

{

210

{

212

std::basic_string<_CharT> res;

211

std::basic_string res;

213

MyPair<PairT<int, const _CharT*>> c1(1, WIDEN("abc"));

212

MyPair<PairT<int, const CharT*>> c1(1, WIDEN("abc"));

214

213

215

res = std::format(WIDEN("{}"), c1);

214

res = std::format(WIDEN("{}"), c1);

216

VERIFY( res == WIDEN(R"(<1; "abc">)") );

215

VERIFY( res == WIDEN(R"(<1; "abc">)") );

@@ -10,7 +10,7 @@

10

using namespace std::chrono;

10

using namespace std::chrono;

11

11

12

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

12

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

13

#define WIDEN(S) WIDEN_(_CharT, S)

13

#define WIDEN(S) WIDEN_(CharT, S)

14

14

15

template<typename CharT, typename T>

15

template<typename CharT, typename T>

16

void

16

void

@@ -34,15 +34,15 @@ test_no_empty_spec()

34

}

34

}

35

}

35

}

36

36

37

template<typename T, typename _CharT>

37

template<typename T, typename CharT>

38

void verify(const T& t, std::basic_string_view<_CharT> str)

38

void verify(const T& t, std::basic_string_view str)

39

{

39

{

40

std::basic_string<_CharT> res;

40

std::basic_string res;

41

41

42

res = std::format(WIDEN("{}"), t);

42

res = std::format(WIDEN("{}"), t);

43

VERIFY( res == str );

43

VERIFY( res == str );

44

44

45

std::basic_stringstream<_CharT> os;

45

std::basic_stringstream os;

46

os << t;

46

os << t;

47

res = std::move(os).str();

47

res = std::move(os).str();

48

VERIFY( res == str );

48

VERIFY( res == str );

@@ -52,11 +52,11 @@ template<typename T, typename CharT>

52

void verify(const T& t, const CharT* str)

52

void verify(const T& t, const CharT* str)

53

{ verify(t, std::basic_string_view(str)); }

53

{ verify(t, std::basic_string_view(str)); }

54

54

55

template<typename _CharT>

55

template

56

void

56

void

57

test_padding()

57

test_padding()

58

{

58

{

59

std::basic_string<_CharT> res;

59

std::basic_string res;

60

60

61

res = std::format(WIDEN("{:5}"), day(2));

61

res = std::format(WIDEN("{:5}"), day(2));

62

VERIFY( res == WIDEN("02 ") );

62

VERIFY( res == WIDEN("02 ") );

@@ -114,9 +114,9 @@ struct Rep

114

114

115

friend auto operator<=>(Rep, Rep) = default;

115

friend auto operator<=>(Rep, Rep) = default;

116

116

117

template<typename _CharT>

117

template

118

friend std::basic_ostream<_CharT>&

118

friend std::basic_ostream&

119

operator<<(std::basic_ostream<_CharT>& os, const Rep& t)

119

operator<<(std::basic_ostream& os, const Rep& t)

120

{ return os << t.val << WIDEN("[via <<]"); }

120

{ return os << t.val << WIDEN("[via <<]"); }

121

121

122

long val;

122

long val;

@@ -140,27 +140,27 @@ struct std::numeric_limits<Rep>

140

: std::numeric_limits

140

: std::numeric_limits

141

{ };

141

{ };

142

142

143

template<typename Ret, typename _CharT>

143

template<typename Ret, typename CharT>

144

struct std::formatter<Rep, _CharT>

144

struct std::formatter<Rep, CharT>

145

: std::formatter<long, _CharT>

145

: std::formatter<long, CharT>

146

{

146

{

147

template

147

template

148

typename std::basic_format_context<Out, _CharT>::iterator

148

typename std::basic_format_context<Out, CharT>::iterator

149

format(const Rep& t, std::basic_format_context<Out, _CharT>& ctx) const

149

format(const Rep& t, std::basic_format_context<Out, CharT>& ctx) const

150

{

150

{

151

constexpr std::basic_string_view<_CharT> suffix = WIDEN("[via format]");

151

constexpr std::basic_string_view suffix = WIDEN("[via format]");

152

auto out = std::formatter<long, _CharT>::format(t.val, ctx);

152

auto out = std::formatter<long, CharT>::format(t.val, ctx);

153

return std::ranges::copy(suffix, out).out;

153

return std::ranges::copy(suffix, out).out;

154

}

154

}

155

};

155

};

156

156

157

using deciseconds = duration<seconds::rep, std::deci>;

157

using deciseconds = duration<seconds::rep, std::deci>;

158

158

159

template<typename _CharT>

159

template

160

void

160

void

161

test_duration()

161

test_duration()

162

{

162

{

163

std::basic_string<_CharT> res;

163

std::basic_string res;

164

164

165

const milliseconds di(40);

165

const milliseconds di(40);

166

verify( di, WIDEN("40ms") );

166

verify( di, WIDEN("40ms") );

@@ -172,11 +172,11 @@ test_duration()

172

VERIFY( res == WIDEN(" -40ms") );

172

VERIFY( res == WIDEN(" -40ms") );

173

}

173

}

174

174

175

template<typename _CharT>

175

template

176

void

176

void

177

test_duration_fp()

177

test_duration_fp()

178

{

178

{

179

std::basic_string<_CharT> res;

179

std::basic_string res;

180

180

181

const duration df(11.22);

181

const duration df(11.22);

182

verify( df, WIDEN("11.22s") );

182

verify( df, WIDEN("11.22s") );

@@ -192,11 +192,11 @@ test_duration_fp()

192

VERIFY( res == WIDEN("11.22s") );

192

VERIFY( res == WIDEN("11.22s") );

193

}

193

}

194

194

195

template<typename _CharT>

195

template

196

void

196

void

197

test_duration_cust()

197

test_duration_cust()

198

{

198

{

199

std::basic_string<_CharT> res;

199

std::basic_string res;

200

const duration<char, std::ratio<1, 10>> charRep(123);

200

const duration<char, std::ratio<1, 10>> charRep(123);

201

verify( charRep, WIDEN("123ds") );

201

verify( charRep, WIDEN("123ds") );

202

202

@@ -253,7 +253,7 @@ hms(const duration<Rep, Period>& d)

253

return hh_mm_ss(duration_cast(d));

253

return hh_mm_ss(duration_cast(d));

254

}

254

}

255

255

256

template<typename _CharT>

256

template

257

void

257

void

258

test_hh_mm_ss()

258

test_hh_mm_ss()

259

{

259

{

@@ -303,7 +303,7 @@ test_hh_mm_ss()

303

WIDEN("-14322:24:54.111222333") );

303

WIDEN("-14322:24:54.111222333") );

304

}

304

}

305

305

306

template<typename _CharT>

306

template

307

void

307

void

308

test_hh_mm_ss_fp()

308

test_hh_mm_ss_fp()

309

{

309

{

@@ -341,7 +341,7 @@ test_hh_mm_ss_fp()

341

WIDEN("-22:24:54") );

341

WIDEN("-22:24:54") );

342

}

342

}

343

343

344

template<typename _CharT>

344

template

345

void

345

void

346

test_hh_mm_ss_cust()

346

test_hh_mm_ss_cust()

347

{

347

{

@@ -396,7 +396,7 @@ test_durations()

396

test_hh_mm_ss_cust();

396

test_hh_mm_ss_cust();

397

}

397

}

398

398

399

template<typename _CharT>

399

template

400

void

400

void

401

test_day()

401

test_day()

402

{

402

{

@@ -408,7 +408,7 @@ test_day()

408

verify( day(255), WIDEN("255 is not a valid day") );

408

verify( day(255), WIDEN("255 is not a valid day") );

409

}

409

}

410

410

411

template<typename _CharT>

411

template

412

void

412

void

413

test_month()

413

test_month()

414

{

414

{

@@ -422,7 +422,7 @@ test_month()

422

verify( month(255), WIDEN("255 is not a valid month") );

422

verify( month(255), WIDEN("255 is not a valid month") );

423

}

423

}

424

424

425

template<typename _CharT>

425

template

426

void

426

void

427

test_year()

427

test_year()

428

{

428

{

@@ -437,7 +437,7 @@ test_year()

437

verify( year(32767), WIDEN( "32767") );

437

verify( year(32767), WIDEN( "32767") );

438

}

438

}

439

439

440

template<typename _CharT>

440

template

441

void

441

void

442

test_weekday()

442

test_weekday()

443

{

443

{

@@ -451,7 +451,7 @@ test_weekday()

451

verify( weekday(255), WIDEN("255 is not a valid weekday") );

451

verify( weekday(255), WIDEN("255 is not a valid weekday") );

452

}

452

}

453

453

454

template<typename _CharT>

454

template

455

void

455

void

456

test_weekday_indexed()

456

test_weekday_indexed()

457

{

457

{

@@ -466,7 +466,7 @@ test_weekday_indexed()

466

verify( weekday(32)[7], WIDEN("32 is not a valid weekday[7 is not a valid index]") );

466

verify( weekday(32)[7], WIDEN("32 is not a valid weekday[7 is not a valid index]") );

467

}

467

}

468

468

469

template<typename _CharT>

469

template

470

void

470

void

471

test_weekday_last()

471

test_weekday_last()

472

{

472

{

@@ -474,7 +474,7 @@ test_weekday_last()

474

verify( weekday(9)[last], WIDEN("9 is not a valid weekday[last]") );

474

verify( weekday(9)[last], WIDEN("9 is not a valid weekday[last]") );

475

}

475

}

476

476

477

template<typename _CharT>

477

template

478

void

478

void

479

test_month_day()

479

test_month_day()

480

{

480

{

@@ -484,7 +484,7 @@ test_month_day()

484

verify( month(13)/32, WIDEN("13 is not a valid month/32 is not a valid day") );

484

verify( month(13)/32, WIDEN("13 is not a valid month/32 is not a valid day") );

485

}

485

}

486

486

487

template<typename _CharT>

487

template

488

void

488

void

489

test_month_day_last()

489

test_month_day_last()

490

{

490

{

@@ -492,7 +492,7 @@ test_month_day_last()

492

verify( month(14)/last, WIDEN("14 is not a valid month/last") );

492

verify( month(14)/last, WIDEN("14 is not a valid month/last") );

493

}

493

}

494

494

495

template<typename _CharT>

495

template

496

void

496

void

497

test_month_weekday()

497

test_month_weekday()

498

{

498

{

@@ -508,7 +508,7 @@ test_month_weekday()

508

WIDEN("13 is not a valid month/130 is not a valid weekday[0 is not a valid index]") );

508

WIDEN("13 is not a valid month/130 is not a valid weekday[0 is not a valid index]") );

509

}

509

}

510

510

511

template<typename _CharT>

511

template

512

void

512

void

513

test_month_weekday_last()

513

test_month_weekday_last()

514

{

514

{

@@ -522,7 +522,7 @@ test_month_weekday_last()

522

WIDEN("13 is not a valid month/10 is not a valid weekday[last]") );

522

WIDEN("13 is not a valid month/10 is not a valid weekday[last]") );

523

}

523

}

524

524

525

template<typename _CharT>

525

template

526

void

526

void

527

test_year_month()

527

test_year_month()

528

{

528

{

@@ -536,7 +536,7 @@ test_year_month()

536

WIDEN("-32768 is not a valid year/0 is not a valid month") );

536

WIDEN("-32768 is not a valid year/0 is not a valid month") );

537

}

537

}

538

538

539

template<typename _CharT>

539

template

540

void

540

void

541

test_year_month_day()

541

test_year_month_day()

542

{

542

{

@@ -556,7 +556,7 @@ test_year_month_day()

556

WIDEN("-32768-14-55 is not a valid date") );

556

WIDEN("-32768-14-55 is not a valid date") );

557

}

557

}

558

558

559

template<typename _CharT>

559

template

560

void

560

void

561

test_year_month_last()

561

test_year_month_last()

562

{

562

{

@@ -570,7 +570,7 @@ test_year_month_last()

570

WIDEN("-32768 is not a valid year/0 is not a valid month/last") );

570

WIDEN("-32768 is not a valid year/0 is not a valid month/last") );

571

}

571

}

572

572

573

template<typename _CharT>

573

template

574

void

574

void

575

test_year_month_weekday()

575

test_year_month_weekday()

576

{

576

{

@@ -586,7 +586,7 @@ test_year_month_weekday()

586

WIDEN("-32768 is not a valid year/13 is not a valid month/130 is not a valid weekday[0 is not a valid index]") );

586

WIDEN("-32768 is not a valid year/13 is not a valid month/130 is not a valid weekday[0 is not a valid index]") );

587

}

587

}

588

588

589

template<typename _CharT>

589

template

590

void

590

void

591

test_year_month_weekday_last()

591

test_year_month_weekday_last()

592

{

592

{

@@ -644,14 +644,14 @@ wall_cast(const local_time& tp)

644

using decadays = duration<days::rep, std::ratio_multiply<std::deca, days::period>>;

644

using decadays = duration<days::rep, std::ratio_multiply<std::deca, days::period>>;

645

using kilodays = duration<days::rep, std::ratio_multiply<std::kilo, days::period>>;

645

using kilodays = duration<days::rep, std::ratio_multiply<std::kilo, days::period>>;

646

646

647

template<typename _CharT, typename Clock>

647

template<typename CharT, typename Clock>

648

void

648

void

649

test_time_point(bool daysAsTime)

649

test_time_point(bool daysAsTime)

650

{

650

{

651

std::basic_string<_CharT> res;

651

std::basic_string res;

652

652

653

const auto lt = local_days(2024y/March/22) + 13h + 24min + 54s + 111222333ns;

653

const auto lt = local_days(2024y/March/22) + 13h + 24min + 54s + 111222333ns;

654

auto strip_time = [daysAsTime](std::basic_string_view<_CharT> sv)

654

auto strip_time = [daysAsTime](std::basic_string_view sv)

655

{ return daysAsTime ? sv : sv.substr(0, 10); };

655

{ return daysAsTime ? sv : sv.substr(0, 10); };

656

656

657

verify( wall_cast<Clock, nanoseconds>(lt),

657

verify( wall_cast<Clock, nanoseconds>(lt),

@@ -674,11 +674,11 @@ test_time_point(bool daysAsTime)

674

strip_time(WIDEN("2022-01-08 00:00:00")) );

674

strip_time(WIDEN("2022-01-08 00:00:00")) );

675

}

675

}

676

676

677

template<typename _CharT>

677

template

678

void

678

void

679

test_leap_second()

679

test_leap_second()

680

{

680

{

681

std::basic_string<_CharT> res;

681

std::basic_string res;

682

682

683

const auto st = sys_days(2012y/June/30) + 23h + 59min + 59s + 111222333ns;

683

const auto st = sys_days(2012y/June/30) + 23h + 59min + 59s + 111222333ns;

684

auto tp = clock_cast<utc_clock>(st);

684

auto tp = clock_cast<utc_clock>(st);

@@ -700,7 +700,7 @@ auto

700

make_zoned(const sys_time& st, const time_zone* tz)

700

make_zoned(const sys_time& st, const time_zone* tz)

701

{ return zoned_time(tz, floor(st)); }

701

{ return zoned_time(tz, floor(st)); }

702

702

703

template<typename _CharT>

703

template

704

void

704

void

705

test_zoned_time()

705

test_zoned_time()

706

{

706

{

@@ -734,11 +734,11 @@ auto

734

local_fmt(const local_time& lt, std::string* zone)

734

local_fmt(const local_time& lt, std::string* zone)

735

{ return local_time_format(floor(lt), zone); }

735

{ return local_time_format(floor(lt), zone); }

736

736

737

template<typename _CharT>

737

template

738

void

738

void

739

test_local_time_format()

739

test_local_time_format()

740

{

740

{

741

std::basic_string<_CharT> res;

741

std::basic_string res;

742

742

743

std::string abbrev = "Zone";

743

std::string abbrev = "Zone";

744

const auto lt = local_days(2024y/March/22) + 13h + 24min + 54s + 111222333ns;

744

const auto lt = local_days(2024y/March/22) + 13h + 24min + 54s + 111222333ns;

@@ -784,7 +784,7 @@ test_time_points()

784

}

784

}

785

785

786

#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI

786

#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI

787

template<typename _CharT>

787

template

788

void

788

void

789

test_sys_info()

789

test_sys_info()

790

{

790

{

@@ -796,13 +796,13 @@ test_sys_info()

796

15min,

796

15min,

797

"Zone"

797

"Zone"

798

};

798

};

799

const std::basic_string_view<_CharT> txt

799

const std::basic_string_view txt

800

= WIDEN("[2024-03-22 02:00:00,2025-04-11 23:15:10,02:13:04,15min,Zone]");

800

= WIDEN("[2024-03-22 02:00:00,2025-04-11 23:15:10,02:13:04,15min,Zone]");

801

801

802

verify( si, txt );

802

verify( si, txt );

803

803

804

std::basic_string<_CharT> res;

804

std::basic_string res;

805

std::basic_string_view<_CharT> sv;

805

std::basic_string_view sv;

806

806

807

sv = res = std::format(WIDEN("{:65}"), si);

807

sv = res = std::format(WIDEN("{:65}"), si);

808

VERIFY( sv.ends_with(WIDEN(" ")) );

808

VERIFY( sv.ends_with(WIDEN(" ")) );

@@ -817,11 +817,11 @@ test_sys_info()

817

VERIFY( sv == txt );

817

VERIFY( sv == txt );

818

}

818

}

819

819

820

template<typename _CharT>

820

template

821

void test_local_info()

821

void test_local_info()

822

{

822

{

823

using String = std::basic_string<_CharT>;

823

using String = std::basic_string;

824

using StringView = std::basic_string_view<_CharT>;

824

using StringView = std::basic_string_view;

825

825

826

const sys_info s1

826

const sys_info s1

827

{

827

{

@@ -7,13 +7,13 @@

7

#include <testsuite_hooks.h>

7

#include <testsuite_hooks.h>

8

8

9

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

9

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

10

#define WIDEN(S) WIDEN_(_CharT, S)

10

#define WIDEN(S) WIDEN_(CharT, S)

11

11

12

template<typename _CharT>

12

template

13

void

13

void

14

test_from_format_string()

14

test_from_format_string()

15

{

15

{

16

std::basic_string<_CharT> res;

16

std::basic_string res;

17

using namespace std::chrono_literals;

17

using namespace std::chrono_literals;

18

auto date = 2025y/std::chrono::May/05d;

18

auto date = 2025y/std::chrono::May/05d;

19

19

@@ -27,24 +27,24 @@ test_from_format_string()

27

VERIFY( res == WIDEN("====2025-05-05\U0001f921====") );

27

VERIFY( res == WIDEN("====2025-05-05\U0001f921====") );

28

}

28

}

29

29

30

template<typename _CharT>

30

template

31

void

31

void

32

test_formatted_value()

32

test_formatted_value()

33

{

33

{

34

// Custom time_put facet which returns Ideographic Telegraph Symbol

34

// Custom time_put facet which returns Ideographic Telegraph Symbol

35

// for given month for Om.

35

// for given month for Om.

36

struct TimePut : std::time_put<_CharT>

36

struct TimePut : std::time_put

37

{

37

{

38

using iter_type = std::time_put<_CharT>::iter_type;

38

using iter_type = std::time_put::iter_type;

39

using char_type = std::time_put<_CharT>::char_type;

39

using char_type = std::time_put::char_type;

40

40

41

iter_type

41

iter_type

42

do_put(iter_type out, std::ios_base& io, char_type fill, const tm* t,

42

do_put(iter_type out, std::ios_base& io, char_type fill, const tm* t,

43

char format, char modifier) const override

43

char format, char modifier) const override

44

{

44

{

45

if (format != 'm' && modifier != 'm')

45

if (format != 'm' && modifier != 'm')

46

return std::time_put<_CharT>::do_put(out, io, fill, t, format, modifier);

46

return std::time_put::do_put(out, io, fill, t, format, modifier);

47

std::basic_string_view<_CharT> str;

47

std::basic_string_view str;

48

switch (t->tm_mon)

48

switch (t->tm_mon)

49

{

49

{

50

case 0:

50

case 0:

@@ -89,7 +89,7 @@ test_formatted_value()

89

};

89

};

90

const std::locale loc(std::locale::classic(), new TimePut);

90

const std::locale loc(std::locale::classic(), new TimePut);

91

91

92

std::basic_string<_CharT> res;

92

std::basic_string res;

93

93

94

res = std::format(loc, WIDEN("{:<1L%Om}"), std::chrono::January);

94

res = std::format(loc, WIDEN("{:<1L%Om}"), std::chrono::January);

95

VERIFY( res == WIDEN("\u32C0") );

95

VERIFY( res == WIDEN("\u32C0") );

@@ -7,15 +7,15 @@

7

#include <testsuite_hooks.h>

7

#include <testsuite_hooks.h>

8

8

9

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

9

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

10

#define WIDEN(S) WIDEN_(_CharT, S)

10

#define WIDEN(S) WIDEN_(CharT, S)

11

11

12

using namespace std::chrono;

12

using namespace std::chrono;

13

13

14

template<typename _CharT>

14

template

15

void

15

void

16

test_year()

16

test_year()

17

{

17

{

18

std::basic_string<_CharT> res;

18

std::basic_string res;

19

19

20

res = std::format(WIDEN("{:%Y}"), year(0));

20

res = std::format(WIDEN("{:%Y}"), year(0));

21

VERIFY( res == WIDEN("0000") );

21

VERIFY( res == WIDEN("0000") );

@@ -77,11 +77,11 @@ test_year()

77

VERIFY( res == WIDEN("01") );

77

VERIFY( res == WIDEN("01") );

78

}

78

}

79

79

80

template<typename _CharT>

80

template

81

void

81

void

82

test_month()

82

test_month()

83

{

83

{

84

std::basic_string<_CharT> res;

84

std::basic_string res;

85

85

86

res = std::format(WIDEN("{:%m}"), month(5));

86

res = std::format(WIDEN("{:%m}"), month(5));

87

VERIFY( res == WIDEN("05") );

87

VERIFY( res == WIDEN("05") );

@@ -93,11 +93,11 @@ test_month()

93

VERIFY( res == WIDEN("254") );

93

VERIFY( res == WIDEN("254") );

94

}

94

}

95

95

96

template<typename _CharT>

96

template

97

void

97

void

98

test_day()

98

test_day()

99

{

99

{

100

std::basic_string<_CharT> res;

100

std::basic_string res;

101

101

102

res = std::format(WIDEN("{:%d}"), day(3));

102

res = std::format(WIDEN("{:%d}"), day(3));

103

VERIFY( res == WIDEN("03") );

103

VERIFY( res == WIDEN("03") );

@@ -118,11 +118,11 @@ test_day()

118

VERIFY( res == WIDEN("214") );

118

VERIFY( res == WIDEN("214") );

119

}

119

}

120

120

121

template<typename _CharT>

121

template

122

void

122

void

123

test_date()

123

test_date()

124

{

124

{

125

std::basic_string<_CharT> res;

125

std::basic_string res;

126

126

127

res = std::format(WIDEN("{:%F}"), year(-22)/month(10)/day(20));

127

res = std::format(WIDEN("{:%F}"), year(-22)/month(10)/day(20));

128

VERIFY( res == WIDEN("-0022-10-20") );

128

VERIFY( res == WIDEN("-0022-10-20") );

@@ -145,11 +145,11 @@ test_date()

145

VERIFY( res == WIDEN("220/100/00") );

145

VERIFY( res == WIDEN("220/100/00") );

146

}

146

}

147

147

148

template<typename _CharT>

148

template

149

void

149

void

150

test_weekday()

150

test_weekday()

151

{

151

{

152

std::basic_string<_CharT> res;

152

std::basic_string res;

153

153

154

res = std::format(WIDEN("{:%w}"), weekday(0));

154

res = std::format(WIDEN("{:%w}"), weekday(0));

155

VERIFY( res == WIDEN("0") );

155

VERIFY( res == WIDEN("0") );

@@ -187,11 +187,11 @@ test_weekday()

187

VERIFY( res == WIDEN("202") );

187

VERIFY( res == WIDEN("202") );

188

}

188

}

189

189

190

template<typename _CharT>

190

template

191

void

191

void

192

test_hour()

192

test_hour()

193

{

193

{

194

std::basic_string<_CharT> res;

194

std::basic_string res;

195

195

196

res = std::format(WIDEN("{:%H}"), 0h + 5min + 6s);

196

res = std::format(WIDEN("{:%H}"), 0h + 5min + 6s);

197

VERIFY( res == WIDEN("00") );

197

VERIFY( res == WIDEN("00") );

@@ -7,13 +7,13 @@

7

using namespace std::chrono;

7

using namespace std::chrono;

8

8

9

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

9

#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S)

10

#define WIDEN(S) WIDEN_(_CharT, S)

10

#define WIDEN(S) WIDEN_(CharT, S)

11

11

12

template<typename _CharT>

12

template

13

void

13

void

14

test_empty()

14

test_empty()

15

{

15

{

16

std::basic_string<_CharT> res;

16

std::basic_string res;

17

17

18

const duration d(33.111222);

18

const duration d(33.111222);

19

res = std::format(WIDEN("{:.3}"), d);

19

res = std::format(WIDEN("{:.3}"), d);

@@ -33,11 +33,11 @@ test_empty()

33

VERIFY( res == WIDEN("3.31112e+10ns") );

33

VERIFY( res == WIDEN("3.31112e+10ns") );

34

}

34

}

35

35

36

template<typename _CharT>

36

template

37

void

37

void

38

test_Q()

38

test_Q()

39

{

39

{

40

std::basic_string<_CharT> res;

40

std::basic_string res;

41

41

42

const duration d(7.111222);

42

const duration d(7.111222);

43

res = std::format(WIDEN("{:.3%Q}"), d);

43

res = std::format(WIDEN("{:.3%Q}"), d);

@@ -56,11 +56,11 @@ test_Q()

56

VERIFY( res == WIDEN("7111222000") );

56

VERIFY( res == WIDEN("7111222000") );

57

}

57

}

58

58

59

template<typename _CharT>

59

template

60

void

60

void

61

test_S()

61

test_S()

62

{

62

{

63

std::basic_string<_CharT> res;

63

std::basic_string res;

64

64

65

// Precision is ignored, but period affects output

65

// Precision is ignored, but period affects output

66

const duration d(5.111222);

66

const duration d(5.111222);