Title: [265344] trunk
Revision
265344
Author
ddkil...@apple.com
Date
2020-08-06 13:09:15 -0700 (Thu, 06 Aug 2020)

Log Message

WTF::makeString() should handle enum values
<https://webkit.org/b/214906>

Reviewed by Sam Weinig.

Source/WebCore:

* Modules/webgpu/WHLSL/Metal/WHLSLMangledNames.h:
(WTF::MangledNameAdaptor::length):
(WTF::MangledNameAdaptor::writeTo):
- Update for function renames.

Source/WebKit:

* Platform/IPC/cocoa/ConnectionCocoa.mm:
(IPC::Connection::sendMessage):
* Shared/Cocoa/AuxiliaryProcessCocoa.mm:
(WebKit::AuxiliaryProcess::didReceiveInvalidMessage):
- Update to take advantage of enum support in WTF::makeString().

Source/WTF:

* wtf/text/IntegerToStringConversion.h:
(WTF::numberToStringSigned):
- Drive-by fix to change std::make_unsigned<>::type to
  std::make_unsigned_t<>.
(WTF::writeNumberToBufferImpl): Delete.
(WTF::writeIntegerToBufferImpl):
- Rename from WTF::writeNumberToBufferImpl().
(WTF::writeNumberToBufferSigned): Delete.
(WTF::writeNumberToBufferUnsigned): Delete.
(WTF::writeIntegerToBuffer):
- Replace WTF::writeNumberToBufferSigned() and
  WTF::writeNumberToBufferUnsigned() with a single function that
  uses constexpr checks to let the compiler eliminate code.  Had
  to use if/else if/else construct to help the compiler
  eliminate unused cases.
(WTF::lengthOfNumberAsStringImpl): Delete.
(WTF::lengthOfIntegerAsStringImpl):
- Rename from WTF::lengthOfNumberAsStringImpl().
(WTF::lengthOfNumberAsStringSigned): Delete.
(WTF::lengthOfNumberAsStringUnsigned): Delete.
(WTF::lengthOfIntegerAsString):
- Replace WTF::lengthOfNumberAsStringSigned() and
  WTF::lengthOfNumberAsStringUnsigned() with a single function
  that uses constexpr checks to let the compiler eliminate code.
  Had to use if/else if/else construct to help the compiler
  eliminate unused cases.

* wtf/text/StringConcatenateNumbers.h:
(WTF::StringTypeAdapter<SignedInt, ...>): Deleted.
(WTF::StringTypeAdapter<UnignedInt, ...>): Deleted.
(WTF::StringTypeAdapter<Integer, ...>):
- Combine signed/unsigned templated classes into a single class
  now that WTF::lengthOfIntegerAsString() and
  WTF::writeIntegerToBuffer() are templated.
(WTF::StringTypeAdapter<Enum, ...>):
- Add support for enum types to WTF::makeString().  This also
  takes advantage of templated WTF::lengthOfIntegerAsString()
  and WTF::writeIntegerToBuffer() functions since enum types may
  be either signed or unsigned.

Tools:

* TestWebKitAPI/Tests/WTF/StringConcatenate.cpp:
(TestWebKitAPI::TEST):
- Update tests for renamed functions.
- Add test for enum values.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (265343 => 265344)


--- trunk/Source/WTF/ChangeLog	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WTF/ChangeLog	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,3 +1,50 @@
+2020-08-06  David Kilzer  <ddkil...@apple.com>
+
+        WTF::makeString() should handle enum values
+        <https://webkit.org/b/214906>
+
+        Reviewed by Sam Weinig.
+
+        * wtf/text/IntegerToStringConversion.h:
+        (WTF::numberToStringSigned):
+        - Drive-by fix to change std::make_unsigned<>::type to
+          std::make_unsigned_t<>.
+        (WTF::writeNumberToBufferImpl): Delete.
+        (WTF::writeIntegerToBufferImpl):
+        - Rename from WTF::writeNumberToBufferImpl().
+        (WTF::writeNumberToBufferSigned): Delete.
+        (WTF::writeNumberToBufferUnsigned): Delete.
+        (WTF::writeIntegerToBuffer):
+        - Replace WTF::writeNumberToBufferSigned() and
+          WTF::writeNumberToBufferUnsigned() with a single function that
+          uses constexpr checks to let the compiler eliminate code.  Had
+          to use if/else if/else construct to help the compiler
+          eliminate unused cases.
+        (WTF::lengthOfNumberAsStringImpl): Delete.
+        (WTF::lengthOfIntegerAsStringImpl):
+        - Rename from WTF::lengthOfNumberAsStringImpl().
+        (WTF::lengthOfNumberAsStringSigned): Delete.
+        (WTF::lengthOfNumberAsStringUnsigned): Delete.
+        (WTF::lengthOfIntegerAsString):
+        - Replace WTF::lengthOfNumberAsStringSigned() and
+          WTF::lengthOfNumberAsStringUnsigned() with a single function
+          that uses constexpr checks to let the compiler eliminate code.
+          Had to use if/else if/else construct to help the compiler
+          eliminate unused cases.
+
+        * wtf/text/StringConcatenateNumbers.h:
+        (WTF::StringTypeAdapter<SignedInt, ...>): Deleted.
+        (WTF::StringTypeAdapter<UnignedInt, ...>): Deleted.
+        (WTF::StringTypeAdapter<Integer, ...>):
+        - Combine signed/unsigned templated classes into a single class
+          now that WTF::lengthOfIntegerAsString() and
+          WTF::writeIntegerToBuffer() are templated.
+        (WTF::StringTypeAdapter<Enum, ...>):
+        - Add support for enum types to WTF::makeString().  This also
+          takes advantage of templated WTF::lengthOfIntegerAsString()
+          and WTF::writeIntegerToBuffer() functions since enum types may
+          be either signed or unsigned.
+
 2020-08-05  Tim Horton  <timothy_hor...@apple.com>
 
         Remove all references to non-existent 10.16

Modified: trunk/Source/WTF/wtf/text/IntegerToStringConversion.h (265343 => 265344)


--- trunk/Source/WTF/wtf/text/IntegerToStringConversion.h	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WTF/wtf/text/IntegerToStringConversion.h	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2012-2020 Apple Inc. All Rights Reserved.
  * Copyright (C) 2012 Patrick Gansterer <par...@paroga.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -51,8 +51,8 @@
 inline typename IntegerToStringConversionTrait<T>::ReturnType numberToStringSigned(SignedIntegerType number, typename IntegerToStringConversionTrait<T>::AdditionalArgumentType* additionalArgument = nullptr)
 {
     if (number < 0)
-        return numberToStringImpl<T, typename std::make_unsigned<SignedIntegerType>::type, NegativeNumber>(-number, additionalArgument);
-    return numberToStringImpl<T, typename std::make_unsigned<SignedIntegerType>::type, PositiveNumber>(number, additionalArgument);
+        return numberToStringImpl<T, typename std::make_unsigned_t<SignedIntegerType>, NegativeNumber>(-number, additionalArgument);
+    return numberToStringImpl<T, typename std::make_unsigned_t<SignedIntegerType>, PositiveNumber>(number, additionalArgument);
 }
 
 template<typename T, typename UnsignedIntegerType>
@@ -62,7 +62,7 @@
 }
 
 template<typename CharacterType, typename UnsignedIntegerType, PositiveOrNegativeNumber NumberType>
-static void writeNumberToBufferImpl(UnsignedIntegerType number, CharacterType* destination)
+static void writeIntegerToBufferImpl(UnsignedIntegerType number, CharacterType* destination)
 {
     static_assert(!std::is_same_v<bool, std::remove_cv_t<UnsignedIntegerType>>, "'bool' not supported");
     LChar buf[sizeof(UnsignedIntegerType) * 3 + 1];
@@ -81,22 +81,22 @@
         *destination++ = static_cast<CharacterType>(*p++);
 }
 
-template<typename CharacterType, typename SignedIntegerType>
-inline void writeNumberToBufferSigned(SignedIntegerType number, CharacterType* destination)
+template<typename CharacterType, typename IntegerType>
+inline void writeIntegerToBuffer(IntegerType integer, CharacterType* destination)
 {
-    if (number < 0)
-        return writeNumberToBufferImpl<CharacterType, typename std::make_unsigned<SignedIntegerType>::type, NegativeNumber>(-number, destination);
-    return writeNumberToBufferImpl<CharacterType, typename std::make_unsigned<SignedIntegerType>::type, PositiveNumber>(number, destination);
+    static_assert(std::is_integral_v<IntegerType>);
+    if constexpr (std::is_same_v<IntegerType, bool>)
+        return writeIntegerToBufferImpl<CharacterType, uint8_t, PositiveNumber>(integer ? 1 : 0, destination);
+    else if constexpr (std::is_signed_v<IntegerType>) {
+        if (integer < 0)
+            return writeIntegerToBufferImpl<CharacterType, typename std::make_unsigned_t<IntegerType>, NegativeNumber>(-integer, destination);
+        return writeIntegerToBufferImpl<CharacterType, typename std::make_unsigned_t<IntegerType>, PositiveNumber>(integer, destination);
+    } else
+        return writeIntegerToBufferImpl<CharacterType, IntegerType, PositiveNumber>(integer, destination);
 }
 
-template<typename CharacterType, typename UnsignedIntegerType>
-inline void writeNumberToBufferUnsigned(UnsignedIntegerType number, CharacterType* destination)
-{
-    return writeNumberToBufferImpl<CharacterType, UnsignedIntegerType, PositiveNumber>(number, destination);
-}
-
 template<typename UnsignedIntegerType, PositiveOrNegativeNumber NumberType>
-static unsigned lengthOfNumberAsStringImpl(UnsignedIntegerType number)
+static unsigned lengthOfIntegerAsStringImpl(UnsignedIntegerType number)
 {
     unsigned length = 0;
 
@@ -111,18 +111,18 @@
     return length;
 }
 
-template<typename SignedIntegerType>
-inline unsigned lengthOfNumberAsStringSigned(SignedIntegerType number)
+template<typename IntegerType>
+inline unsigned lengthOfIntegerAsString(IntegerType integer)
 {
-    if (number < 0)
-        return lengthOfNumberAsStringImpl<typename std::make_unsigned<SignedIntegerType>::type, NegativeNumber>(-number);
-    return lengthOfNumberAsStringImpl<typename std::make_unsigned<SignedIntegerType>::type, PositiveNumber>(number);
+    static_assert(std::is_integral_v<IntegerType>);
+    if constexpr (std::is_same_v<IntegerType, bool>)
+        return 1;
+    else if constexpr (std::is_signed_v<IntegerType>) {
+        if (integer < 0)
+            return lengthOfIntegerAsStringImpl<typename std::make_unsigned_t<IntegerType>, NegativeNumber>(-integer);
+        return lengthOfIntegerAsStringImpl<typename std::make_unsigned_t<IntegerType>, PositiveNumber>(integer);
+    } else
+        return lengthOfIntegerAsStringImpl<IntegerType, PositiveNumber>(integer);
 }
 
-template<typename UnsignedIntegerType>
-inline unsigned lengthOfNumberAsStringUnsigned(UnsignedIntegerType number)
-{
-    return lengthOfNumberAsStringImpl<UnsignedIntegerType, PositiveNumber>(number);
-}
-
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/text/StringConcatenateNumbers.h (265343 => 265344)


--- trunk/Source/WTF/wtf/text/StringConcatenateNumbers.h	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WTF/wtf/text/StringConcatenateNumbers.h	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,36 +31,39 @@
 
 namespace WTF {
 
-template<typename SignedInt>
-class StringTypeAdapter<SignedInt, typename std::enable_if_t<std::is_integral<SignedInt>::value && std::is_signed<SignedInt>::value>> {
+template<typename Integer>
+class StringTypeAdapter<Integer, typename std::enable_if_t<std::is_integral_v<Integer>>> {
 public:
-    StringTypeAdapter(SignedInt number)
+    StringTypeAdapter(Integer number)
         : m_number { number }
     {
     }
 
-    unsigned length() const { return lengthOfNumberAsStringSigned(m_number); }
+    unsigned length() const { return lengthOfIntegerAsString(m_number); }
     bool is8Bit() const { return true; }
-    template<typename CharacterType> void writeTo(CharacterType* destination) const { writeNumberToBufferSigned(m_number, destination); }
+    template<typename CharacterType>
+    void writeTo(CharacterType* destination) const { writeIntegerToBuffer(m_number, destination); }
 
 private:
-    SignedInt m_number;
+    Integer m_number;
 };
 
-template<typename UnsignedInt>
-class StringTypeAdapter<UnsignedInt, typename std::enable_if_t<std::is_integral<UnsignedInt>::value && !std::is_signed<UnsignedInt>::value>> {
+template<typename Enum>
+class StringTypeAdapter<Enum, typename std::enable_if_t<std::is_enum_v<Enum>>> {
+using UnderlyingType = typename std::underlying_type_t<Enum>;
 public:
-    StringTypeAdapter(UnsignedInt number)
-        : m_number { number }
+    StringTypeAdapter(Enum enumValue)
+        : m_enum { enumValue }
     {
     }
 
-    unsigned length() const { return lengthOfNumberAsStringUnsigned(m_number); }
+    unsigned length() const { return lengthOfIntegerAsString(static_cast<UnderlyingType>(m_enum)); }
     bool is8Bit() const { return true; }
-    template<typename CharacterType> void writeTo(CharacterType* destination) const { writeNumberToBufferUnsigned(m_number, destination); }
+    template<typename CharacterType>
+    void writeTo(CharacterType* destination) const { writeIntegerToBuffer(static_cast<UnderlyingType>(m_enum), destination); }
 
 private:
-    UnsignedInt m_number;
+    Enum m_enum;
 };
 
 template<typename FloatingPoint>

Modified: trunk/Source/WebCore/ChangeLog (265343 => 265344)


--- trunk/Source/WebCore/ChangeLog	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WebCore/ChangeLog	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,3 +1,15 @@
+2020-08-06  David Kilzer  <ddkil...@apple.com>
+
+        WTF::makeString() should handle enum values
+        <https://webkit.org/b/214906>
+
+        Reviewed by Sam Weinig.
+
+        * Modules/webgpu/WHLSL/Metal/WHLSLMangledNames.h:
+        (WTF::MangledNameAdaptor::length):
+        (WTF::MangledNameAdaptor::writeTo):
+        - Update for function renames.
+
 2020-08-06  Chris Dumez  <cdu...@apple.com>
 
         MediaStreamAudioSourceNode should have a constructor

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMangledNames.h (265343 => 265344)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMangledNames.h	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMangledNames.h	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -83,12 +83,12 @@
     {
     }
 
-    unsigned length() { return strlen(MangledNameType::prefix) + lengthOfNumberAsStringUnsigned(m_name.value); }
+    unsigned length() { return strlen(MangledNameType::prefix) + lengthOfIntegerAsString(m_name.value); }
     bool is8Bit() { return true; }
     template<typename CharacterType> void writeTo(CharacterType* destination)
     {
         StringImpl::copyCharacters(destination, reinterpret_cast<const LChar*>(MangledNameType::prefix), strlen(MangledNameType::prefix));
-        writeNumberToBufferUnsigned(m_name.value, destination + strlen(MangledNameType::prefix));
+        writeIntegerToBuffer(m_name.value, destination + strlen(MangledNameType::prefix));
     }
 
 private:
@@ -142,7 +142,7 @@
     {
         return WTF::switchOn(m_name,
             [&] (const WebCore::WHLSL::Metal::MangledTypeName& mangledTypeName) {
-                return strlen(WebCore::WHLSL::Metal::MangledTypeName::prefix) + lengthOfNumberAsStringUnsigned(mangledTypeName.value);
+                return strlen(WebCore::WHLSL::Metal::MangledTypeName::prefix) + lengthOfIntegerAsString(mangledTypeName.value);
             },
             [&] (const String& string) {
                 return string.length();
@@ -167,7 +167,7 @@
         WTF::switchOn(m_name,
             [&] (const WebCore::WHLSL::Metal::MangledTypeName& mangledTypeName) {
                 StringImpl::copyCharacters(destination, reinterpret_cast<const LChar*>(WebCore::WHLSL::Metal::MangledTypeName::prefix), strlen(WebCore::WHLSL::Metal::MangledTypeName::prefix));
-                writeNumberToBufferUnsigned(mangledTypeName.value, destination + strlen(WebCore::WHLSL::Metal::MangledTypeName::prefix));
+                writeIntegerToBuffer(mangledTypeName.value, destination + strlen(WebCore::WHLSL::Metal::MangledTypeName::prefix));
             },
             [&] (const String& string) {
                 StringView { string }.getCharactersWithUpconvert(destination);

Modified: trunk/Source/WebKit/ChangeLog (265343 => 265344)


--- trunk/Source/WebKit/ChangeLog	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WebKit/ChangeLog	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,3 +1,16 @@
+2020-08-06  David Kilzer  <ddkil...@apple.com>
+
+        WTF::makeString() should handle enum values
+        <https://webkit.org/b/214906>
+
+        Reviewed by Sam Weinig.
+
+        * Platform/IPC/cocoa/ConnectionCocoa.mm:
+        (IPC::Connection::sendMessage):
+        * Shared/Cocoa/AuxiliaryProcessCocoa.mm:
+        (WebKit::AuxiliaryProcess::didReceiveInvalidMessage):
+        - Update to take advantage of enum support in WTF::makeString().
+
 2020-08-06  Jer Noble  <jer.no...@apple.com>
 
         [Mac,WK2] REGRESSION(r262322): ScreenTime overlay is hidden in fullscreen mode

Modified: trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm (265343 => 265344)


--- trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2020-08-06 20:09:15 UTC (rev 265344)
@@ -275,10 +275,9 @@
 
     default:
         auto messageName = message->messageName();
-        auto messageNameValue = static_cast<std::underlying_type_t<IPC::MessageName>>(messageName);
-        auto errorMessage = makeString("Unhandled error code 0x", hex(kr), ", message '", description(messageName), "' (", messageNameValue, ')');
+        auto errorMessage = makeString("Unhandled error code 0x", hex(kr), ", message '", description(messageName), "' (", messageName, ')');
         WebKit::logAndSetCrashLogMessage(errorMessage.utf8().data());
-        CRASH_WITH_INFO(kr, messageNameValue);
+        CRASH_WITH_INFO(kr, WTF::enumToUnderlyingType(messageName));
     }
 }
 

Modified: trunk/Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm (265343 => 265344)


--- trunk/Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm	2020-08-06 20:09:15 UTC (rev 265344)
@@ -34,10 +34,9 @@
 
 void AuxiliaryProcess::didReceiveInvalidMessage(IPC::Connection&, IPC::MessageName messageName)
 {
-    auto messageNameValue = static_cast<std::underlying_type_t<IPC::MessageName>>(messageName);
-    auto errorMessage = makeString("Received invalid message: '", description(messageName), "' (", messageNameValue, ')');
+    auto errorMessage = makeString("Received invalid message: '", description(messageName), "' (", messageName, ')');
     logAndSetCrashLogMessage(errorMessage.utf8().data());
-    CRASH_WITH_INFO(messageNameValue);
+    CRASH_WITH_INFO(WTF::enumToUnderlyingType(messageName));
 }
 
 bool AuxiliaryProcess::parentProcessHasEntitlement(const char* entitlement)

Modified: trunk/Tools/ChangeLog (265343 => 265344)


--- trunk/Tools/ChangeLog	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Tools/ChangeLog	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,5 +1,17 @@
 2020-08-06  David Kilzer  <ddkil...@apple.com>
 
+        WTF::makeString() should handle enum values
+        <https://webkit.org/b/214906>
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WTF/StringConcatenate.cpp:
+        (TestWebKitAPI::TEST):
+        - Update tests for renamed functions.
+        - Add test for enum values.
+
+2020-08-06  David Kilzer  <ddkil...@apple.com>
+
         check-webkit-style: better algorithm to check for acronym capitalization in an identifier
         <https://webkit.org/b/215026>
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringConcatenate.cpp (265343 => 265344)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringConcatenate.cpp	2020-08-06 20:06:18 UTC (rev 265343)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringConcatenate.cpp	2020-08-06 20:09:15 UTC (rev 265344)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,6 +35,23 @@
 
 namespace TestWebKitAPI {
 
+enum class BoolEnum : bool {
+    A,
+    B
+};
+
+enum class SignedEnum : int8_t {
+    A = -1,
+    B = 0,
+    C = 1
+};
+
+enum class UnsignedEnum : uint8_t {
+    A,
+    B,
+    C
+};
+
 static int arr[2];
 struct S {
     char c;
@@ -48,7 +65,7 @@
 
 TEST(WTF, StringConcatenate_Int)
 {
-    EXPECT_EQ(5u, WTF::lengthOfNumberAsStringSigned(17890));
+    EXPECT_EQ(5u, WTF::lengthOfIntegerAsString(17890));
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890 , " world").utf8().data());
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890l , " world").utf8().data());
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890ll , " world").utf8().data());
@@ -55,7 +72,7 @@
     EXPECT_STREQ("hello 17890 world", makeString("hello ", static_cast<int64_t>(17890) , " world").utf8().data());
     EXPECT_STREQ("hello 17890 world", makeString("hello ", static_cast<int64_t>(17890) , " world").utf8().data());
 
-    EXPECT_EQ(6u, WTF::lengthOfNumberAsStringSigned(-17890));
+    EXPECT_EQ(6u, WTF::lengthOfIntegerAsString(-17890));
     EXPECT_STREQ("hello -17890 world", makeString("hello ", -17890 , " world").utf8().data());
     EXPECT_STREQ("hello -17890 world", makeString("hello ", -17890l , " world").utf8().data());
     EXPECT_STREQ("hello -17890 world", makeString("hello ", -17890ll , " world").utf8().data());
@@ -62,7 +79,7 @@
     EXPECT_STREQ("hello -17890 world", makeString("hello ", static_cast<int64_t>(-17890) , " world").utf8().data());
     EXPECT_STREQ("hello -17890 world", makeString("hello ", static_cast<int64_t>(-17890) , " world").utf8().data());
 
-    EXPECT_EQ(1u, WTF::lengthOfNumberAsStringSigned(0));
+    EXPECT_EQ(1u, WTF::lengthOfIntegerAsString(0));
     EXPECT_STREQ("hello 0 world", makeString("hello ", 0 , " world").utf8().data());
 
     EXPECT_STREQ("hello 42 world", makeString("hello ", static_cast<signed char>(42) , " world").utf8().data());
@@ -72,7 +89,7 @@
 
 TEST(WTF, StringConcatenate_Unsigned)
 {
-    EXPECT_EQ(5u, WTF::lengthOfNumberAsStringUnsigned(17890u));
+    EXPECT_EQ(5u, WTF::lengthOfIntegerAsString(17890u));
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890u , " world").utf8().data());
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890ul , " world").utf8().data());
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890ull , " world").utf8().data());
@@ -79,7 +96,7 @@
     EXPECT_STREQ("hello 17890 world", makeString("hello ", static_cast<uint64_t>(17890) , " world").utf8().data());
     EXPECT_STREQ("hello 17890 world", makeString("hello ", static_cast<uint64_t>(17890) , " world").utf8().data());
 
-    EXPECT_EQ(1u, WTF::lengthOfNumberAsStringSigned(0u));
+    EXPECT_EQ(1u, WTF::lengthOfIntegerAsString(0u));
     EXPECT_STREQ("hello 0 world", makeString("hello ", 0u , " world").utf8().data());
 
     EXPECT_STREQ("hello 42 world", makeString("hello ", static_cast<unsigned char>(42) , " world").utf8().data());
@@ -89,6 +106,20 @@
     EXPECT_STREQ("hello 3235839742 world", makeString("hello ", static_cast<size_t>(0xc0defefe), " world").utf8().data());
 }
 
+TEST(WTF, StringConcatenate_Enum)
+{
+    EXPECT_STREQ("0", makeString(BoolEnum::A).utf8().data());
+    EXPECT_STREQ("1", makeString(BoolEnum::B).utf8().data());
+
+    EXPECT_STREQ("-1", makeString(SignedEnum::A).utf8().data());
+    EXPECT_STREQ("0", makeString(SignedEnum::B).utf8().data());
+    EXPECT_STREQ("1", makeString(SignedEnum::C).utf8().data());
+
+    EXPECT_STREQ("0", makeString(UnsignedEnum::A).utf8().data());
+    EXPECT_STREQ("1", makeString(UnsignedEnum::B).utf8().data());
+    EXPECT_STREQ("2", makeString(UnsignedEnum::C).utf8().data());
+}
+
 TEST(WTF, StringConcatenate_Float)
 {
     EXPECT_STREQ("hello 17890 world", makeString("hello ", 17890.0f , " world").utf8().data());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to