File: test_message.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (668 lines) | stat: -rw-r--r-- 25,549 bytes parent folder | download | duplicates (3)
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
// Copyright (c) 2021-2023 Alexander Grund
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/locale/encoding.hpp>
#include <boost/locale/generator.hpp>
#include <boost/locale/gnu_gettext.hpp>
#include <boost/locale/localization_backend.hpp>
#include <boost/locale/message.hpp>
#include "boostLocale/test/tools.hpp"
#include "boostLocale/test/unit_test.hpp"
#include <fstream>
#include <iostream>
#include <limits>
#include <type_traits>
#include <vector>

namespace bl = boost::locale;

void test_messages_info()
{
    using string_vec = std::vector<std::string>;
    {
        bl::gnu_gettext::messages_info info;
        info.locale_category = "LC";
        TEST_EQ(info.get_catalog_paths(), string_vec{});
        info.paths.push_back(".");
        TEST_EQ(info.get_catalog_paths(), string_vec{"./C/LC"});
        info.language = "en";
        TEST_EQ(info.get_catalog_paths(), string_vec{"./en/LC"});
        info.country = "US";
        TEST_EQ(info.get_catalog_paths(), (string_vec{"./en_US/LC", "./en/LC"}));
        info.country.clear();
        info.variant = "euro";
        TEST_EQ(info.get_catalog_paths(), (string_vec{"./en@euro/LC", "./en/LC"}));
        info.country = "US";
        TEST_EQ(info.get_catalog_paths(), (string_vec{"./en_US@euro/LC", "./en@euro/LC", "./en_US/LC", "./en/LC"}));

        info.paths = string_vec{"/1", "/2"};
        TEST_EQ(info.get_catalog_paths(),
                (string_vec{"/1/en_US@euro/LC",
                            "/2/en_US@euro/LC",
                            "/1/en@euro/LC",
                            "/2/en@euro/LC",
                            "/1/en_US/LC",
                            "/2/en_US/LC",
                            "/1/en/LC",
                            "/2/en/LC"}));
    }
}

std::string backend;
bool file_loader_is_actually_called = false;

struct file_loader {
    std::vector<char> operator()(const std::string& name, const std::string& /*encoding*/) const
    {
        std::vector<char> buffer;
        std::ifstream f(name.c_str(), std::ifstream::binary);
        if(!f)
            return buffer;
        f.seekg(0, std::ifstream::end);
        const auto len = f.tellg();
        f.seekg(0);
        if(len > 0) {
            buffer.resize(static_cast<size_t>(len));
            f.read(buffer.data(), buffer.size());
        }
        file_loader_is_actually_called = true;
        return buffer;
    }
};

std::string same_s(std::string s)
{
    return s;
}

std::wstring same_w(std::wstring s)
{
    return s;
}

#ifdef __cpp_lib_char8_t
std::basic_string<char8_t> same_u8(std::basic_string<char8_t> s)
{
    return s;
}
#endif

#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
std::u16string same_u16(std::u16string s)
{
    return s;
}
#endif

#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
std::u32string same_u32(std::u32string s)
{
    return s;
}
#endif

namespace impl {

template<class T, std::size_t = sizeof(T)>
std::true_type is_complete_impl(T*);
std::false_type is_complete_impl(...);

template<class T>
using has_ctype = decltype(is_complete_impl(std::declval<std::ctype<T>*>()));

template<typename Char, typename... Ts>
typename std::enable_if<has_ctype<Char>::value, bool>::type stream_translate(std::basic_ostream<Char>& ss, Ts&&... args)
{
    ss << bl::translate(args...);
    return true;
}

// Required for char types not fully supported by the standard library
// e.g.: error: implicit instantiation of undefined template 'std::ctype<char8_t>'
template<typename Char, typename... Ts>
typename std::enable_if<!has_ctype<Char>::value, bool>::type stream_translate(std::basic_ostream<Char>&, Ts&&...)
{
    return false; // LCOV_EXCL_LINE
}

template<typename Char>
void test_cntranslate(const std::string& sContext,
                      const std::string& sSingular,
                      const std::string& sPlural,
                      long long n,
                      const std::string& sExpected,
                      const std::locale& l,
                      const std::string& domain)
{
    typedef std::basic_string<Char> string_type;
    const string_type expected = to_correct_string<Char>(sExpected, l);

    const string_type c = to<Char>(sContext);
    const string_type s = to<Char>(sSingular);
    const string_type p = to<Char>(sPlural);

    if(domain == "default") {
        TEST_EQ(bl::translate(c, s, p, n).str(l), expected);
        TEST_EQ(bl::translate(c.c_str(), s.c_str(), p.c_str(), n).str(l), expected);
        std::locale tmp_locale;
        std::locale::global(l);
        string_type tmp = bl::translate(c, s, p, n);
        TEST_EQ(tmp, expected);
        tmp = bl::translate(c, s, p, n).str();
        TEST_EQ(tmp, expected);
        std::locale::global(tmp_locale);

        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss, c, s, p, n))
            TEST_EQ(ss.str(), expected);

        // Copyable & movable
        const string_type s2 = ascii_to<Char>("missing Singular");
        const string_type p2 = ascii_to<Char>("missing Plural");
        const string_type& expected2 = (n == 1) ? s2 : p2;
        auto translation1 = bl::translate(c, s, p, n);
        auto translation2 = bl::translate(c, s2, p2, n);
        TEST_EQ(translation1.str(l), expected);
        TEST_EQ(translation2.str(l), expected2);
        // Copy
        translation1 = translation2;
        TEST_EQ(translation1.str(l), expected2);
        {
            bl::basic_message<Char> t3(translation2);
            TEST_EQ(t3.str(l), expected2);
        }
        // Move
        translation1 = bl::translate(c, s, p, n);
        translation2 = std::move(translation1);
        TEST_EQ(translation2.str(l), expected);
        {
            bl::basic_message<Char> t3(std::move(translation2));
            TEST_EQ(t3.str(l), expected);
        }
        // Swap
        translation1 = bl::translate(c, s, p, n);
        translation2 = bl::translate(c, s2, p2, n);
        TEST_EQ(translation1.str(l), expected);
        TEST_EQ(translation2.str(l), expected2);
        using std::swap;
        swap(translation1, translation2);
        TEST_EQ(translation1.str(l), expected2);
        TEST_EQ(translation2.str(l), expected);
        translation1 = bl::translate(c, s, p, n);
        translation2 = bl::translate(c, s2, p2, 1); // n==1!
        swap(translation1, translation2);
        TEST_EQ(translation1.str(l), s2);
        TEST_EQ(translation2.str(l), expected);
    }
    TEST_EQ(bl::translate(c, s, p, n).str(l, domain), expected);
    std::locale tmp_locale;
    std::locale::global(l);
    TEST_EQ(bl::translate(c, s, p, n).str(domain), expected);
    std::locale::global(tmp_locale);
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), c, s, p, n))
            TEST_EQ(ss.str(), expected);
    }
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), c.c_str(), s.c_str(), p.c_str(), n))
            TEST_EQ(ss.str(), expected);
    }
    // Missing facet -> No translation
    {
        const string_type nonAscii = ((string_type() + Char('\x7F')) + Char('\x82')) + Char('\xF0');
        const string_type p2 = nonAscii + p + nonAscii;
        // For char the non-ASCII chars are removed -> original p
        const string_type expected2 = (n == 1) ? s : (std::is_same<Char, char>::value ? p : p2);
        TEST_EQ(bl::translate(c, s, p2, n).str(std::locale::classic()), expected2);
    }
}

template<typename Char>
void test_ntranslate(const std::string& sSingular,
                     const std::string& sPlural,
                     long long n,
                     const std::string& sExpected,
                     const std::locale& l,
                     const std::string& domain)
{
    typedef std::basic_string<Char> string_type;
    const string_type expected = to_correct_string<Char>(sExpected, l);
    const string_type s = to<Char>(sSingular);
    const string_type p = to<Char>(sPlural);
    if(domain == "default") {
        TEST_EQ(bl::translate(s, p, n).str(l), expected);
        TEST_EQ(bl::translate(s.c_str(), p.c_str(), n).str(l), expected);
        std::locale tmp_locale;
        std::locale::global(l);
        string_type tmp = bl::translate(s, p, n);
        TEST_EQ(tmp, expected);
        tmp = bl::translate(s, p, n).str();
        TEST_EQ(tmp, expected);
        std::locale::global(tmp_locale);

        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss, s, p, n))
            TEST_EQ(ss.str(), expected);
    }
    TEST_EQ(bl::translate(s, p, n).str(l, domain), expected);
    std::locale tmp_locale;
    std::locale::global(l);
    TEST_EQ(bl::translate(s, p, n).str(domain), expected);
    std::locale::global(tmp_locale);
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), s, p, n))
            TEST_EQ(ss.str(), expected);
    }
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), s.c_str(), p.c_str(), n))
            TEST_EQ(ss.str(), expected);
    }
}

template<typename Char>
void test_ctranslate(const std::string& sContext,
                     const std::string& sOriginal,
                     const std::string& sExpected,
                     const std::locale& l,
                     const std::string& domain)
{
    typedef std::basic_string<Char> string_type;
    const string_type expected = to_correct_string<Char>(sExpected, l);
    const string_type original = to<Char>(sOriginal);
    const string_type c = to<Char>(sContext);
    if(domain == "default") {
        TEST_EQ(bl::translate(c, original).str(l), expected);
        TEST_EQ(bl::translate(c.c_str(), original.c_str()).str(l), expected);
        std::locale tmp_locale;
        std::locale::global(l);
        string_type tmp = bl::translate(c, original);
        TEST_EQ(tmp, expected);
        tmp = bl::translate(c, original).str();
        TEST_EQ(tmp, expected);
        std::locale::global(tmp_locale);

        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss, c, original))
            TEST_EQ(ss.str(), expected);
    }
    TEST_EQ(bl::translate(c, original).str(l, domain), expected);
    std::locale tmp_locale;
    std::locale::global(l);
    TEST_EQ(bl::translate(c, original).str(domain), expected);
    std::locale::global(tmp_locale);
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), c, original))
            TEST_EQ(ss.str(), expected);
    }
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), c.c_str(), original.c_str()))
            TEST_EQ(ss.str(), expected);
    }
}

template<typename Char>
void test_translate(const std::string& sOriginal,
                    const std::string& sExpected,
                    const std::locale& l,
                    const std::string& domain)
{
    typedef std::basic_string<Char> string_type;
    const string_type expected = to_correct_string<Char>(sExpected, l);
    const string_type original = to<Char>(sOriginal);
    if(domain == "default") {
        TEST_EQ(bl::translate(original).str(l), expected);
        TEST_EQ(bl::translate(original.c_str()).str(l), expected);
        std::locale tmp_locale;
        std::locale::global(l);
        string_type tmp = bl::translate(original);
        TEST_EQ(tmp, expected);
        tmp = bl::translate(original).str();
        TEST_EQ(tmp, expected);
        std::locale::global(tmp_locale);

        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss, original))
            TEST_EQ(ss.str(), expected);
    }
    TEST_EQ(bl::translate(original).str(l, domain), expected);
    std::locale tmp_locale;
    std::locale::global(l);
    TEST_EQ(bl::translate(original).str(domain), expected);
    std::locale::global(tmp_locale);
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), original))
            TEST_EQ(ss.str(), expected);
    }
    {
        std::basic_ostringstream<Char> ss;
        ss.imbue(l);
        if(stream_translate(ss << bl::as::domain(domain), original.c_str()))
            TEST_EQ(ss.str(), expected);
    }
}
} // namespace impl

void test_cntranslate(const std::string& c,
                      const std::string& s,
                      const std::string& p,
                      long long n,
                      const std::string& expected,
                      const std::locale& l,
                      const std::string& domain)
{
    std::cout << "  char" << std::endl;
    impl::test_cntranslate<char>(c, s, p, n, expected, l, domain);
    std::cout << "  wchar_t" << std::endl;
    impl::test_cntranslate<wchar_t>(c, s, p, n, expected, l, domain);
#ifdef __cpp_lib_char8_t
    std::cout << "  char8_t" << std::endl;
    impl::test_cntranslate<char8_t>(c, s, p, n, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
    std::cout << "  char16_t" << std::endl;
    impl::test_cntranslate<char16_t>(c, s, p, n, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
    std::cout << "  char32_t" << std::endl;
    impl::test_cntranslate<char32_t>(c, s, p, n, expected, l, domain);
#endif
}

void test_ntranslate(const std::string& s,
                     const std::string& p,
                     long long n,
                     const std::string& expected,
                     const std::locale& l,
                     const std::string& domain)
{
    std::cout << "  char" << std::endl;
    impl::test_ntranslate<char>(s, p, n, expected, l, domain);
    std::cout << "  wchar_t" << std::endl;
    impl::test_ntranslate<wchar_t>(s, p, n, expected, l, domain);
#ifdef __cpp_lib_char8_t
    std::cout << "  char8_t" << std::endl;
    impl::test_ntranslate<char8_t>(s, p, n, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
    std::cout << "  char16_t" << std::endl;
    impl::test_ntranslate<char16_t>(s, p, n, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
    std::cout << "  char32_t" << std::endl;
    impl::test_ntranslate<char32_t>(s, p, n, expected, l, domain);
#endif
}

void test_ctranslate(const std::string& c,
                     const std::string& original,
                     const std::string& expected,
                     const std::locale& l,
                     const std::string& domain)
{
    std::cout << "  char" << std::endl;
    impl::test_ctranslate<char>(c, original, expected, l, domain);
    std::cout << "  wchar_t" << std::endl;
    impl::test_ctranslate<wchar_t>(c, original, expected, l, domain);
#ifdef __cpp_lib_char8_t
    std::cout << "  char8_t" << std::endl;
    impl::test_ctranslate<char8_t>(c, original, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
    std::cout << "  char16_t" << std::endl;
    impl::test_ctranslate<char16_t>(c, original, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
    std::cout << "  char32_t" << std::endl;
    impl::test_ctranslate<char32_t>(c, original, expected, l, domain);
#endif
}

void test_translate(const std::string& original,
                    const std::string& expected,
                    const std::locale& l,
                    const std::string& domain)
{
    std::cout << "  char" << std::endl;
    impl::test_translate<char>(original, expected, l, domain);
    std::cout << "  wchar_t" << std::endl;
    impl::test_translate<wchar_t>(original, expected, l, domain);
#ifdef __cpp_lib_char8_t
    std::cout << "  char8_t" << std::endl;
    impl::test_translate<char8_t>(original, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
    std::cout << "  char16_t" << std::endl;
    impl::test_translate<char16_t>(original, expected, l, domain);
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
    std::cout << "  char32_t" << std::endl;
    impl::test_translate<char32_t>(original, expected, l, domain);
#endif
}

bool iso_8859_8_supported = true;

void test_main(int argc, char** argv)
{
    test_messages_info();

    const std::string message_path = (argc == 2) ? argv[1] : ".";

    for(const std::string& backend_name : boost::locale::localization_backend_manager::global().get_all_backends()) {
        std::cout << "Testing for backend --------- " << backend_name << std::endl;
        boost::locale::localization_backend_manager tmp_backend = boost::locale::localization_backend_manager::global();
        tmp_backend.select(backend_name);
        boost::locale::localization_backend_manager::global(tmp_backend);

        backend = backend_name;

        boost::locale::generator g;
        g.add_messages_domain("simple");
        g.add_messages_domain("full");
        // Fallback using only ASCII keys, choose a specific encoding != UTF-8, here: Latin1
        g.add_messages_domain("fall/ISO-8859-1");
        g.add_messages_path(message_path);
        g.set_default_messages_domain("default");

        for(const std::string locale_name : {"he_IL.UTF-8", "he_IL.ISO8859-8"}) {
            std::locale l;

            if(locale_name.find(".ISO") != std::string::npos) {
                try {
                    l = g(locale_name);
                } catch(const boost::locale::conv::invalid_charset_error&) {                      // LCOV_EXCL_LINE
                    std::cout << "Looks like ISO-8859-8 is not supported! skipping" << std::endl; // LCOV_EXCL_LINE
                    iso_8859_8_supported = false;                                                 // LCOV_EXCL_LINE
                    continue;                                                                     // LCOV_EXCL_LINE
                }
            } else
                l = g(locale_name);

            std::cout << "  Testing " << locale_name << std::endl;
            std::cout << "    single forms" << std::endl;

            test_translate("hello", "שלום", l, "default");
            test_translate("hello", "היי", l, "simple");
            test_translate("hello", "hello", l, "undefined");
            test_translate("untranslated", "untranslated", l, "default");
            // Check removal of old "context" information
            test_translate("#untranslated", "#untranslated", l, "default");
            test_translate("##untranslated", "##untranslated", l, "default");
            test_ctranslate("context", "hello", "שלום בהקשר אחר", l, "default");
            test_translate("#hello", "#שלום", l, "default");

            std::cout << "    plural forms" << std::endl;

            {
                test_ntranslate("x day", "x days", 0, "x ימים", l, "default");
                test_ntranslate("x day", "x days", 1, "יום x", l, "default");
                test_ntranslate("x day", "x days", 2, "יומיים", l, "default");
                test_ntranslate("x day", "x days", 3, "x ימים", l, "default");
                test_ntranslate("x day", "x days", 20, "x יום", l, "default");
                test_ntranslate("x day", "x days", 0, "x days", l, "undefined");
                test_ntranslate("x day", "x days", 1, "x day", l, "undefined");
                test_ntranslate("x day", "x days", 2, "x days", l, "undefined");
                test_ntranslate("x day", "x days", 20, "x days", l, "undefined");
                // Ensure no truncation occurs
                test_ntranslate("x day", "x days", std::numeric_limits<long long>::min(), "x days", l, "undefined");
                test_ntranslate("x day", "x days", std::numeric_limits<long long>::max(), "x days", l, "undefined");
                for(unsigned bit = 1; bit < std::numeric_limits<long long>::digits; ++bit) {
                    // Set each individual bit possible and add 1.
                    // If the value is truncated the 1 will remain leading to singular form
                    const auto num = static_cast<long long>(static_cast<unsigned long long>(1) << bit);
                    test_ntranslate("x day", "x days", num + 1, "x days", l, "undefined");
                }
            }
            std::cout << "    plural forms with context" << std::endl;
            {
                std::string inp = "context";
                std::string out = "בהקשר ";

                test_cntranslate(inp, "x day", "x days", 0, out + "x ימים", l, "default");
                test_cntranslate(inp, "x day", "x days", 1, out + "יום x", l, "default");
                test_cntranslate(inp, "x day", "x days", 2, out + "יומיים", l, "default");
                test_cntranslate(inp, "x day", "x days", 3, out + "x ימים", l, "default");
                test_cntranslate(inp, "x day", "x days", 20, out + "x יום", l, "default");

                test_cntranslate(inp, "x day", "x days", 0, "x days", l, "undefined");
                test_cntranslate(inp, "x day", "x days", 1, "x day", l, "undefined");
                test_cntranslate(inp, "x day", "x days", 2, "x days", l, "undefined");
                test_cntranslate(inp, "x day", "x days", 20, "x days", l, "undefined");
            }
        }
        std::cout << "  Testing fallbacks" << std::endl;
        {
            const std::locale l = g("he_IL.UTF-8");
            test_translate("test", "he_IL", l, "full");
            test_translate("test", "he", l, "fall");
            for(int n = -1; n < 5; ++n) {
                // No plural forms -> Use english logic
                // Singular is translated, plural is not
                test_ntranslate("test", "tests", n, (n == 1) ? "he" : "tests", l, "fall");
            }
        }

        std::cout << "  Testing automatic conversions " << std::endl;
        std::locale::global(g("he_IL.UTF-8"));

        TEST_EQ(same_s(bl::translate("hello")), "שלום");
        TEST_EQ(same_w(bl::translate(to<wchar_t>("hello"))), to<wchar_t>("שלום"));

#ifdef __cpp_lib_char8_t
        TEST_EQ(same_u8(bl::translate(to<char8_t>("hello"))), to<char8_t>("שלום"));
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
        if(backend == "icu" || backend == "std")
            TEST_EQ(same_u16(bl::translate(to<char16_t>("hello"))), to<char16_t>("שלום"));
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
        if(backend == "icu" || backend == "std")
            TEST_EQ(same_u32(bl::translate(to<char32_t>("hello"))), to<char32_t>("שלום"));
#endif
    }

    std::cout << "Testing custom file system support" << std::endl;
    {
        boost::locale::gnu_gettext::messages_info info;
        info.language = "he";
        info.country = "IL";
        info.encoding = "UTF-8";
        info.paths.push_back(message_path);

        info.domains.push_back(bl::gnu_gettext::messages_info::domain("default"));
        info.callback = file_loader();

        file_loader_is_actually_called = false;
        std::locale l(std::locale::classic(), boost::locale::gnu_gettext::create_messages_facet<char>(info));
        TEST(file_loader_is_actually_called);
        TEST_EQ(bl::translate("hello").str(l), "שלום");
    }
    if(iso_8859_8_supported) {
        std::cout << "Testing non-US-ASCII keys" << std::endl;
        std::cout << "  UTF-8 keys" << std::endl;
        {
            boost::locale::generator g;
            g.add_messages_domain("default");
            g.add_messages_path(message_path);

            std::locale l = g("he_IL.UTF-8");

            // narrow
            TEST_EQ(bl::gettext("בדיקה", l), "test");
            TEST_EQ(bl::gettext("לא קיים", l), "לא קיים");

            // wide
            std::wstring wtest = bl::conv::utf_to_utf<wchar_t>("בדיקה");
            std::wstring wmiss = bl::conv::utf_to_utf<wchar_t>("לא קיים");
            TEST_EQ(bl::gettext(wtest.c_str(), l), L"test");
            TEST_EQ(bl::gettext(wmiss.c_str(), l), wmiss);

            l = g("he_IL.ISO-8859-8");

            // conversion with substitution
            TEST_EQ(bl::gettext("test-あにま-בדיקה", l), bl::conv::from_utf("test--בדיקה", "ISO-8859-8"));
        }

        std::cout << "  ANSI keys" << std::endl;

        {
            boost::locale::generator g;
            g.add_messages_domain("default/ISO-8859-8");
            g.add_messages_path(message_path);

            std::locale l = g("he_IL.UTF-8");

            // narrow non-UTF-8 keys
            // match
            TEST_EQ(bl::gettext(bl::conv::from_utf("בדיקה", "ISO-8859-8").c_str(), l), "test");
            // conversion
            TEST_EQ(bl::gettext(bl::conv::from_utf("לא קיים", "ISO-8859-8").c_str(), l), "לא קיים");
        }
    }
    // Test compiles
    {
        bl::gettext("");
        bl::gettext(L"");
        bl::dgettext("", "");
        bl::dgettext("", L"");

        bl::pgettext("", "");
        bl::pgettext(L"", L"");
        bl::dpgettext("", "", "");
        bl::dpgettext("", L"", L"");

        bl::ngettext("", "", 1);
        bl::ngettext(L"", L"", 1);
        bl::dngettext("", "", "", 1);
        bl::dngettext("", L"", L"", 1);

        bl::npgettext("", "", "", 1);
        bl::npgettext(L"", L"", L"", 1);
        bl::dnpgettext("", "", "", "", 1);
        bl::dnpgettext("", L"", L"", L"", 1);
    }
}

// boostinspect:noascii