-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for FMT_ENFORCE_COMPILE_STRING, fix several errors #2038
Merged
+145
−60
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
e05c8fc
Add test
f76c64a
fix wide string formatting
b75bd49
fix formatted_size
2f9484c
fix chrono
3b6d21b
clang-format, test fixes
aa65e99
fix ranges
54d6d5b
fix gcc test
e805e8e
workaround MSVC bug
1fbfccc
Improve docs
55600c9
fix ranges.h
35b94fa
increase MSVC version restriction
1e034bd
try a fix for strange gcc failures
900adeb
fix gcc pedantic error
7f1c041
fix gcc errors
d343e4b
fix MSVC version check #if statements
c4c8351
trim down compiletime test
60bceae
fixup chrono.h with better notes about MSVC workaround
b61537a
restore missing include
d539f76
cleanup doc string
dafbc05
fixup test
9fafb14
fix unused arg issue in test
2489501
fix gcc issue
b8ebadd
fixup chrono MSVC workaround
098de0d
Remove formatted_size overlaod accepting compile-time strings
8e575bd
address comments
f2a5a0f
restore ifdef guarding GCC bug
c85d5e3
address easy comments
b9063f9
remove vformat from chrono.h
98a8830
attempt stripping void casts
b0c65df
Refactor ranges, fix chrono, apply clang format to include/fmt/*.h
6f393f2
fixup constexpr issues
06a576c
revert locale format fix
99ed2a8
address feedback
5083486
move array of literals format test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,74 @@ | ||
// Formatting library for C++ - formatting library tests | ||
// | ||
// Copyright (c) 2012 - present, Victor Zverovich | ||
// All rights reserved. | ||
// | ||
// For the license information refer to format.h. | ||
|
||
#include <array> | ||
#include <chrono> | ||
#include <iterator> | ||
#include <list> | ||
#include <string> | ||
|
||
#include "fmt/chrono.h" | ||
#include "fmt/color.h" | ||
#include "fmt/format.h" | ||
#include "fmt/locale.h" | ||
#include "fmt/ostream.h" | ||
#include "fmt/ranges.h" | ||
|
||
// Exercise the API to verify that everything we expect to can compile. | ||
void test_format_api() { | ||
fmt::format(FMT_STRING("{}"), 42); | ||
fmt::format(FMT_STRING(L"{}"), 42); | ||
fmt::format(FMT_STRING("noop")); | ||
|
||
fmt::to_string(42); | ||
fmt::to_wstring(42); | ||
|
||
std::list<char> out; | ||
fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42); | ||
|
||
char buffer[4]; | ||
fmt::format_to_n(buffer, 3, FMT_STRING("{}"), 12345); | ||
|
||
wchar_t wbuffer[4]; | ||
fmt::format_to_n(wbuffer, 3, FMT_STRING(L"{}"), 12345); | ||
} | ||
|
||
void test_literals_api() { | ||
#if FMT_USE_UDL_TEMPLATE | ||
using namespace fmt::literals; | ||
"{}c{}"_format("ab", 1); | ||
L"{}c{}"_format(L"ab", 1); | ||
#endif | ||
} | ||
|
||
void test_chrono() { | ||
fmt::format(FMT_STRING("{}"), std::chrono::seconds(42)); | ||
fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42)); | ||
} | ||
|
||
void test_text_style() { | ||
fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)"); | ||
fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)"); | ||
|
||
fmt::text_style ts = fg(fmt::rgb(255, 20, 30)); | ||
std::string out; | ||
fmt::format_to(std::back_inserter(out), ts, | ||
FMT_STRING("rgb(255,20,30){}{}{}"), 1, 2, 3); | ||
} | ||
|
||
void test_range() { | ||
std::array<char, 5> hello = {'h', 'e', 'l', 'l', 'o'}; | ||
fmt::format(FMT_STRING("{}"), hello); | ||
} | ||
|
||
int main() { | ||
test_format_api(); | ||
test_literals_api(); | ||
test_chrono(); | ||
test_text_style(); | ||
test_range(); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto