mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 11:28:20 +00:00
Test invalid fill
This commit is contained in:
parent
8a3a8177d6
commit
b4218aa0f8
@ -962,8 +962,9 @@ template <typename T = void> struct null {};
|
||||
// Workaround an array initialization issue in gcc 4.8.
|
||||
template <typename Char> struct fill_t {
|
||||
private:
|
||||
enum { max_size = 5 };
|
||||
Char data_[max_size + 1];
|
||||
enum { max_size = 4 };
|
||||
Char data_[max_size];
|
||||
unsigned char size_;
|
||||
|
||||
public:
|
||||
FMT_CONSTEXPR void operator=(basic_string_view<Char> s) {
|
||||
@ -973,15 +974,10 @@ template <typename Char> struct fill_t {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < size; ++i) data_[i] = s[i];
|
||||
data_[size] = Char();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
size_t i = 1;
|
||||
while (data_[i] && i <= max_size) ++i;
|
||||
return i;
|
||||
size_ = static_cast<unsigned char>(size);
|
||||
}
|
||||
|
||||
size_t size() const { return size_; }
|
||||
const Char* data() const { return data_; }
|
||||
|
||||
FMT_CONSTEXPR Char& operator[](size_t index) { return data_[index]; }
|
||||
@ -992,6 +988,7 @@ template <typename Char> struct fill_t {
|
||||
static FMT_CONSTEXPR fill_t<Char> make() {
|
||||
auto fill = fill_t<Char>();
|
||||
fill[0] = Char(' ');
|
||||
fill.size_ = 1;
|
||||
return fill;
|
||||
}
|
||||
};
|
||||
|
@ -816,6 +816,8 @@ TEST(FormatterTest, Fill) {
|
||||
EXPECT_EQ("foo=", format("{:}=", "foo"));
|
||||
EXPECT_EQ(std::string("\0\0\0*", 4), format(string_view("{:\0>4}", 6), '*'));
|
||||
EXPECT_EQ("жж42", format("{0:ж>4}", 42));
|
||||
EXPECT_THROW_MSG(format("{:\x80\x80\x80\x80\x80>}", 0), format_error,
|
||||
"invalid fill");
|
||||
}
|
||||
|
||||
TEST(FormatterTest, PlusSign) {
|
||||
|
Loading…
Reference in New Issue
Block a user