1 //===---------- llvm/unittest/Support/DJBTest.cpp -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/DJB.h"
10 #include "llvm/ADT/Twine.h"
11 #include "gtest/gtest.h"
15 TEST(DJBTest
, caseFolding
) {
21 static constexpr TestCase Tests
[] = {
24 {{"qqqqqqqqqqqqqqqqqqqq"}, {"QQQQQQQQQQQQQQQQQQQQ"}},
27 // Latin Small Letter Dotless I
28 {{u8
"\u0130"}, {"i"}},
29 // Latin Capital Letter I With Dot Above
30 {{u8
"\u0131"}, {"i"}},
32 // Latin Capital Letter A With Grave
33 {{u8
"\u00c0"}, {u8
"\u00e0"}},
34 // Latin Capital Letter A With Macron
35 {{u8
"\u0100"}, {u8
"\u0101"}},
36 // Latin Capital Letter L With Acute
37 {{u8
"\u0139"}, {u8
"\u013a"}},
38 // Cyrillic Capital Letter Ie
39 {{u8
"\u0415"}, {u8
"\u0435"}},
40 // Latin Capital Letter A With Circumflex And Grave
41 {{u8
"\u1ea6"}, {u8
"\u1ea7"}},
43 {{u8
"\u212a"}, {u8
"\u006b"}},
44 // Glagolitic Capital Letter Chrivi
45 {{u8
"\u2c1d"}, {u8
"\u2c4d"}},
46 // Fullwidth Latin Capital Letter M
47 {{u8
"\uff2d"}, {u8
"\uff4d"}},
48 // Old Hungarian Capital Letter Ej
49 {{u8
"\U00010c92"}, {u8
"\U00010cd2"}},
52 for (const TestCase
&T
: Tests
) {
53 SCOPED_TRACE("Comparing '" + T
.One
+ "' and '" + T
.Two
+ "'");
54 EXPECT_EQ(caseFoldingDjbHash(T
.One
), caseFoldingDjbHash(T
.Two
));
58 TEST(DJBTest
, knownValuesLowerCase
) {
63 static constexpr TestCase Tests
[] = {
67 {{"foo"}, 193491849u},
68 {{"foob"}, 2090263819u},
69 {{"fooba"}, 259229388u},
70 {{"foobar"}, 4259602622u},
71 {{"pneumonoultramicroscopicsilicovolcanoconiosis"}, 3999417781u},
74 for (const TestCase
&T
: Tests
) {
75 SCOPED_TRACE("Text: '" + T
.Text
+ "'");
76 EXPECT_EQ(T
.Hash
, djbHash(T
.Text
));
77 EXPECT_EQ(T
.Hash
, caseFoldingDjbHash(T
.Text
));
78 EXPECT_EQ(T
.Hash
, caseFoldingDjbHash(T
.Text
.upper()));
82 TEST(DJBTest
, knownValuesUnicode
) {
83 EXPECT_EQ(5866553u, djbHash(u8
"\u0130"));
84 EXPECT_EQ(177678u, caseFoldingDjbHash(u8
"\u0130"));
88 u8
"\u0130\u0131\u00c0\u00e0\u0100\u0101\u0139\u013a\u0415\u0435\u1ea6"
89 u8
"\u1ea7\u212a\u006b\u2c1d\u2c4d\uff2d\uff4d\U00010c92\U00010cd2"));
93 u8
"\u0130\u0131\u00c0\u00e0\u0100\u0101\u0139\u013a\u0415\u0435\u1ea6"
94 u8
"\u1ea7\u212a\u006b\u2c1d\u2c4d\uff2d\uff4d\U00010c92\U00010cd2"));