mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-29 21:24:04 +00:00
[libcxx] [test] Fix the collate compare test for Glibc, Windows and FreeBSD
The old expected behaviour was specific to Apple platforms, while Glibc, Windows and FreeBSD collate differently (ignoring case). Make the old tested behaviour a special case for Apple platforms, and make the default case the one used by the other three. In clang-cl/DLL configurations, the test is hit by https://llvm.org/PR41018 (making the test fail to link). Differential Revision: https://reviews.llvm.org/D120797
This commit is contained in:
parent
4c3b74b7f5
commit
77fd54d2eb
@ -19,11 +19,8 @@
|
||||
// has any difference from "C" collation. But I do believe I'm picking
|
||||
// up the OS's collation files.
|
||||
|
||||
// TODO investigation needed.
|
||||
// Glibc seems to collate files differently from the way Apple's C library does it.
|
||||
// XFAIL: target={{.*}}-linux-gnu{{.*}}
|
||||
|
||||
// XFAIL: LIBCXX-WINDOWS-FIXME
|
||||
// https://llvm.org/PR41018
|
||||
// XFAIL: windows-dll && msvc
|
||||
|
||||
// XFAIL: LIBCXX-AIX-FIXME
|
||||
|
||||
@ -36,24 +33,49 @@
|
||||
#include "test_macros.h"
|
||||
#include "platform_support.h" // locale name macros
|
||||
|
||||
#define ASSERT_COMPARE(type, str1, str2, expected) \
|
||||
do { \
|
||||
type s1(str1); \
|
||||
type s2(str2); \
|
||||
assert(f.compare(s1.data(), s1.data() + s1.size(), \
|
||||
s2.data(), s2.data() + s2.size()) == (expected)); \
|
||||
} while (0)
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
std::locale l(LOCALE_en_US_UTF_8);
|
||||
{
|
||||
const std::collate<char>& f = std::use_facet<std::collate<char> >(l);
|
||||
std::string s2("aaaaaaA");
|
||||
std::string s3("BaaaaaA");
|
||||
assert(f.compare(s2.data(), s2.data() + s2.size(),
|
||||
s3.data(), s3.data() + s3.size()) == 1);
|
||||
|
||||
ASSERT_COMPARE(std::string, "aaa", "bbb", -1);
|
||||
ASSERT_COMPARE(std::string, "AAA", "BBB", -1);
|
||||
ASSERT_COMPARE(std::string, "bbb", "aaa", 1);
|
||||
ASSERT_COMPARE(std::string, "ccc", "ccc", 0);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// Apple's default collation is case-sensitive
|
||||
ASSERT_COMPARE(std::string, "aaaaaaA", "BaaaaaA", 1);
|
||||
#else
|
||||
// Glibc, Windows, and FreeBSD's default collation is case-insensitive
|
||||
ASSERT_COMPARE(std::string, "aaaaaaA", "BaaaaaA", -1);
|
||||
#endif
|
||||
}
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
{
|
||||
const std::collate<wchar_t>& f = std::use_facet<std::collate<wchar_t> >(l);
|
||||
std::wstring s2(L"aaaaaaA");
|
||||
std::wstring s3(L"BaaaaaA");
|
||||
assert(f.compare(s2.data(), s2.data() + s2.size(),
|
||||
s3.data(), s3.data() + s3.size()) == 1);
|
||||
|
||||
ASSERT_COMPARE(std::wstring, L"aaa", L"bbb", -1);
|
||||
ASSERT_COMPARE(std::wstring, L"AAA", L"BBB", -1);
|
||||
ASSERT_COMPARE(std::wstring, L"bbb", L"aaa", 1);
|
||||
ASSERT_COMPARE(std::wstring, L"ccc", L"ccc", 0);
|
||||
#if defined(__APPLE__)
|
||||
// Apple's default collation is case-sensitive
|
||||
ASSERT_COMPARE(std::wstring, L"aaaaaaA", L"BaaaaaA", 1);
|
||||
#else
|
||||
// Glibc, Windows, and FreeBSD's default collation is case-insensitive
|
||||
ASSERT_COMPARE(std::wstring, L"aaaaaaA", L"BaaaaaA", -1);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -61,18 +83,25 @@ int main(int, char**)
|
||||
std::locale l("C");
|
||||
{
|
||||
const std::collate<char>& f = std::use_facet<std::collate<char> >(l);
|
||||
std::string s2("aaaaaaA");
|
||||
std::string s3("BaaaaaA");
|
||||
assert(f.compare(s2.data(), s2.data() + s2.size(),
|
||||
s3.data(), s3.data() + s3.size()) == 1);
|
||||
ASSERT_COMPARE(std::string, "aaa", "bbb", -1);
|
||||
ASSERT_COMPARE(std::string, "AAA", "BBB", -1);
|
||||
ASSERT_COMPARE(std::string, "bbb", "aaa", 1);
|
||||
ASSERT_COMPARE(std::string, "ccc", "ccc", 0);
|
||||
|
||||
// In the C locale, these are collated lexicographically.
|
||||
ASSERT_COMPARE(std::string, "aaaaaaA", "BaaaaaA", 1);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
{
|
||||
const std::collate<wchar_t>& f = std::use_facet<std::collate<wchar_t> >(l);
|
||||
std::wstring s2(L"aaaaaaA");
|
||||
std::wstring s3(L"BaaaaaA");
|
||||
assert(f.compare(s2.data(), s2.data() + s2.size(),
|
||||
s3.data(), s3.data() + s3.size()) == 1);
|
||||
|
||||
ASSERT_COMPARE(std::wstring, L"aaa", L"bbb", -1);
|
||||
ASSERT_COMPARE(std::wstring, L"AAA", L"BBB", -1);
|
||||
ASSERT_COMPARE(std::wstring, L"bbb", L"aaa", 1);
|
||||
ASSERT_COMPARE(std::wstring, L"ccc", L"ccc", 0);
|
||||
|
||||
// In the C locale, these are collated lexicographically.
|
||||
ASSERT_COMPARE(std::wstring, L"aaaaaaA", L"BaaaaaA", 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user