822be9b238
This patch normalizes the casing of hexadecimal digits in escape sequences of the form `\xNN` and integer literals of the form `0xNNNN`. Previously, the V8 code base used an inconsistent mixture of uppercase and lowercase. Google’s C++ style guide uses uppercase in its examples: https://google.github.io/styleguide/cppguide.html#Non-ASCII_Characters Moreover, uppercase letters more clearly stand out from the lowercase `x` (or `u`) characters at the start, as well as lowercase letters elsewhere in strings. BUG=v8:7109 TBR=marja@chromium.org,titzer@chromium.org,mtrofin@chromium.org,mstarzinger@chromium.org,rossberg@chromium.org,yangguo@chromium.org,mlippautz@chromium.org NOPRESUBMIT=true Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I790e21c25d96ad5d95c8229724eb45d2aa9e22d6 Reviewed-on: https://chromium-review.googlesource.com/804294 Commit-Queue: Mathias Bynens <mathias@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#49810}
68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/ostreams.h"
|
|
|
|
#include "testing/gtest-support.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
TEST(Ostream, AsHex) {
|
|
auto testAsHex = [](const char* expected, const AsHex& value) {
|
|
std::ostringstream out;
|
|
out << value;
|
|
std::string result = out.str();
|
|
EXPECT_EQ(expected, result);
|
|
EXPECT_TRUE(result == expected)
|
|
<< "\nexpected: " << expected << "\ngot: " << result << "\n";
|
|
};
|
|
|
|
testAsHex("0", AsHex(0));
|
|
testAsHex("", AsHex(0, 0));
|
|
testAsHex("0x", AsHex(0, 0, true));
|
|
testAsHex("0x0", AsHex(0, 1, true));
|
|
testAsHex("0x00", AsHex(0, 2, true));
|
|
testAsHex("123", AsHex(0x123, 0));
|
|
testAsHex("0123", AsHex(0x123, 4));
|
|
testAsHex("0x123", AsHex(0x123, 0, true));
|
|
testAsHex("0x123", AsHex(0x123, 3, true));
|
|
testAsHex("0x0123", AsHex(0x123, 4, true));
|
|
testAsHex("0x00000123", AsHex(0x123, 8, true));
|
|
}
|
|
|
|
TEST(Ostream, AsHexBytes) {
|
|
auto testAsHexBytes = [](const char* expected, const AsHexBytes& value) {
|
|
std::ostringstream out;
|
|
out << value;
|
|
std::string result = out.str();
|
|
EXPECT_EQ(expected, result);
|
|
};
|
|
|
|
// Little endian (default):
|
|
testAsHexBytes("00", AsHexBytes(0));
|
|
testAsHexBytes("", AsHexBytes(0, 0));
|
|
testAsHexBytes("23 01", AsHexBytes(0x123));
|
|
testAsHexBytes("23 01", AsHexBytes(0x123, 1));
|
|
testAsHexBytes("23 01", AsHexBytes(0x123, 2));
|
|
testAsHexBytes("23 01 00", AsHexBytes(0x123, 3));
|
|
testAsHexBytes("ff ff ff ff", AsHexBytes(0xFFFFFFFF));
|
|
testAsHexBytes("00 00 00 00", AsHexBytes(0, 4));
|
|
testAsHexBytes("56 34 12", AsHexBytes(0x123456));
|
|
|
|
// Big endian:
|
|
testAsHexBytes("00", AsHexBytes(0, 1, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("", AsHexBytes(0, 0, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("01 23", AsHexBytes(0x123, 1, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("01 23", AsHexBytes(0x123, 1, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("01 23", AsHexBytes(0x123, 2, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("00 01 23", AsHexBytes(0x123, 3, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("ff ff ff ff", AsHexBytes(0xFFFFFFFF, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("00 00 00 00", AsHexBytes(0, 4, AsHexBytes::kBigEndian));
|
|
testAsHexBytes("12 34 56", AsHexBytes(0x123456, 1, AsHexBytes::kBigEndian));
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|