Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++][test] Add test coverage for codecvt<char(16|32)_t, char8_t, …
…mbstate_t> This change adds test coverage for the `codecvt<char16_t, char8_t, mbstate_t>` and `codecvt<char32_t, char8_t, mbstate_t>` ctype facets added to the C++20 WD by [P0482R6](https://wg21.link/P0428R6). Note that libc++ does not implement these facets despite implementing the remainder of P0482, presumably for ABI reasons, so these tests are marked `UNSUPPORTED: libc++`.
- Loading branch information
1 parent
ad811a2
commit 197f185
Showing
19 changed files
with
851 additions
and
102 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...calization/locale.categories/category.ctype/locale.codecvt/ctor_char16_t_char8_t.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// explicit codecvt(size_t refs = 0); | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
|
||
struct my_facet : F { | ||
static int count; | ||
|
||
explicit my_facet(std::size_t refs = 0) : F(refs) { ++count; } | ||
|
||
~my_facet() { --count; } | ||
}; | ||
|
||
int my_facet::count = 0; | ||
|
||
int main(int, char**) { | ||
{ | ||
std::locale l(std::locale::classic(), new my_facet); | ||
assert(my_facet::count == 1); | ||
} | ||
assert(my_facet::count == 0); | ||
{ | ||
my_facet f(1); | ||
assert(my_facet::count == 1); | ||
{ | ||
std::locale l(std::locale::classic(), &f); | ||
assert(my_facet::count == 1); | ||
} | ||
assert(my_facet::count == 1); | ||
} | ||
assert(my_facet::count == 0); | ||
|
||
return 0; | ||
} |
53 changes: 53 additions & 0 deletions
53
...calization/locale.categories/category.ctype/locale.codecvt/ctor_char32_t_char8_t.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char32_t, char8_t, mbstate_t> | ||
|
||
// explicit codecvt(size_t refs = 0); | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
using F = std::codecvt<char32_t, char8_t, std::mbstate_t>; | ||
|
||
struct my_facet : F { | ||
static int count; | ||
|
||
explicit my_facet(std::size_t refs = 0) : F(refs) { ++count; } | ||
|
||
~my_facet() { --count; } | ||
}; | ||
|
||
int my_facet::count = 0; | ||
|
||
int main(int, char**) { | ||
{ | ||
std::locale l(std::locale::classic(), new my_facet); | ||
assert(my_facet::count == 1); | ||
} | ||
assert(my_facet::count == 0); | ||
{ | ||
my_facet f(1); | ||
assert(my_facet::count == 1); | ||
{ | ||
std::locale l(std::locale::classic(), &f); | ||
assert(my_facet::count == 1); | ||
} | ||
assert(my_facet::count == 1); | ||
} | ||
assert(my_facet::count == 0); | ||
|
||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
...egory.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_always_noconv.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// bool always_noconv() const noexcept; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
assert(!f.always_noconv()); | ||
static_assert(noexcept(f.always_noconv())); | ||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
...s/category.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_encoding.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// int encoding() const noexcept; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
assert(f.encoding() == 0); | ||
static_assert(noexcept(f.encoding())); | ||
return 0; | ||
} |
39 changes: 39 additions & 0 deletions
39
...egories/category.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_in.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// result in(stateT& state, | ||
// const externT* from, const externT* from_end, const externT*& from_next, | ||
// internT* to, internT* to_end, internT*& to_next) const; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F::extern_type from[] = u8"some text"; | ||
F::intern_type to[9]; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
std::mbstate_t mbs = {}; | ||
const F::extern_type* from_next = nullptr; | ||
F::intern_type* to_next = nullptr; | ||
assert(f.in(mbs, from, from + 9, from_next, to, to + 9, to_next) == F::ok); | ||
assert(from_next - from == 9); | ||
assert(to_next - to == 9); | ||
for (unsigned i = 0; i < 9; ++i) | ||
assert(to[i] == from[i]); | ||
return 0; | ||
} |
34 changes: 34 additions & 0 deletions
34
...ies/category.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_length.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// int length(stateT& state, const externT* from, const externT* from_end, size_t max) const; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
std::mbstate_t mbs = {}; | ||
const char8_t from[] = u8"some text"; | ||
assert(f.length(mbs, from, from + 10, 0) == 0); | ||
assert(f.length(mbs, from, from + 10, 8) == 8); | ||
assert(f.length(mbs, from, from + 10, 9) == 9); | ||
assert(f.length(mbs, from, from + 10, 10) == 10); | ||
assert(f.length(mbs, from, from + 10, 100) == 10); | ||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
...category.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_max_length.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// int max_length() const noexcept; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
assert(f.max_length() == 4); | ||
static_assert(noexcept(f.max_length())); | ||
return 0; | ||
} |
40 changes: 40 additions & 0 deletions
40
...gories/category.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_out.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// result out(stateT& state, | ||
// const internT* from, const internT* from_end, const internT*& from_next, | ||
// externT* to, externT* to_end, externT*& to_next) const; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
F::intern_type from[9] = {'s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't'}; | ||
F::extern_type to[9] = {0}; | ||
std::mbstate_t mbs = {}; | ||
const F::intern_type* from_next = nullptr; | ||
F::extern_type* to_next = nullptr; | ||
F::result r = f.out(mbs, from, from + 9, from_next, to, to + 9, to_next); | ||
assert(r == F::ok); | ||
assert(from_next - from == 9); | ||
assert(to_next - to == 9); | ||
for (unsigned i = 0; i < 9; ++i) | ||
assert(to[i] == from[i]); | ||
return 0; | ||
} |
33 changes: 33 additions & 0 deletions
33
...es/category.ctype/locale.codecvt/locale.codecvt.members/char16_t_char8_t_unshift.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char16_t, char8_t, mbstate_t> | ||
|
||
// result unshift(stateT& state, | ||
// externT* to, externT* to_end, externT*& to_next) const; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char16_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
std::mbstate_t mbs = {}; | ||
char8_t to[3]; | ||
char8_t* to_next = nullptr; | ||
assert(f.unshift(mbs, to, to + 3, to_next) == F::noconv); | ||
assert(to_next == to); | ||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
...egory.ctype/locale.codecvt/locale.codecvt.members/char32_t_char8_t_always_noconv.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <locale> | ||
|
||
// template <> class codecvt<char32_t, char8_t, mbstate_t> | ||
|
||
// bool always_noconv() const noexcept; | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | ||
|
||
// C++20 codecvt specializations for char8_t are not yet implemented: | ||
// UNSUPPORTED: libc++ | ||
|
||
#include <cassert> | ||
#include <locale> | ||
|
||
int main(int, char**) { | ||
using F = std::codecvt<char32_t, char8_t, std::mbstate_t>; | ||
const F& f = std::use_facet<F>(std::locale::classic()); | ||
assert(!f.always_noconv()); | ||
static_assert(noexcept(f.always_noconv())); | ||
return 0; | ||
} |
Oops, something went wrong.