Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Asiri Rathnayake | 6edc12c | 2016-05-28 08:57:35 +0000 | [diff] [blame] | 9 | |
| 10 | // UNSUPPORTED: c++98, c++03, c++11 |
| 11 | |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <cassert> |
| 14 | |
Marshall Clow | 289f1ce | 2018-11-20 22:55:40 +0000 | [diff] [blame] | 15 | #include "test_macros.h" |
| 16 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 17 | #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L |
| 18 | typedef std::u8string u8string; |
| 19 | #else |
| 20 | typedef std::string u8string; |
| 21 | #endif |
| 22 | |
| 23 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 24 | int main(int, char**) |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 25 | { |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 26 | using namespace std::literals::string_literals; |
| 27 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 28 | static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" ); |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 29 | static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" ); |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 30 | static_assert ( std::is_same<decltype( L"Hi"s), std::wstring>::value, "" ); |
| 31 | static_assert ( std::is_same<decltype( u"Hi"s), std::u16string>::value, "" ); |
| 32 | static_assert ( std::is_same<decltype( U"Hi"s), std::u32string>::value, "" ); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 33 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 34 | std::string foo; |
| 35 | std::wstring Lfoo; |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 36 | u8string u8foo; |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 37 | std::u16string ufoo; |
| 38 | std::u32string Ufoo; |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 39 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 40 | foo = ""s; assert( foo.size() == 0); |
| 41 | u8foo = u8""s; assert(u8foo.size() == 0); |
| 42 | Lfoo = L""s; assert( Lfoo.size() == 0); |
| 43 | ufoo = u""s; assert( ufoo.size() == 0); |
| 44 | Ufoo = U""s; assert( Ufoo.size() == 0); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 45 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 46 | foo = " "s; assert( foo.size() == 1); |
| 47 | u8foo = u8" "s; assert(u8foo.size() == 1); |
| 48 | Lfoo = L" "s; assert( Lfoo.size() == 1); |
| 49 | ufoo = u" "s; assert( ufoo.size() == 1); |
| 50 | Ufoo = U" "s; assert( Ufoo.size() == 1); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 51 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 52 | foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC")); |
| 53 | u8foo = u8"ABC"s; assert(u8foo == u8"ABC"); assert(u8foo == u8string (u8"ABC")); |
| 54 | Lfoo = L"ABC"s; assert( Lfoo == L"ABC"); assert( Lfoo == std::wstring ( L"ABC")); |
| 55 | ufoo = u"ABC"s; assert( ufoo == u"ABC"); assert( ufoo == std::u16string( u"ABC")); |
| 56 | Ufoo = U"ABC"s; assert( Ufoo == U"ABC"); assert( Ufoo == std::u32string( U"ABC")); |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 57 | |
| 58 | return 0; |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 59 | } |