Commit fc979660 authored by Nigel Tao's avatar Nigel Tao Committed by Commit Bot

clang-format string_number_conversions_unittest.cc

This will minimize the diff for a follow-up commit.

Change-Id: I79bfaf5913550acb9c579e3e2037012241c6639b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310050
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790650}
parent 979cb165
...@@ -44,7 +44,8 @@ TEST(StringNumberConversionsTest, NumberToString) { ...@@ -44,7 +44,8 @@ TEST(StringNumberConversionsTest, NumberToString) {
{0, "0", "0"}, {0, "0", "0"},
{-1, "-1", "18446744073709551615"}, {-1, "-1", "18446744073709551615"},
{ {
std::numeric_limits<int64_t>::max(), "9223372036854775807", std::numeric_limits<int64_t>::max(),
"9223372036854775807",
"9223372036854775807", "9223372036854775807",
}, },
{std::numeric_limits<int64_t>::min(), "-9223372036854775808", {std::numeric_limits<int64_t>::min(), "-9223372036854775808",
...@@ -114,7 +115,9 @@ TEST(StringNumberConversionsTest, StringToInt) { ...@@ -114,7 +115,9 @@ TEST(StringNumberConversionsTest, StringToInt) {
{"0", 0, true}, {"0", 0, true},
{"42", 42, true}, {"42", 42, true},
{"42\x99", 42, false}, {"42\x99", 42, false},
{"\x99" "42\x99", 0, false}, {"\x99"
"42\x99",
0, false},
{"-2147483648", INT_MIN, true}, {"-2147483648", INT_MIN, true},
{"2147483647", INT_MAX, true}, {"2147483647", INT_MAX, true},
{"", 0, false}, {"", 0, false},
...@@ -163,7 +166,7 @@ TEST(StringNumberConversionsTest, StringToInt) { ...@@ -163,7 +166,7 @@ TEST(StringNumberConversionsTest, StringToInt) {
EXPECT_EQ(6, output); EXPECT_EQ(6, output);
output = 0; output = 0;
const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0}; const char16 negative_wide_input[] = {0xFF4D, '4', '2', 0};
EXPECT_FALSE(StringToInt(string16(negative_wide_input), &output)); EXPECT_FALSE(StringToInt(string16(negative_wide_input), &output));
EXPECT_EQ(0, output); EXPECT_EQ(0, output);
} }
...@@ -177,7 +180,9 @@ TEST(StringNumberConversionsTest, StringToUint) { ...@@ -177,7 +180,9 @@ TEST(StringNumberConversionsTest, StringToUint) {
{"0", 0, true}, {"0", 0, true},
{"42", 42, true}, {"42", 42, true},
{"42\x99", 42, false}, {"42\x99", 42, false},
{"\x99" "42\x99", 0, false}, {"\x99"
"42\x99",
0, false},
{"-2147483648", 0, false}, {"-2147483648", 0, false},
{"2147483647", INT_MAX, true}, {"2147483647", INT_MAX, true},
{"", 0, false}, {"", 0, false},
...@@ -227,7 +232,7 @@ TEST(StringNumberConversionsTest, StringToUint) { ...@@ -227,7 +232,7 @@ TEST(StringNumberConversionsTest, StringToUint) {
EXPECT_EQ(6U, output); EXPECT_EQ(6U, output);
output = 0; output = 0;
const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0}; const char16 negative_wide_input[] = {0xFF4D, '4', '2', 0};
EXPECT_FALSE(StringToUint(string16(negative_wide_input), &output)); EXPECT_FALSE(StringToUint(string16(negative_wide_input), &output));
EXPECT_EQ(0U, output); EXPECT_EQ(0U, output);
} }
...@@ -478,7 +483,9 @@ TEST(StringNumberConversionsTest, HexStringToInt) { ...@@ -478,7 +483,9 @@ TEST(StringNumberConversionsTest, HexStringToInt) {
// One additional test to verify that conversion of numbers in strings with // One additional test to verify that conversion of numbers in strings with
// embedded NUL characters. The NUL and extra data after it should be // embedded NUL characters. The NUL and extra data after it should be
// interpreted as junk after the number. // interpreted as junk after the number.
const char input[] = "0xc0ffee\0" "9"; const char input[] =
"0xc0ffee\0"
"9";
std::string input_string(input, base::size(input) - 1); std::string input_string(input, base::size(input) - 1);
int output; int output;
EXPECT_FALSE(HexStringToInt(input_string, &output)); EXPECT_FALSE(HexStringToInt(input_string, &output));
...@@ -543,7 +550,9 @@ TEST(StringNumberConversionsTest, HexStringToUInt) { ...@@ -543,7 +550,9 @@ TEST(StringNumberConversionsTest, HexStringToUInt) {
// One additional test to verify that conversion of numbers in strings with // One additional test to verify that conversion of numbers in strings with
// embedded NUL characters. The NUL and extra data after it should be // embedded NUL characters. The NUL and extra data after it should be
// interpreted as junk after the number. // interpreted as junk after the number.
const char input[] = "0xc0ffee\0" "9"; const char input[] =
"0xc0ffee\0"
"9";
std::string input_string(input, base::size(input) - 1); std::string input_string(input, base::size(input) - 1);
uint32_t output; uint32_t output;
EXPECT_FALSE(HexStringToUInt(input_string, &output)); EXPECT_FALSE(HexStringToUInt(input_string, &output));
...@@ -602,7 +611,9 @@ TEST(StringNumberConversionsTest, HexStringToInt64) { ...@@ -602,7 +611,9 @@ TEST(StringNumberConversionsTest, HexStringToInt64) {
// One additional test to verify that conversion of numbers in strings with // One additional test to verify that conversion of numbers in strings with
// embedded NUL characters. The NUL and extra data after it should be // embedded NUL characters. The NUL and extra data after it should be
// interpreted as junk after the number. // interpreted as junk after the number.
const char input[] = "0xc0ffee\0" "9"; const char input[] =
"0xc0ffee\0"
"9";
std::string input_string(input, base::size(input) - 1); std::string input_string(input, base::size(input) - 1);
int64_t output; int64_t output;
EXPECT_FALSE(HexStringToInt64(input_string, &output)); EXPECT_FALSE(HexStringToInt64(input_string, &output));
...@@ -665,7 +676,9 @@ TEST(StringNumberConversionsTest, HexStringToUInt64) { ...@@ -665,7 +676,9 @@ TEST(StringNumberConversionsTest, HexStringToUInt64) {
// One additional test to verify that conversion of numbers in strings with // One additional test to verify that conversion of numbers in strings with
// embedded NUL characters. The NUL and extra data after it should be // embedded NUL characters. The NUL and extra data after it should be
// interpreted as junk after the number. // interpreted as junk after the number.
const char input[] = "0xc0ffee\0" "9"; const char input[] =
"0xc0ffee\0"
"9";
std::string input_string(input, base::size(input) - 1); std::string input_string(input, base::size(input) - 1);
uint64_t output; uint64_t output;
EXPECT_FALSE(HexStringToUInt64(input_string, &output)); EXPECT_FALSE(HexStringToUInt64(input_string, &output));
...@@ -695,8 +708,8 @@ TEST(StringNumberConversionsTest, HexStringToBytesStringSpan) { ...@@ -695,8 +708,8 @@ TEST(StringNumberConversionsTest, HexStringToBytesStringSpan) {
{"efgh", "\xef", 1, false}, {"efgh", "\xef", 1, false},
{"", "", 0, false}, {"", "", 0, false},
{"0123456789ABCDEF", "\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8, true}, {"0123456789ABCDEF", "\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8, true},
{"0123456789ABCDEF012345", {"0123456789ABCDEF012345", "\x01\x23\x45\x67\x89\xAB\xCD\xEF\x01\x23\x45",
"\x01\x23\x45\x67\x89\xAB\xCD\xEF\x01\x23\x45", 11, true}, 11, true},
}; };
for (size_t test_i = 0; test_i < base::size(cases); ++test_i) { for (size_t test_i = 0; test_i < base::size(cases); ++test_i) {
...@@ -854,7 +867,9 @@ TEST(StringNumberConversionsTest, StringToDouble) { ...@@ -854,7 +867,9 @@ TEST(StringNumberConversionsTest, StringToDouble) {
// One additional test to verify that conversion of numbers in strings with // One additional test to verify that conversion of numbers in strings with
// embedded NUL characters. The NUL and extra data after it should be // embedded NUL characters. The NUL and extra data after it should be
// interpreted as junk after the number. // interpreted as junk after the number.
const char input[] = "3.14\0" "159"; const char input[] =
"3.14\0"
"159";
std::string input_string(input, base::size(input) - 1); std::string input_string(input, base::size(input) - 1);
double output; double output;
EXPECT_FALSE(StringToDouble(input_string, &output)); EXPECT_FALSE(StringToDouble(input_string, &output));
...@@ -886,8 +901,8 @@ TEST(StringNumberConversionsTest, DoubleToString) { ...@@ -886,8 +901,8 @@ TEST(StringNumberConversionsTest, DoubleToString) {
double input = 0; double input = 0;
memcpy(&input, input_bytes, base::size(input_bytes)); memcpy(&input, input_bytes, base::size(input_bytes));
EXPECT_EQ("1.335179083776e+12", NumberToString(input)); EXPECT_EQ("1.335179083776e+12", NumberToString(input));
const char input_bytes2[8] = const char input_bytes2[8] = {0, 0, 0, '\xa0',
{0, 0, 0, '\xa0', '\xda', '\x6c', '\x73', '\x42'}; '\xda', '\x6c', '\x73', '\x42'};
input = 0; input = 0;
memcpy(&input, input_bytes2, base::size(input_bytes2)); memcpy(&input, input_bytes2, base::size(input_bytes2));
EXPECT_EQ("1.33489033216e+12", NumberToString(input)); EXPECT_EQ("1.33489033216e+12", NumberToString(input));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment