blob: a51d0d9ac8c0fc59aa673a9a4761ad7d6154a7c9 [file] [log] [blame]
Marshall Clowca0be232013-07-23 17:05:24 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Chandler Carruth57b08b02019-01-19 10:56:40 +00004// 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 Clowca0be232013-07-23 17:05:24 +00007//
8//===----------------------------------------------------------------------===//
Asiri Rathnayake6edc12c2016-05-28 08:57:35 +00009
10// UNSUPPORTED: c++98, c++03, c++11
11
Marshall Clowca0be232013-07-23 17:05:24 +000012#include <string>
13#include <cassert>
14
Marshall Clow289f1ce2018-11-20 22:55:40 +000015#include "test_macros.h"
16
Marshall Clow7dad0bd2018-12-11 04:35:44 +000017#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 Bastien2df59c52019-02-04 20:31:13 +000024int main(int, char**)
Marshall Clowca0be232013-07-23 17:05:24 +000025{
Marshall Clowca0be232013-07-23 17:05:24 +000026 using namespace std::literals::string_literals;
27
Howard Hinnantd0987132013-08-07 19:39:48 +000028 static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" );
Marshall Clow7dad0bd2018-12-11 04:35:44 +000029 static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" );
Howard Hinnantd0987132013-08-07 19:39:48 +000030 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 Fiselierd04c6852016-06-01 21:35:39 +000033
Howard Hinnantd0987132013-08-07 19:39:48 +000034 std::string foo;
35 std::wstring Lfoo;
Marshall Clow7dad0bd2018-12-11 04:35:44 +000036 u8string u8foo;
Howard Hinnantd0987132013-08-07 19:39:48 +000037 std::u16string ufoo;
38 std::u32string Ufoo;
Eric Fiselierd04c6852016-06-01 21:35:39 +000039
Marshall Clow7dad0bd2018-12-11 04:35:44 +000040 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 Fiselierd04c6852016-06-01 21:35:39 +000045
Marshall Clow7dad0bd2018-12-11 04:35:44 +000046 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 Fiselierd04c6852016-06-01 21:35:39 +000051
Marshall Clow7dad0bd2018-12-11 04:35:44 +000052 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 Bastien2df59c52019-02-04 20:31:13 +000057
58 return 0;
Marshall Clowca0be232013-07-23 17:05:24 +000059}