Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
translation_tests.cpp
Go to the documentation of this file.
1
// Copyright (c) 2023-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <
tinyformat.h
>
6
#include <
util/translation.h
>
7
8
#include <boost/test/unit_test.hpp>
9
10
BOOST_AUTO_TEST_SUITE(translation_tests)
11
12
static
TranslateFn
translate
{[](
const
char
* str) {
return
strprintf
(
"t(%s)"
, str); }};
13
14
// Custom translation function _t(), similar to _() but internal to this test.
15
consteval
auto
_t
(
util::TranslatedLiteral
str)
16
{
17
str.
translate_fn
= &
translate
;
18
return
str;
19
}
20
21
BOOST_AUTO_TEST_CASE
(translation_namedparams)
22
{
23
bilingual_str
arg{
"original"
,
"translated"
};
24
bilingual_str
result{
strprintf
(
_t
(
"original [%s]"
), arg)};
25
BOOST_CHECK_EQUAL
(result.
original
,
"original [original]"
);
26
BOOST_CHECK_EQUAL
(result.
translated
,
"t(original [translated])"
);
27
28
util::TranslatedLiteral
arg2{
"original"
, &
translate
};
29
bilingual_str
result2{
strprintf
(
_t
(
"original [%s]"
), arg2)};
30
BOOST_CHECK_EQUAL
(result2.
original
,
"original [original]"
);
31
BOOST_CHECK_EQUAL
(result2.
translated
,
"t(original [t(original)])"
);
32
}
33
34
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition
object.cpp:17
bilingual_str
Bilingual messages:
Definition
translation.h:24
bilingual_str::translated
std::string translated
Definition
translation.h:26
bilingual_str::original
std::string original
Definition
translation.h:25
util::TranslatedLiteral
Compile-time literal string that can be translated with an optional translation function.
Definition
translation.h:55
util::TranslatedLiteral::translate_fn
const TranslateFn * translate_fn
Definition
translation.h:57
tinyformat.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition
tinyformat.h:1172
translation.h
TranslateFn
std::function< std::string(const char *)> TranslateFn
Translate a message to the native language of the user.
Definition
translation.h:16
_t
consteval auto _t(util::TranslatedLiteral str)
Definition
translation_tests.cpp:15
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(translation_namedparams)
Definition
translation_tests.cpp:21
translate
static TranslateFn translate
Definition
translation_tests.cpp:12
Generated on
for Bitcoin Core by
1.17.0