Debian Codegraph @

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/println.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
10
11 // TODO PRINT Investigate see https://reviews.llvm.org/D156585
12 // UNSUPPORTED: no-filesystem
13
14 // XFAIL: availability-fp_to_chars-missing
15
16 // <ostream>
17
18 // template<class... Args>
19 // void println(ostream& os, format_string<Args...> fmt, Args&&... args);
20 // void println(ostream& os); // since C++26
21
22 // [ostream.formatted.print]/3
23 // If the function is vprint_unicode and os is a stream that refers to
24 // a terminal capable of displaying Unicode which is determined in an
25 // implementation-defined manner, writes out to the terminal using the
26 // native Unicode API;
27 // This is tested in
28 // test/libcxx/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp
29
30 #include <cassert>
31 #include <ostream>
32 #include <sstream>
33
34 #include "assert_macros.h"
35 #include "concat_macros.h"
36 #include "print_tests.h"
37 #include "test_format_string.h"
38 #include "test_macros.h"
39
40 auto test_file = []<class... Args>(std::string_view e, test_format_string<char, Args...> fmt, Args&&... args) {
41 std::string expected = std::string{e} + '\n';
42
43 std::stringstream sstr;
44 std::println(sstr, fmt, std::forward<Args>(args)...);
45
46 std::string out = sstr.str();
47 TEST_REQUIRE(out == expected,
48 TEST_WRITE_CONCATENATED(
49 "\nFormat string ", fmt.get(), "\nExpected output ", expected, "\nActual output ", out, '\n'));
50 };
51
52 auto test_exception = []<class... Args>(std::string_view, std::string_view, Args&&...) {
53 // After P2216 most exceptions thrown by std::format become ill-formed.
54 // Therefore this tests does nothing.
55 // A basic ill-formed test is done in format.verify.cpp
56 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument.
57 };
58
59 void test_println_blank_line() {
60 std::string expected{'\n'};
61
62 std::stringstream sstr;
63 std::println(sstr);
64
65 std::string out = sstr.str();
66 TEST_REQUIRE(out == expected,
67 TEST_WRITE_CONCATENATED("\nExpected output (blank line) ", expected, "\nActual output ", out, '\n'));
68 };
69
70 int main(int, char**) {
71 print_tests(test_file, test_exception);
72 test_println_blank_line();
73
74 return 0;
75 }