LCOV - code coverage report
Current view: top level - src/test - translation_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 11 11
Test Date: 2025-01-19 05:08:01 Functions: 100.0 % 2 2
Branches: 50.0 % 74 37

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2023 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                 :           3 : 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   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(translation_namedparams)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      22                 :             : {
      23   [ +  -  +  - ]:           1 :     bilingual_str arg{"original", "translated"};
      24         [ +  - ]:           1 :     bilingual_str result{strprintf(_t("original [%s]"), arg)};
      25   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(result.original, "original [original]");
      26   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(result.translated, "t(original [translated])");
      27                 :             : 
      28                 :           1 :     util::TranslatedLiteral arg2{"original", &translate};
      29         [ +  - ]:           1 :     bilingual_str result2{strprintf(_t("original [%s]"), arg2)};
      30   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(result2.original, "original [original]");
      31   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(result2.translated, "t(original [t(original)])");
      32                 :           3 : }
      33                 :             : 
      34                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1