Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
Asiri Rathnayake | 6edc12c | 2016-05-28 08:57:35 +0000 | [diff] [blame] | 10 | |
| 11 | // UNSUPPORTED: c++98, c++03, c++11 |
| 12 | |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <cassert> |
| 15 | |
Marshall Clow | 289f1ce | 2018-11-20 22:55:40 +0000 | [diff] [blame] | 16 | #include "test_macros.h" |
| 17 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame^] | 18 | #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L |
| 19 | typedef std::u8string u8string; |
| 20 | #else |
| 21 | typedef std::string u8string; |
| 22 | #endif |
| 23 | |
| 24 | |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 25 | int main() |
| 26 | { |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 27 | using namespace std::literals::string_literals; |
| 28 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 29 | static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" ); |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame^] | 30 | static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" ); |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 31 | static_assert ( std::is_same<decltype( L"Hi"s), std::wstring>::value, "" ); |
| 32 | static_assert ( std::is_same<decltype( u"Hi"s), std::u16string>::value, "" ); |
| 33 | static_assert ( std::is_same<decltype( U"Hi"s), std::u32string>::value, "" ); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 34 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 35 | std::string foo; |
| 36 | std::wstring Lfoo; |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame^] | 37 | u8string u8foo; |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 38 | std::u16string ufoo; |
| 39 | std::u32string Ufoo; |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 40 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame^] | 41 | foo = ""s; assert( foo.size() == 0); |
| 42 | u8foo = u8""s; assert(u8foo.size() == 0); |
| 43 | Lfoo = L""s; assert( Lfoo.size() == 0); |
| 44 | ufoo = u""s; assert( ufoo.size() == 0); |
| 45 | Ufoo = U""s; assert( Ufoo.size() == 0); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 46 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame^] | 47 | foo = " "s; assert( foo.size() == 1); |
| 48 | u8foo = u8" "s; assert(u8foo.size() == 1); |
| 49 | Lfoo = L" "s; assert( Lfoo.size() == 1); |
| 50 | ufoo = u" "s; assert( ufoo.size() == 1); |
| 51 | Ufoo = U" "s; assert( Ufoo.size() == 1); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 52 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame^] | 53 | foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC")); |
| 54 | u8foo = u8"ABC"s; assert(u8foo == u8"ABC"); assert(u8foo == u8string (u8"ABC")); |
| 55 | Lfoo = L"ABC"s; assert( Lfoo == L"ABC"); assert( Lfoo == std::wstring ( L"ABC")); |
| 56 | ufoo = u"ABC"s; assert( ufoo == u"ABC"); assert( ufoo == std::u16string( u"ABC")); |
| 57 | Ufoo = U"ABC"s; assert( Ufoo == U"ABC"); assert( Ufoo == std::u32string( U"ABC")); |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 58 | } |