/
test_to_wstring.cpp
424 lines (334 loc) · 27.6 KB
/
test_to_wstring.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2019 jwellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include "UnitTest++.h"
#include <ostream>
#include <sstream>
#include <iomanip>
#include "etl/to_wstring.h"
#include "etl/wstring.h"
#include "etl/format_spec.h"
#undef STR
#define STR(x) L##x
namespace
{
typedef etl::wformat_spec Format;
std::ostream& operator << (std::ostream& os, const etl::iwstring& str)
{
for (auto c : str)
{
os << c;
}
return os;
}
SUITE(test_to_wstring)
{
//*************************************************************************
TEST(test_default_format_no_append)
{
etl::wstring<20> str;
CHECK_EQUAL(etl::wstring<20>(STR("0")), etl::to_string(uint8_t(0), str));
CHECK_EQUAL(etl::wstring<20>(STR("0")), etl::to_string(uint16_t(0), str));
CHECK_EQUAL(etl::wstring<20>(STR("0")), etl::to_string(uint32_t(0), str));
CHECK_EQUAL(etl::wstring<20>(STR("0")), etl::to_string(uint64_t(0), str));
CHECK_EQUAL(etl::wstring<20>(STR("128")), etl::to_string(uint8_t(128), str));
CHECK_EQUAL(etl::wstring<20>(STR("32768")), etl::to_string(uint16_t(32768), str));
CHECK_EQUAL(etl::wstring<20>(STR("2147483648")), etl::to_string(uint32_t(2147483648ul), str));
CHECK_EQUAL(etl::wstring<20>(STR("9223372036854775808")), etl::to_string(uint64_t(9223372036854775808ull), str));
CHECK_EQUAL(etl::wstring<20>(STR("127")), etl::to_string(int8_t(127), str));
CHECK_EQUAL(etl::wstring<20>(STR("32767")), etl::to_string(int16_t(32767), str));
CHECK_EQUAL(etl::wstring<20>(STR("2147483647")), etl::to_string(int32_t(2147483647ll), str));
CHECK_EQUAL(etl::wstring<20>(STR("9223372036854775807")), etl::to_string(int64_t(9223372036854775807ll), str));
CHECK_EQUAL(etl::wstring<20>(STR("-128")), etl::to_string(int8_t(-128), str));
CHECK_EQUAL(etl::wstring<20>(STR("-32768")), etl::to_string(int16_t(-32768), str));
CHECK_EQUAL(etl::wstring<20>(STR("-2147483648")), etl::to_string(int32_t(-2147483648ll), str));
CHECK_EQUAL(etl::wstring<20>(STR("-9223372036854775808")), etl::to_string(int64_t(-9223372036854775807ll - 1), str));
}
//*************************************************************************
TEST(test_default_format_append)
{
etl::wstring<120> str;
CHECK_EQUAL(etl::wstring<120>(STR("0")), etl::to_string(uint8_t(0), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("00")), etl::to_string(uint16_t(0), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000")), etl::to_string(uint32_t(0), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("0000")), etl::to_string(uint64_t(0), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("0000128")), etl::to_string(uint8_t(128), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000012832768")), etl::to_string(uint16_t(32768), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("0000128327682147483648")), etl::to_string(uint32_t(2147483648ul), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("00001283276821474836489223372036854775808")), etl::to_string(uint64_t(9223372036854775808ull), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("00001283276821474836489223372036854775808127")), etl::to_string(int8_t(127), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("0000128327682147483648922337203685477580812732767")), etl::to_string(int16_t(32767), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("00001283276821474836489223372036854775808127327672147483647")), etl::to_string(int32_t(2147483647ll), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")), etl::to_string(int64_t(9223372036854775807ll), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")), etl::to_string(int8_t(-128), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")), etl::to_string(int16_t(-32768), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")), etl::to_string(int32_t(-2147483648ll), str, true));
CHECK_EQUAL(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")), etl::to_string(int64_t(-9223372036854775807ll - 1), str, true));
}
//*************************************************************************
TEST(test_format_right_justified_no_append)
{
etl::wstring<20> str;
Format format = Format().base(10).width(20).fill(STR('#'));
CHECK_EQUAL(etl::wstring<20>(STR("###################0")), etl::to_string(uint8_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("###################0")), etl::to_string(uint16_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("###################0")), etl::to_string(uint32_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("###################0")), etl::to_string(uint64_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("#################128")), etl::to_string(uint8_t(128), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("###############32768")), etl::to_string(uint16_t(32768), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("##########2147483648")), etl::to_string(uint32_t(2147483648ul), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("#9223372036854775808")), etl::to_string(uint64_t(9223372036854775808ull), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("#################127")), etl::to_string(int8_t(127), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("###############32767")), etl::to_string(int16_t(32767), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("##########2147483647")), etl::to_string(int32_t(2147483647ll), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("#9223372036854775807")), etl::to_string(int64_t(9223372036854775807ll), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("################-128")), etl::to_string(int8_t(-128), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("##############-32768")), etl::to_string(int16_t(-32768), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("#########-2147483648")), etl::to_string(int32_t(-2147483648ll), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("-9223372036854775808")), etl::to_string(int64_t(-9223372036854775807ll - 1), str, format));
}
//*************************************************************************
TEST(test_format_left_justified_no_append)
{
etl::wstring<20> str;
Format format = Format().base(10).width(20).fill(STR('#')).left();
CHECK_EQUAL(etl::wstring<20>(STR("0###################")), etl::to_string(uint8_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("0###################")), etl::to_string(uint16_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("0###################")), etl::to_string(uint32_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("0###################")), etl::to_string(uint64_t(0), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("128#################")), etl::to_string(uint8_t(128), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("32768###############")), etl::to_string(uint16_t(32768), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("2147483648##########")), etl::to_string(uint32_t(2147483648ul), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("9223372036854775808#")), etl::to_string(uint64_t(9223372036854775808ull), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("127#################")), etl::to_string(int8_t(127), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("32767###############")), etl::to_string(int16_t(32767), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("2147483647##########")), etl::to_string(int32_t(2147483647ll), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("9223372036854775807#")), etl::to_string(int64_t(9223372036854775807ll), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("-128################")), etl::to_string(int8_t(-128), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("-32768##############")), etl::to_string(int16_t(-32768), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("-2147483648#########")), etl::to_string(int32_t(-2147483648ll), str, format));
CHECK_EQUAL(etl::wstring<20>(STR("-9223372036854775808")), etl::to_string(int64_t(-9223372036854775807ll - 1), str, format));
}
//*************************************************************************
TEST(test_binary_format_no_append)
{
etl::wstring<64> str;
CHECK_EQUAL(etl::wstring<64>(STR("00000000")), etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("0000000000000000")), etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("00000000000000000000000000000000")), etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("0000000000000000000000000000000000000000000000000000000000000000")), etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("10000000")), etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("1000000000000000")), etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("10000000000000000000000000000000")), etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")), etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(2).width(64).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("01111111")), etl::to_string(int8_t(127), str, Format().base(2).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("0111111111111111")), etl::to_string(int16_t(32767), str, Format().base(2).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("01111111111111111111111111111111")), etl::to_string(int32_t(2147483647ll), str, Format().base(2).width(32).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")), etl::to_string(int64_t(9223372036854775807ll), str, Format().base(2).width(64).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("10000000")), etl::to_string(int8_t(-128), str, Format().base(2).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("1000000000000000")), etl::to_string(int16_t(-32768), str, Format().base(2).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("10000000000000000000000000000000")), etl::to_string(int32_t(-2147483648ll), str, Format().base(2).width(32).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")), etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(2).width(64).fill(STR('0'))));
}
//*************************************************************************
TEST(test_octal_format_no_append)
{
etl::wstring<22> str;
CHECK_EQUAL(etl::wstring<22>(STR("000")), etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("000000")), etl::to_string(uint16_t(0), str, Format().base(8).width(6).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("00000000000")), etl::to_string(uint32_t(0), str, Format().base(8).width(11).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("0000000000000000000000")), etl::to_string(uint64_t(0), str, Format().base(8).width(22).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("200")), etl::to_string(uint8_t(128), str, Format().base(8).width(3).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("100000")), etl::to_string(uint16_t(32768), str, Format().base(8).width(6).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("20000000000")), etl::to_string(uint32_t(2147483648ul), str, Format().base(8).width(11).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("1000000000000000000000")), etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(8).width(22).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("177")), etl::to_string(int8_t(127), str, Format().base(8).width(3).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("077777")), etl::to_string(int16_t(32767), str, Format().base(8).width(6).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("17777777777")), etl::to_string(int32_t(2147483647ll), str, Format().base(8).width(11).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("0777777777777777777777")), etl::to_string(int64_t(9223372036854775807ll), str, Format().base(8).width(22).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("200")), etl::to_string(int8_t(-128), str, Format().base(8).width(3).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("100000")), etl::to_string(int16_t(-32768), str, Format().base(8).width(6).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("20000000000")), etl::to_string(int32_t(-2147483648ll), str, Format().base(8).width(11).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<22>(STR("1000000000000000000000")), etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(8).width(22).fill(STR('0'))));
}
//*************************************************************************
TEST(test_hex_format_no_append)
{
etl::wstring<16> str;
CHECK_EQUAL(etl::wstring<16>(STR("00")), etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("0000")), etl::to_string(uint16_t(0), str, Format().base(16).width(4).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("00000000")), etl::to_string(uint32_t(0), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("0000000000000000")), etl::to_string(uint64_t(0), str, Format().base(16).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("80")), etl::to_string(uint8_t(128), str, Format().base(16).width(2).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("8000")), etl::to_string(uint16_t(32768), str, Format().base(16).width(4).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("80000000")), etl::to_string(uint32_t(2147483648ul), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("8000000000000000")), etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(16).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("7F")), etl::to_string(int8_t(127), str, Format().base(16).width(2).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("7FFF")), etl::to_string(int16_t(32767), str, Format().base(16).width(4).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("7FFFFFFF")), etl::to_string(int32_t(2147483647ll), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("7FFFFFFFFFFFFFFF")), etl::to_string(int64_t(9223372036854775807ll), str, Format().base(16).width(16).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("80")), etl::to_string(int8_t(-128), str, Format().base(16).width(2).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("8000")), etl::to_string(int16_t(-32768), str, Format().base(16).width(4).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("80000000")), etl::to_string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0'))));
CHECK_EQUAL(etl::wstring<16>(STR("8000000000000000")), etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(16).width(16).fill(STR('0'))));
}
//*************************************************************************
TEST(test_named_format_no_append)
{
etl::wstring<17> str;
CHECK_EQUAL(etl::wstring<17>(STR("11110001001000000")), etl::to_string(123456, str, Format().binary()));
CHECK_EQUAL(etl::wstring<17>(STR("361100")), etl::to_string(123456, str, Format().octal()));
CHECK_EQUAL(etl::wstring<17>(STR("123456")), etl::to_string(123456, str, Format().decimal()));
CHECK_EQUAL(etl::wstring<17>(STR("1E240")), etl::to_string(123456, str, Format().hex()));
}
//*************************************************************************
TEST(test_floating_point_no_append)
{
etl::wstring<20> str;
CHECK_EQUAL(etl::wstring<20>(STR(" 0.000000")), etl::to_string(0.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.000000 ")), etl::to_string(0.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 0.000001")), etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.000001 ")), etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 1.000000")), etl::to_string(1.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("1.000000 ")), etl::to_string(1.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 1.000001")), etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("1.000001 ")), etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
CHECK_EQUAL(etl::wstring<20>(STR("-12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
}
//*************************************************************************
TEST(test_floating_point_append)
{
etl::wstring<20> str;
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result -12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
}
//*************************************************************************
TEST(test_floating_point_rounding)
{
etl::wstring<20> str;
CHECK_EQUAL(etl::wstring<20>(STR("0.00001")), etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.0001")), etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.001")), etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.01")), etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.1")), etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
CHECK_EQUAL(etl::wstring<20>(STR("1.0")), etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
CHECK_EQUAL(etl::wstring<20>(STR("1")), etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
CHECK_EQUAL(etl::wstring<20>(STR("10.0")), etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
CHECK_EQUAL(etl::wstring<20>(STR("2")), etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
CHECK_EQUAL(etl::wstring<20>(STR("10.0")), etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
CHECK_EQUAL(etl::wstring<20>(STR("20.0")), etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
}
//*************************************************************************
TEST(test_bool_no_append)
{
etl::wstring<20> str;
CHECK_EQUAL(etl::wstring<20>(STR(" 0")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
CHECK_EQUAL(etl::wstring<20>(STR(" 1")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
CHECK_EQUAL(etl::wstring<20>(STR("0 ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
CHECK_EQUAL(etl::wstring<20>(STR("1 ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
CHECK_EQUAL(etl::wstring<20>(STR(" false")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
CHECK_EQUAL(etl::wstring<20>(STR(" true")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
CHECK_EQUAL(etl::wstring<20>(STR("false ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
CHECK_EQUAL(etl::wstring<20>(STR("true ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
}
//*************************************************************************
TEST(test_bool_append)
{
etl::wstring<20> str;
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result 0")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result 1")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result 0 ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result 1 ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result false")), to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result true")), to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result false ")), to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
str.assign(STR("Result "));
CHECK_EQUAL(etl::wstring<20>(STR("Result true ")), to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
}
//*************************************************************************
TEST(test_pointer_no_append)
{
etl::wstring<20> str;
static const volatile int cvi = 0;
std::wostringstream oss;
oss.width(10);
oss.fill(STR('0'));
oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi);
std::wstring temp(oss.str());
etl::wstring<20> compare(temp.begin(), temp.end());
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')));
CHECK_EQUAL(compare, str);
oss.clear();
oss.str(STR(""));
oss.width(10);
oss.fill(STR('0'));
oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi);
temp = oss.str();
compare.assign(temp.begin(), temp.end());
to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')));
CHECK_EQUAL(compare, str);
}
//*************************************************************************
TEST(test_pointer_append)
{
etl::wstring<20> str;
static const volatile int cvi = 0;
std::wostringstream oss;
oss.width(10);
oss.fill(STR('0'));
oss << std::hex << std::uppercase << std::right << uintptr_t(&cvi);
std::wstring temp(STR("Result "));
temp.append(oss.str());
etl::wstring<20> compare(temp.begin(), temp.end());
str.assign(STR("Result "));
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')), true);
CHECK_EQUAL(compare, str);
oss.clear();
oss.str(STR(""));
oss.width(10);
oss.fill(STR('0'));
oss << std::hex << std::uppercase << std::left << uintptr_t(&cvi);
temp = STR("Result ");
temp.append(oss.str());
compare.assign(temp.begin(), temp.end());
str.assign(STR("Result "));
to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true);
CHECK_EQUAL(compare, str);
}
};
}