blob: cbb03ef61f11ee01cfa113fe68f2d942c1fe1cb9 [file] [log] [blame]
Marshall Clowca0be232013-07-23 17:05:24 +00001// -*- 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 Rathnayake6edc12c2016-05-28 08:57:35 +000010
11// UNSUPPORTED: c++98, c++03, c++11
12
Marshall Clowca0be232013-07-23 17:05:24 +000013#include <string>
14#include <cassert>
15
Marshall Clow289f1ce2018-11-20 22:55:40 +000016#include "test_macros.h"
17
Marshall Clow7dad0bd2018-12-11 04:35:44 +000018#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 Clowca0be232013-07-23 17:05:24 +000025int main()
26{
Marshall Clowca0be232013-07-23 17:05:24 +000027 using namespace std::literals::string_literals;
28
Howard Hinnantd0987132013-08-07 19:39:48 +000029 static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" );
Marshall Clow7dad0bd2018-12-11 04:35:44 +000030 static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" );
Howard Hinnantd0987132013-08-07 19:39:48 +000031 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 Fiselierd04c6852016-06-01 21:35:39 +000034
Howard Hinnantd0987132013-08-07 19:39:48 +000035 std::string foo;
36 std::wstring Lfoo;
Marshall Clow7dad0bd2018-12-11 04:35:44 +000037 u8string u8foo;
Howard Hinnantd0987132013-08-07 19:39:48 +000038 std::u16string ufoo;
39 std::u32string Ufoo;
Eric Fiselierd04c6852016-06-01 21:35:39 +000040
Marshall Clow7dad0bd2018-12-11 04:35:44 +000041 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 Fiselierd04c6852016-06-01 21:35:39 +000046
Marshall Clow7dad0bd2018-12-11 04:35:44 +000047 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 Fiselierd04c6852016-06-01 21:35:39 +000052
Marshall Clow7dad0bd2018-12-11 04:35:44 +000053 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 Clowca0be232013-07-23 17:05:24 +000058}