| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 Yandex LLC. All rights reserved. | 2 * Copyright (c) 2013 Yandex LLC. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/text/UnicodeUtilities.h" | 32 #include "platform/text/UnicodeUtilities.h" |
| 33 | 33 |
| 34 #include "wtf/Vector.h" | 34 #include "wtf/Vector.h" |
| 35 #include "wtf/text/WTFString.h" | 35 #include "wtf/text/WTFString.h" |
| 36 #include "wtf/unicode/CharacterNames.h" | 36 #include "wtf/unicode/CharacterNames.h" |
| 37 #include <gtest/gtest.h> | 37 #include <gtest/gtest.h> |
| 38 #include <unicode/uchar.h> | 38 #include <unicode/uchar.h> |
| 39 | 39 |
| 40 using namespace blink; | 40 namespace blink { |
| 41 | |
| 42 namespace { | |
| 43 | 41 |
| 44 static const UChar32 kMaxLatinCharCount = 256; | 42 static const UChar32 kMaxLatinCharCount = 256; |
| 45 | 43 |
| 46 static bool isTestFirstAndLastCharsInCategoryFailed = false; | 44 static bool isTestFirstAndLastCharsInCategoryFailed = false; |
| 47 UBool U_CALLCONV testFirstAndLastCharsInCategory(const void *context, UChar32 st
art, UChar32 limit, UCharCategory type) | 45 UBool U_CALLCONV testFirstAndLastCharsInCategory(const void *context, UChar32 st
art, UChar32 limit, UCharCategory type) |
| 48 { | 46 { |
| 49 if (start >= kMaxLatinCharCount | 47 if (start >= kMaxLatinCharCount |
| 50 && U_MASK(type) & (U_GC_S_MASK | U_GC_P_MASK | U_GC_Z_MASK | U_GC_CF_MAS
K) | 48 && U_MASK(type) & (U_GC_S_MASK | U_GC_P_MASK | U_GC_Z_MASK | U_GC_CF_MAS
K) |
| 51 && (!isSeparator(start) || !isSeparator(limit - 1))) { | 49 && (!isSeparator(start) || !isSeparator(limit - 1))) { |
| 52 isTestFirstAndLastCharsInCategoryFailed = true; | 50 isTestFirstAndLastCharsInCategoryFailed = true; |
| 53 | 51 |
| 54 // Break enumeration process | 52 // Break enumeration process |
| 55 return 0; | 53 return 0; |
| 56 } | 54 } |
| 57 | 55 |
| 58 return 1; | 56 return 1; |
| 59 } | 57 } |
| 60 | 58 |
| 61 TEST(WebCoreUnicodeUnit, Separators) | 59 TEST(UnicodeUtilitiesTest, Separators) |
| 62 { | 60 { |
| 63 static const bool latinSeparatorTable[kMaxLatinCharCount] = { | 61 static const bool latinSeparatorTable[kMaxLatinCharCount] = { |
| 64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 66 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // space ! " # $ % & ' (
) * + , - . / | 64 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // space ! " # $ % & ' (
) * + , - . / |
| 67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, //
: ; < = > ? | 65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, //
: ; < = > ? |
| 68 1, 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, |
| 78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 79 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 | 77 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 |
| 80 }; | 78 }; |
| 81 | 79 |
| 82 for (UChar32 character = 0; character < kMaxLatinCharCount; ++character) { | 80 for (UChar32 character = 0; character < kMaxLatinCharCount; ++character) { |
| 83 EXPECT_EQ(isSeparator(character), latinSeparatorTable[character]); | 81 EXPECT_EQ(isSeparator(character), latinSeparatorTable[character]); |
| 84 } | 82 } |
| 85 | 83 |
| 86 isTestFirstAndLastCharsInCategoryFailed = false; | 84 isTestFirstAndLastCharsInCategoryFailed = false; |
| 87 u_enumCharTypes(&testFirstAndLastCharsInCategory, 0); | 85 u_enumCharTypes(&testFirstAndLastCharsInCategory, 0); |
| 88 EXPECT_FALSE(isTestFirstAndLastCharsInCategoryFailed); | 86 EXPECT_FALSE(isTestFirstAndLastCharsInCategoryFailed); |
| 89 } | 87 } |
| 90 | 88 |
| 91 TEST(WebCoreUnicodeUnit, KanaLetters) | 89 TEST(UnicodeUtilitiesTest, KanaLetters) |
| 92 { | 90 { |
| 93 // Non Kana symbols | 91 // Non Kana symbols |
| 94 for (UChar character = 0; character < 0x3041; ++character) | 92 for (UChar character = 0; character < 0x3041; ++character) |
| 95 EXPECT_FALSE(isKanaLetter(character)); | 93 EXPECT_FALSE(isKanaLetter(character)); |
| 96 | 94 |
| 97 // Hiragana letters. | 95 // Hiragana letters. |
| 98 for (UChar character = 0x3041; character <= 0x3096; ++character) | 96 for (UChar character = 0x3041; character <= 0x3096; ++character) |
| 99 EXPECT_TRUE(isKanaLetter(character)); | 97 EXPECT_TRUE(isKanaLetter(character)); |
| 100 | 98 |
| 101 // Katakana letters. | 99 // Katakana letters. |
| 102 for (UChar character = 0x30A1; character <= 0x30FA; ++character) | 100 for (UChar character = 0x30A1; character <= 0x30FA; ++character) |
| 103 EXPECT_TRUE(isKanaLetter(character)); | 101 EXPECT_TRUE(isKanaLetter(character)); |
| 104 } | 102 } |
| 105 | 103 |
| 106 TEST(WebCoreUnicodeUnit, ContainsKanaLetters) | 104 TEST(UnicodeUtilitiesTest, ContainsKanaLetters) |
| 107 { | 105 { |
| 108 // Non Kana symbols | 106 // Non Kana symbols |
| 109 String nonKanaString; | 107 String nonKanaString; |
| 110 for (UChar character = 0; character < 0x3041; ++character) | 108 for (UChar character = 0; character < 0x3041; ++character) |
| 111 nonKanaString.append(character); | 109 nonKanaString.append(character); |
| 112 EXPECT_FALSE(containsKanaLetters(nonKanaString)); | 110 EXPECT_FALSE(containsKanaLetters(nonKanaString)); |
| 113 | 111 |
| 114 // Hiragana letters. | 112 // Hiragana letters. |
| 115 for (UChar character = 0x3041; character <= 0x3096; ++character) { | 113 for (UChar character = 0x3041; character <= 0x3096; ++character) { |
| 116 String str(nonKanaString); | 114 String str(nonKanaString); |
| 117 str.append(character); | 115 str.append(character); |
| 118 EXPECT_TRUE(containsKanaLetters(str)); | 116 EXPECT_TRUE(containsKanaLetters(str)); |
| 119 } | 117 } |
| 120 | 118 |
| 121 // Katakana letters. | 119 // Katakana letters. |
| 122 for (UChar character = 0x30A1; character <= 0x30FA; ++character) { | 120 for (UChar character = 0x30A1; character <= 0x30FA; ++character) { |
| 123 String str(nonKanaString); | 121 String str(nonKanaString); |
| 124 str.append(character); | 122 str.append(character); |
| 125 EXPECT_TRUE(containsKanaLetters(str)); | 123 EXPECT_TRUE(containsKanaLetters(str)); |
| 126 } | 124 } |
| 127 } | 125 } |
| 128 | 126 |
| 129 TEST(WebCoreUnicodeUnit, FoldQuoteMarkOrSoftHyphenTest) | 127 TEST(UnicodeUtilitiesTest, FoldQuoteMarkOrSoftHyphenTest) |
| 130 { | 128 { |
| 131 const UChar charactersToFold[] = { | 129 const UChar charactersToFold[] = { |
| 132 hebrewPunctuationGershayimCharacter, leftDoubleQuotationMarkCharacter, r
ightDoubleQuotationMarkCharacter, | 130 hebrewPunctuationGershayimCharacter, leftDoubleQuotationMarkCharacter, r
ightDoubleQuotationMarkCharacter, |
| 133 hebrewPunctuationGereshCharacter, leftSingleQuotationMarkCharacter, righ
tSingleQuotationMarkCharacter, | 131 hebrewPunctuationGereshCharacter, leftSingleQuotationMarkCharacter, righ
tSingleQuotationMarkCharacter, |
| 134 softHyphenCharacter | 132 softHyphenCharacter |
| 135 }; | 133 }; |
| 136 | 134 |
| 137 String stringToFold(charactersToFold, WTF_ARRAY_LENGTH(charactersToFold)); | 135 String stringToFold(charactersToFold, WTF_ARRAY_LENGTH(charactersToFold)); |
| 138 Vector<UChar> buffer; | 136 Vector<UChar> buffer; |
| 139 stringToFold.appendTo(buffer); | 137 stringToFold.appendTo(buffer); |
| 140 | 138 |
| 141 foldQuoteMarksAndSoftHyphens(stringToFold); | 139 foldQuoteMarksAndSoftHyphens(stringToFold); |
| 142 | 140 |
| 143 const String foldedString("\"\"\"\'\'\'\0", WTF_ARRAY_LENGTH(charactersToFol
d)); | 141 const String foldedString("\"\"\"\'\'\'\0", WTF_ARRAY_LENGTH(charactersToFol
d)); |
| 144 EXPECT_EQ(stringToFold, foldedString); | 142 EXPECT_EQ(stringToFold, foldedString); |
| 145 | 143 |
| 146 foldQuoteMarksAndSoftHyphens(buffer.data(), buffer.size()); | 144 foldQuoteMarksAndSoftHyphens(buffer.data(), buffer.size()); |
| 147 EXPECT_EQ(String(buffer), foldedString); | 145 EXPECT_EQ(String(buffer), foldedString); |
| 148 } | 146 } |
| 149 | 147 |
| 150 TEST(WebCoreUnicodeUnit, OnlyKanaLettersEqualityTest) | 148 TEST(UnicodeUtilitiesTest, OnlyKanaLettersEqualityTest) |
| 151 { | 149 { |
| 152 const UChar nonKanaString1[] = { 'a', 'b', 'c', 'd' }; | 150 const UChar nonKanaString1[] = { 'a', 'b', 'c', 'd' }; |
| 153 const UChar nonKanaString2[] = { 'e', 'f', 'g' }; | 151 const UChar nonKanaString2[] = { 'e', 'f', 'g' }; |
| 154 | 152 |
| 155 // Check that non-Kana letters will be skipped. | 153 // Check that non-Kana letters will be skipped. |
| 156 EXPECT_TRUE(checkOnlyKanaLettersInStrings( | 154 EXPECT_TRUE(checkOnlyKanaLettersInStrings( |
| 157 nonKanaString1, WTF_ARRAY_LENGTH(nonKanaString1), | 155 nonKanaString1, WTF_ARRAY_LENGTH(nonKanaString1), |
| 158 nonKanaString2, WTF_ARRAY_LENGTH(nonKanaString2))); | 156 nonKanaString2, WTF_ARRAY_LENGTH(nonKanaString2))); |
| 159 | 157 |
| 160 const UChar kanaString[] = { 'e', 'f', 'g', 0x3041 }; | 158 const UChar kanaString[] = { 'e', 'f', 'g', 0x3041 }; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 EXPECT_TRUE(checkOnlyKanaLettersInStrings( | 178 EXPECT_TRUE(checkOnlyKanaLettersInStrings( |
| 181 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), | 179 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), |
| 182 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); | 180 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); |
| 183 | 181 |
| 184 voicedKanaString2[0] = 0x3043; | 182 voicedKanaString2[0] = 0x3043; |
| 185 EXPECT_FALSE(checkOnlyKanaLettersInStrings( | 183 EXPECT_FALSE(checkOnlyKanaLettersInStrings( |
| 186 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), | 184 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), |
| 187 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); | 185 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); |
| 188 } | 186 } |
| 189 | 187 |
| 190 TEST(WebCoreUnicodeUnit, StringsWithKanaLettersTest) | 188 TEST(UnicodeUtilitiesTest, StringsWithKanaLettersTest) |
| 191 { | 189 { |
| 192 const UChar nonKanaString1[] = { 'a', 'b', 'c' }; | 190 const UChar nonKanaString1[] = { 'a', 'b', 'c' }; |
| 193 const UChar nonKanaString2[] = { 'a', 'b', 'c' }; | 191 const UChar nonKanaString2[] = { 'a', 'b', 'c' }; |
| 194 | 192 |
| 195 // Check that non-Kana letters will be compared. | 193 // Check that non-Kana letters will be compared. |
| 196 EXPECT_TRUE(checkKanaStringsEqual( | 194 EXPECT_TRUE(checkKanaStringsEqual( |
| 197 nonKanaString1, WTF_ARRAY_LENGTH(nonKanaString1), | 195 nonKanaString1, WTF_ARRAY_LENGTH(nonKanaString1), |
| 198 nonKanaString2, WTF_ARRAY_LENGTH(nonKanaString2))); | 196 nonKanaString2, WTF_ARRAY_LENGTH(nonKanaString2))); |
| 199 | 197 |
| 200 const UChar kanaString[] = { 'a', 'b', 'c', 0x3041 }; | 198 const UChar kanaString[] = { 'a', 'b', 'c', 0x3041 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 EXPECT_TRUE(checkKanaStringsEqual( | 236 EXPECT_TRUE(checkKanaStringsEqual( |
| 239 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), | 237 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), |
| 240 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); | 238 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); |
| 241 | 239 |
| 242 voicedKanaString2[0] = 0x3043; | 240 voicedKanaString2[0] = 0x3043; |
| 243 EXPECT_FALSE(checkKanaStringsEqual( | 241 EXPECT_FALSE(checkKanaStringsEqual( |
| 244 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), | 242 voicedKanaString1, WTF_ARRAY_LENGTH(voicedKanaString1), |
| 245 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); | 243 voicedKanaString2, WTF_ARRAY_LENGTH(voicedKanaString2))); |
| 246 } | 244 } |
| 247 | 245 |
| 248 } // namespace | 246 } // namespace blink |
| OLD | NEW |