xref: /aosp_15_r20/external/libcxx/test/std/strings/basic.string.literals/literal.pass.cpp (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker // -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
3*58b9f456SAndroid Build Coastguard Worker //
4*58b9f456SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker //
6*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker //
9*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker 
11*58b9f456SAndroid Build Coastguard Worker // UNSUPPORTED: c++98, c++03, c++11
12*58b9f456SAndroid Build Coastguard Worker 
13*58b9f456SAndroid Build Coastguard Worker #include <string>
14*58b9f456SAndroid Build Coastguard Worker #include <cassert>
15*58b9f456SAndroid Build Coastguard Worker 
16*58b9f456SAndroid Build Coastguard Worker #include "test_macros.h"
17*58b9f456SAndroid Build Coastguard Worker 
18*58b9f456SAndroid Build Coastguard Worker #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
19*58b9f456SAndroid Build Coastguard Worker     typedef std::u8string u8string;
20*58b9f456SAndroid Build Coastguard Worker #else
21*58b9f456SAndroid Build Coastguard Worker     typedef std::string   u8string;
22*58b9f456SAndroid Build Coastguard Worker #endif
23*58b9f456SAndroid Build Coastguard Worker 
24*58b9f456SAndroid Build Coastguard Worker 
main()25*58b9f456SAndroid Build Coastguard Worker int main()
26*58b9f456SAndroid Build Coastguard Worker {
27*58b9f456SAndroid Build Coastguard Worker     using namespace std::literals::string_literals;
28*58b9f456SAndroid Build Coastguard Worker 
29*58b9f456SAndroid Build Coastguard Worker     static_assert ( std::is_same<decltype(   "Hi"s), std::string>::value, "" );
30*58b9f456SAndroid Build Coastguard Worker     static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" );
31*58b9f456SAndroid Build Coastguard Worker     static_assert ( std::is_same<decltype(  L"Hi"s), std::wstring>::value, "" );
32*58b9f456SAndroid Build Coastguard Worker     static_assert ( std::is_same<decltype(  u"Hi"s), std::u16string>::value, "" );
33*58b9f456SAndroid Build Coastguard Worker     static_assert ( std::is_same<decltype(  U"Hi"s), std::u32string>::value, "" );
34*58b9f456SAndroid Build Coastguard Worker 
35*58b9f456SAndroid Build Coastguard Worker     std::string foo;
36*58b9f456SAndroid Build Coastguard Worker     std::wstring Lfoo;
37*58b9f456SAndroid Build Coastguard Worker     u8string u8foo;
38*58b9f456SAndroid Build Coastguard Worker     std::u16string ufoo;
39*58b9f456SAndroid Build Coastguard Worker     std::u32string Ufoo;
40*58b9f456SAndroid Build Coastguard Worker 
41*58b9f456SAndroid Build Coastguard Worker     foo   =   ""s;     assert(  foo.size() == 0);
42*58b9f456SAndroid Build Coastguard Worker     u8foo = u8""s;     assert(u8foo.size() == 0);
43*58b9f456SAndroid Build Coastguard Worker     Lfoo  =  L""s;     assert( Lfoo.size() == 0);
44*58b9f456SAndroid Build Coastguard Worker     ufoo  =  u""s;     assert( ufoo.size() == 0);
45*58b9f456SAndroid Build Coastguard Worker     Ufoo  =  U""s;     assert( Ufoo.size() == 0);
46*58b9f456SAndroid Build Coastguard Worker 
47*58b9f456SAndroid Build Coastguard Worker     foo   =   " "s;    assert(  foo.size() == 1);
48*58b9f456SAndroid Build Coastguard Worker     u8foo = u8" "s;    assert(u8foo.size() == 1);
49*58b9f456SAndroid Build Coastguard Worker     Lfoo  =  L" "s;    assert( Lfoo.size() == 1);
50*58b9f456SAndroid Build Coastguard Worker     ufoo  =  u" "s;    assert( ufoo.size() == 1);
51*58b9f456SAndroid Build Coastguard Worker     Ufoo  =  U" "s;    assert( Ufoo.size() == 1);
52*58b9f456SAndroid Build Coastguard Worker 
53*58b9f456SAndroid Build Coastguard Worker     foo   =   "ABC"s;     assert(  foo ==   "ABC");   assert(  foo == std::string   (  "ABC"));
54*58b9f456SAndroid Build Coastguard Worker     u8foo = u8"ABC"s;     assert(u8foo == u8"ABC");   assert(u8foo == u8string      (u8"ABC"));
55*58b9f456SAndroid Build Coastguard Worker     Lfoo  =  L"ABC"s;     assert( Lfoo ==  L"ABC");   assert( Lfoo == std::wstring  ( L"ABC"));
56*58b9f456SAndroid Build Coastguard Worker     ufoo  =  u"ABC"s;     assert( ufoo ==  u"ABC");   assert( ufoo == std::u16string( u"ABC"));
57*58b9f456SAndroid Build Coastguard Worker     Ufoo  =  U"ABC"s;     assert( Ufoo ==  U"ABC");   assert( Ufoo == std::u32string( U"ABC"));
58*58b9f456SAndroid Build Coastguard Worker }
59