]>
Commit | Line | Data |
---|---|---|
83ac9249 | 1 | // { dg-do run } |
cd9b223a | 2 | // { dg-options "-std=gnu++14" } |
83ac9249 | 3 | |
818ab71a | 4 | // Copyright (C) 2013-2016 Free Software Foundation, Inc. |
83ac9249 ESR |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | // 27.7.6 - Quoted manipulators [quoted.manip] | |
22 | ||
23 | #include <string> | |
24 | #include <sstream> | |
25 | #include <iomanip> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | void | |
29 | test01() | |
30 | { | |
31 | // Basic test from paper. | |
32 | bool test [[gnu::unused]] = true; | |
33 | std::wstringstream ss; | |
34 | std::wstring original = L"foolish me"; | |
35 | std::wstring round_trip; | |
36 | ss << std::quoted(original); | |
37 | ss >> std::quoted(round_trip); | |
38 | VERIFY( original == round_trip ); | |
39 | } | |
40 | ||
41 | void | |
42 | test02() | |
43 | { | |
44 | // Test skipws correctness. | |
45 | bool test [[gnu::unused]] = true; | |
46 | std::wstringstream ss; | |
47 | ss << std::quoted(L"Hello Goodbye") << L' ' << 1 << L' ' << 2; | |
48 | std::wstring song; | |
49 | int thing1, thing2; | |
50 | ss >> std::quoted(song) >> thing1 >> thing2; | |
51 | VERIFY( song == L"Hello Goodbye" ); | |
52 | VERIFY( thing1 == 1 ); | |
53 | VERIFY( thing2 == 2 ); | |
54 | } | |
55 | ||
56 | void | |
57 | test03() | |
58 | { | |
59 | // Test read of unquoted string. | |
60 | bool test [[gnu::unused]] = true; | |
61 | std::wstringstream ss; | |
62 | ss << L"Alpha Omega"; | |
63 | std::wstring testit; | |
64 | ss >> std::quoted(testit); | |
65 | VERIFY( testit == L"Alpha" ); | |
66 | } | |
67 | ||
68 | auto | |
69 | test04(const std::wstring& message) | |
70 | { | |
71 | // Test 'const basic_string&' | |
72 | bool test [[gnu::unused]] = true; | |
73 | std::wstringstream ss; | |
74 | ss << L"** Error: " << std::quoted(message) << L" **"; | |
75 | return ss.str(); | |
76 | } | |
77 | ||
78 | int | |
79 | main() | |
80 | { | |
81 | test01(); | |
82 | test02(); | |
83 | test03(); | |
84 | auto ss = test04(L"My biscuits are burnin'!"); | |
85 | VERIFY( ss == L"** Error: \"My biscuits are burnin'!\" **" ); | |
86 | ||
87 | return 0; | |
88 | } |