Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize floating values locale-independent
Closes: #281
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "prometheus/counter.h" | ||
#include "prometheus/family.h" | ||
#include "prometheus/text_serializer.h" | ||
|
||
#include <gmock/gmock.h> | ||
#include <locale> | ||
|
||
namespace prometheus { | ||
namespace { | ||
|
||
TEST(SerializerTest, shouldSerializeLocaleIndependent) { | ||
Family<Counter> family{"requests_total", "", {}}; | ||
auto& counter = family.Add({}); | ||
counter.Increment(); | ||
const auto collected = family.Collect(); | ||
|
||
// save and change locale | ||
const std::locale oldLocale = std::locale::classic(); | ||
std::locale::global(std::locale("de_DE.UTF-8")); | ||
|
||
TextSerializer textSerializer; | ||
const auto serialized = textSerializer.Serialize(collected); | ||
EXPECT_THAT(serialized, testing::HasSubstr("1.0")); | ||
|
||
// restore locale | ||
std::locale::global(oldLocale); | ||
} | ||
|
||
} // namespace | ||
} // namespace prometheus |