-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<format>: Assume UTF-8 format strings when execution charset is UTF-8 (…
…#1824) * Assume format strings are always UTF-8 when encoding charset is UTF-8 * Add `/utf-8` tests * Run Shift-JIS tests with `/execution-charset:.932` * Apply code review feedback * constexpr function implies inline * Code review feedback. * Mitigate merge conflicts: Use _THROW. * Mitigate merge conflicts: Check setlocale(), reset to "C". Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
- Loading branch information
1 parent
de11c9a
commit b81d9eb
Showing
10 changed files
with
397 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#pragma once | ||
|
||
#include <cassert> | ||
#include <cstddef> | ||
#include <format> | ||
#include <string_view> | ||
#include <utility> | ||
|
||
// copied from the string_view tests | ||
template <typename CharT> | ||
struct choose_literal; // not defined | ||
|
||
template <> | ||
struct choose_literal<char> { | ||
static constexpr const char* choose(const char* s, const wchar_t*) { | ||
return s; | ||
} | ||
}; | ||
|
||
template <> | ||
struct choose_literal<wchar_t> { | ||
static constexpr const wchar_t* choose(const char*, const wchar_t* s) { | ||
return s; | ||
} | ||
}; | ||
|
||
#define TYPED_LITERAL(CharT, Literal) (choose_literal<CharT>::choose(Literal, L##Literal)) | ||
|
||
template <typename CharT> | ||
struct noop_testing_callbacks { | ||
constexpr void _On_align(std::_Align) {} | ||
constexpr void _On_fill(std::basic_string_view<CharT>) {} | ||
constexpr void _On_width(unsigned int) {} | ||
constexpr void _On_dynamic_width(std::size_t) {} | ||
constexpr void _On_dynamic_width(std::_Auto_id_tag) {} | ||
constexpr void _On_precision(unsigned int) {} | ||
constexpr void _On_dynamic_precision(std::size_t) {} | ||
constexpr void _On_dynamic_precision(std::_Auto_id_tag) {} | ||
constexpr void _On_sign(std::_Sign) {} | ||
constexpr void _On_hash() {} | ||
constexpr void _On_zero() {} | ||
constexpr void _On_localized() {} | ||
constexpr void _On_type(CharT) {} | ||
}; | ||
|
||
template <typename CharT> | ||
struct testing_callbacks { | ||
std::_Align expected_alignment = std::_Align::_None; | ||
std::_Sign expected_sign = std::_Sign::_None; | ||
std::basic_string_view<CharT> expected_fill; | ||
int expected_width = -1; | ||
std::size_t expected_dynamic_width = static_cast<std::size_t>(-1); | ||
bool expected_auto_dynamic_width = false; | ||
int expected_precision = -1; | ||
std::size_t expected_dynamic_precision = static_cast<std::size_t>(-1); | ||
bool expected_auto_dynamic_precision = false; | ||
bool expected_hash = false; | ||
bool expected_zero = false; | ||
bool expected_localized = false; | ||
CharT expected_type = '\0'; | ||
|
||
constexpr void _On_align(std::_Align aln) { | ||
assert(aln == expected_alignment); | ||
} | ||
constexpr void _On_fill(std::basic_string_view<CharT> str_view) { | ||
assert(str_view == expected_fill); | ||
} | ||
constexpr void _On_width(int width) { | ||
assert(width == expected_width); | ||
} | ||
constexpr void _On_dynamic_width(std::size_t id) { | ||
assert(id == expected_dynamic_width); | ||
} | ||
constexpr void _On_dynamic_width(std::_Auto_id_tag) { | ||
assert(expected_auto_dynamic_width); | ||
} | ||
constexpr void _On_precision(int pre) { | ||
assert(pre == expected_precision); | ||
} | ||
constexpr void _On_dynamic_precision(std::size_t id) { | ||
assert(id == expected_dynamic_precision); | ||
} | ||
constexpr void _On_dynamic_precision(std::_Auto_id_tag) { | ||
assert(expected_auto_dynamic_precision); | ||
} | ||
constexpr void _On_sign(std::_Sign sgn) { | ||
assert(sgn == expected_sign); | ||
} | ||
constexpr void _On_hash() { | ||
assert(expected_hash); | ||
} | ||
constexpr void _On_zero() { | ||
assert(expected_zero); | ||
} | ||
constexpr void _On_localized() { | ||
assert(expected_localized); | ||
} | ||
constexpr void _On_type(CharT type) { | ||
assert(type == expected_type); | ||
} | ||
}; | ||
template <typename CharT> | ||
testing_callbacks(std::_Align, std::basic_string_view<CharT>) -> testing_callbacks<CharT>; | ||
|
||
struct testing_arg_id_callbacks { | ||
constexpr void _On_auto_id() {} | ||
constexpr void _On_manual_id(std::size_t) {} | ||
}; | ||
|
||
template <typename CharT, typename callback_type> | ||
void test_parse_helper(const CharT* (*func)(const CharT*, const CharT*, callback_type&&), | ||
std::basic_string_view<CharT> view, bool err_expected = false, | ||
typename std::basic_string_view<CharT>::size_type expected_end_position = std::basic_string_view<CharT>::npos, | ||
callback_type&& callbacks = {}) { | ||
try { | ||
auto end = func(view.data(), view.data() + view.size(), std::move(callbacks)); | ||
if (expected_end_position != std::basic_string_view<CharT>::npos) { | ||
assert(end == view.data() + expected_end_position); | ||
} | ||
assert(!err_expected); | ||
} catch (const std::format_error&) { | ||
assert(err_expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.