]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/manipulators/standard/char/quoted_sv.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / manipulators / standard / char / quoted_sv.cc
1 // { dg-do run { target c++17 } }
2
3 // Copyright (C) 2018-2023 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // C++17 30.7.8 - Quoted manipulators [quoted.manip]
21
22 #include <string_view>
23 #include <sstream>
24 #include <iomanip>
25 #include <testsuite_hooks.h>
26
27 void
28 test01()
29 {
30 std::stringstream ss;
31 const std::string_view original = R"(This "string" will be \"quoted\")";
32 std::string raw, round_trip;
33 ss << std::quoted(original);
34 raw = ss.str();
35 VERIFY( raw == R"("This \"string\" will be \\\"quoted\\\"")" );
36 ss >> std::quoted(round_trip);
37 VERIFY( original == round_trip );
38 }
39
40 void
41 test02()
42 {
43 std::stringstream ss;
44 const std::string_view original = R"(This "string" will be \"quoted\")";
45 std::string raw, round_trip;
46 ss << std::quoted(original, '\'', '!');
47 raw = ss.str();
48 VERIFY( raw == R"('This "string" will be \"quoted\"')" );
49 ss >> std::quoted(round_trip, '\'', '!');
50 VERIFY( original == round_trip );
51 }
52
53 void
54 test03()
55 {
56 std::stringstream ss;
57 const std::string_view original = R"(This 'string' will be !'quoted!')";
58 std::string raw, round_trip;
59 ss << std::quoted(original, '\'', '!');
60 raw = ss.str();
61 VERIFY( raw == R"('This !'string!' will be !!!'quoted!!!'')" );
62 ss >> std::quoted(round_trip, '\'', '!');
63 VERIFY( original == round_trip );
64 }
65
66 int
67 main()
68 {
69 test01();
70 test02();
71 test03();
72 }