#include <cassert>
#include <format>
#include <locale>
#include <sstream>
#include <thread>
#include "make_string.h"
#include "platform_support.h"
#include "test_macros.h"
template <class CharT>
static void basic() {
std::thread::id id0 = std::this_thread::get_id();
std::basic_ostringstream<CharT> os;
os << id0;
#if TEST_STD_VER > 20
std::basic_string<CharT> s = std::format(MAKE_STRING_VIEW(CharT, "{}"), id0);
assert(s == os.str());
#endif
}
template <class CharT>
static std::basic_string<CharT> format(std::ios_base::fmtflags flags) {
std::basic_stringstream<CharT> sstr;
sstr.flags(flags);
sstr << std::this_thread::get_id();
return sstr.str();
}
template <class CharT>
static void stream_state() {
std::basic_stringstream<CharT> sstr;
sstr << std::this_thread::get_id();
std::basic_string<CharT> expected = sstr.str();
assert(expected == format<CharT>(std::ios_base::dec | std::ios_base::skipws));
assert(expected == format<CharT>(std::ios_base::oct));
assert(expected == format<CharT>(std::ios_base::hex));
assert(expected == format<CharT>(std::ios_base::scientific));
assert(expected == format<CharT>(std::ios_base::fixed));
assert(expected == format<CharT>(std::ios_base::boolalpha));
assert(expected == format<CharT>(std::ios_base::showbase));
assert(expected == format<CharT>(std::ios_base::showpoint));
assert(expected == format<CharT>(std::ios_base::showpos));
assert(expected == format<CharT>(std::ios_base::skipws));
assert(expected == format<CharT>(std::ios_base::unitbuf));
assert(expected == format<CharT>(std::ios_base::uppercase));
sstr.str(std::basic_string<CharT>());
sstr.fill(CharT('#'));
sstr.width(expected.size() + 10);
sstr.flags(std::ios_base::dec | std::ios_base::skipws | std::ios_base::right);
sstr << std::this_thread::get_id();
expected = sstr.str();
sstr.str(std::basic_string<CharT>());
sstr.fill(CharT('*'));
sstr.width(expected.size());
sstr.flags(std::ios_base::dec | std::ios_base::skipws | std::ios_base::right);
sstr << std::this_thread::get_id();
assert(expected != sstr.str());
sstr.str(std::basic_string<CharT>());
sstr.fill(CharT('#'));
sstr.width(expected.size() - 1);
sstr.flags(std::ios_base::dec | std::ios_base::skipws | std::ios_base::right);
sstr << std::this_thread::get_id();
assert(expected != sstr.str());
sstr.str(std::basic_string<CharT>());
sstr.fill(CharT('#'));
sstr.width(expected.size());
sstr.flags(std::ios_base::dec | std::ios_base::skipws | std::ios_base::left);
sstr << std::this_thread::get_id();
assert(expected != sstr.str());
sstr.str(std::basic_string<CharT>());
sstr.fill(CharT('#'));
sstr.width(expected.size());
sstr.flags(std::ios_base::dec | std::ios_base::skipws | std::ios_base::internal);
sstr << std::this_thread::get_id();
assert(expected == sstr.str());
std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
sstr.str(std::basic_string<CharT>());
sstr.fill(CharT('#'));
sstr.width(expected.size());
sstr << std::this_thread::get_id();
assert(expected == sstr.str());
}
template <class CharT>
static void test() {
basic<CharT>();
stream_state<CharT>();
}
int main(int, char**) {
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<wchar_t>();
#endif
return 0;
}