================ @@ -0,0 +1,354 @@ +//===- unittest/Format/NumericLiteralCaseTest.cpp -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FormatTestBase.h" + +#define DEBUG_TYPE "numeric-literal-case-test" + +namespace clang { +namespace format { +namespace test { +namespace { + +class NumericLiteralCaseTest : public FormatTestBase {}; + +TEST_F(NumericLiteralCaseTest, Prefix) { + FormatStyle Style = getLLVMStyle(); + EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp); + EXPECT_EQ(Style.NumericLiteralCase.Prefix, FormatStyle::NLCS_Leave); + EXPECT_EQ(Style.NumericLiteralCase.HexDigit, FormatStyle::NLCS_Leave); + EXPECT_EQ(Style.NumericLiteralCase.ExponentLetter, FormatStyle::NLCS_Leave); + EXPECT_EQ(Style.NumericLiteralCase.Suffix, FormatStyle::NLCS_Leave); + + constexpr StringRef Bin0{"b = 0b0'10'010uL;"}; + constexpr StringRef Bin1{"b = 0B010'010Ul;"}; + constexpr StringRef Hex0{"b = 0xdead'BEEFuL;"}; + constexpr StringRef Hex1{"b = 0Xdead'BEEFUl;"}; + verifyFormat(Bin0, Style); + verifyFormat(Bin1, Style); + verifyFormat(Hex0, Style); + verifyFormat(Hex1, Style); + + Style.NumericLiteralCase.Prefix = FormatStyle::NLCS_Upper; + verifyFormat("b = 0B0'10'010uL;", Bin0, Style); + verifyFormat(Bin1, Style); + verifyFormat("b = 0Xdead'BEEFuL;", Hex0, Style); + verifyFormat(Hex1, Style); + verifyFormat("i = 0XaBcD.a0Ebp123F;", Style); + verifyFormat("j = 0XaBcD.a0EbP123f;", Style); + + Style.NumericLiteralCase.Prefix = FormatStyle::NLCS_Lower; + verifyFormat(Bin0, Style); + verifyFormat("b = 0b010'010Ul;", Bin1, Style); + verifyFormat(Hex0, Style); + verifyFormat("b = 0xdead'BEEFUl;", Hex1, Style); +} + +TEST_F(NumericLiteralCaseTest, HexDigit) { + FormatStyle Style = getLLVMStyle(); + + constexpr StringRef A{"a = 0xaBc0'123fuL;"}; + constexpr StringRef B{"b = 0XaBc0'123FUl;"}; + constexpr StringRef C{"c = 0xa'Bc.0p12'3f32;"}; + constexpr StringRef D{"d = 0xa'Bc.0P12'3F128;"}; + constexpr StringRef E{"e = 0b0011'00Ull;"}; + constexpr StringRef F{"f = 0B0100'000zu;"}; + constexpr StringRef G{"g = 0.123e-19f;"}; + constexpr StringRef H{"h = 0.12'3E-19F16;"}; + constexpr StringRef I{"i = 0x.0000aBcp12'3F128;"}; + constexpr StringRef J{"j = 0xaa1'fP12'3F128;"}; + constexpr StringRef K{"k = 0x0;"}; + constexpr StringRef L{"l = 0xA;"}; + + verifyFormat(A, Style); + verifyFormat(B, Style); + verifyFormat(C, Style); + verifyFormat(D, Style); + verifyFormat(E, Style); + verifyFormat(F, Style); + verifyFormat(G, Style); + verifyFormat(H, Style); + verifyFormat(I, Style); + verifyFormat(J, Style); ---------------- owenca wrote:
Ditto. https://github.com/llvm/llvm-project/pull/151590 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits