| 1 | // { dg-do run { target c++20 } } |
| 2 | |
| 3 | // Copyright (C) 2018-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // basic_string ends_with |
| 21 | |
| 22 | #include <testsuite_string.h> |
| 23 | #include <testsuite_hooks.h> |
| 24 | |
| 25 | void |
| 26 | test01() |
| 27 | { |
| 28 | const wchar_t cstr_suf[] = L".jpg"; |
| 29 | const std::wstring_view sv_suf(L".jpg"); |
| 30 | const wchar_t cstr_suf2[] = L".rgb"; |
| 31 | const std::wstring_view sv_suf2(L".rgb"); |
| 32 | |
| 33 | const __gnu_test::wstring s_test(L"slugs/slimy.jpg"); |
| 34 | |
| 35 | const auto cstr_in_slugs = s_test.ends_with(cstr_suf); |
| 36 | VERIFY( cstr_in_slugs ); |
| 37 | const auto sv_in_slugs = s_test.ends_with(sv_suf); |
| 38 | VERIFY( sv_in_slugs ); |
| 39 | const auto char_g = s_test.ends_with(L'g'); |
| 40 | VERIFY( char_g ); |
| 41 | |
| 42 | const auto cstr_in_worms = s_test.ends_with(cstr_suf2); |
| 43 | VERIFY( !cstr_in_worms ); |
| 44 | const auto sv_in_worms = s_test.ends_with(sv_suf2); |
| 45 | VERIFY( !sv_in_worms ); |
| 46 | const auto char_b = s_test.ends_with(L'b'); |
| 47 | VERIFY( !char_b ); |
| 48 | } |
| 49 | |
| 50 | int |
| 51 | main() |
| 52 | { |
| 53 | test01(); |
| 54 | return 0; |
| 55 | } |