Skip to content

Commit

Permalink
Add tests for localized_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytheway committed May 5, 2020
1 parent f96dc20 commit 12246fb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/catacharset_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <clocale>
#include <stdexcept>
#include <string>
#include <vector>

#include "catacharset.h"
#include "catch/catch.hpp"
#include "translations.h"

TEST_CASE( "utf8_width", "[catacharset]" )
{
Expand Down Expand Up @@ -51,3 +53,31 @@ TEST_CASE( "wstr_to_utf8", "[catacharset]" )
CHECK( wstr_to_utf8( src ) == dest );
setlocale( LC_ALL, "C" );
}

TEST_CASE( "localized_compare", "[catacharset]" )
{
try {
std::locale::global( std::locale( "en_US.UTF-8" ) );
} catch( std::runtime_error & ) {
// On platforms where we can't set the locale, ignore this test
return;
}
CAPTURE( setlocale( LC_ALL, nullptr ) );
CAPTURE( std::locale().name() );
std::string a = "a";
std::string b = "b";
std::string c = "c";
std::string A = "A";
std::string B = "B";
CHECK( !localized_compare( a, a ) );
CHECK( localized_compare( a, B ) );
CHECK( localized_compare( A, b ) );
CHECK( !localized_compare( B, a ) );
CHECK( !localized_compare( b, A ) );
CHECK( localized_compare( std::make_pair( a, a ), std::make_pair( a, B ) ) );
CHECK( localized_compare( std::make_tuple( a ), std::make_tuple( B ) ) );
CHECK( localized_compare( std::make_tuple( a, c, c ), std::make_tuple( B, a, a ) ) );
CHECK( localized_compare( std::make_tuple( a, a, c ), std::make_tuple( a, B, a ) ) );
CHECK( localized_compare( std::make_tuple( a, a, a ), std::make_tuple( a, a, B ) ) );
std::locale::global( std::locale::classic() );
}

0 comments on commit 12246fb

Please sign in to comment.