| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Golen ratio. | 109 // Golen ratio. |
| 110 const double phi = 1.6180339887498948482; | 110 const double phi = 1.6180339887498948482; |
| 111 testNumberToStringECMAScript(phi, "1.618033988749895"); | 111 testNumberToStringECMAScript(phi, "1.618033988749895"); |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST(StringTest, ReplaceWithLiteral) | 114 TEST(StringTest, ReplaceWithLiteral) |
| 115 { | 115 { |
| 116 // Cases for 8Bit source. | 116 // Cases for 8Bit source. |
| 117 String testString = "1224"; | 117 String testString = "1224"; |
| 118 EXPECT_TRUE(testString.is8Bit()); | 118 EXPECT_TRUE(testString.is8Bit()); |
| 119 testString.replaceWithLiteral('2', ""); | 119 testString.replace('2', ""); |
| 120 EXPECT_STREQ("14", testString.utf8().data()); | 120 EXPECT_STREQ("14", testString.utf8().data()); |
| 121 | 121 |
| 122 testString = "1224"; | 122 testString = "1224"; |
| 123 EXPECT_TRUE(testString.is8Bit()); | 123 EXPECT_TRUE(testString.is8Bit()); |
| 124 testString.replaceWithLiteral('2', "3"); | 124 testString.replace('2', "3"); |
| 125 EXPECT_STREQ("1334", testString.utf8().data()); | 125 EXPECT_STREQ("1334", testString.utf8().data()); |
| 126 | 126 |
| 127 testString = "1224"; | 127 testString = "1224"; |
| 128 EXPECT_TRUE(testString.is8Bit()); | 128 EXPECT_TRUE(testString.is8Bit()); |
| 129 testString.replaceWithLiteral('2', "555"); | 129 testString.replace('2', "555"); |
| 130 EXPECT_STREQ("15555554", testString.utf8().data()); | 130 EXPECT_STREQ("15555554", testString.utf8().data()); |
| 131 | 131 |
| 132 testString = "1224"; | 132 testString = "1224"; |
| 133 EXPECT_TRUE(testString.is8Bit()); | 133 EXPECT_TRUE(testString.is8Bit()); |
| 134 testString.replaceWithLiteral('3', "NotFound"); | 134 testString.replace('3', "NotFound"); |
| 135 EXPECT_STREQ("1224", testString.utf8().data()); | 135 EXPECT_STREQ("1224", testString.utf8().data()); |
| 136 | 136 |
| 137 // Cases for 16Bit source. | 137 // Cases for 16Bit source. |
| 138 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent. | 138 // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent. |
| 139 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); | 139 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); |
| 140 EXPECT_FALSE(testString.is8Bit()); | 140 EXPECT_FALSE(testString.is8Bit()); |
| 141 testString.replaceWithLiteral(UChar(0x00E9), "e"); | 141 testString.replace(UChar(0x00E9), "e"); |
| 142 EXPECT_STREQ("resume", testString.utf8().data()); | 142 EXPECT_STREQ("resume", testString.utf8().data()); |
| 143 | 143 |
| 144 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); | 144 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); |
| 145 EXPECT_FALSE(testString.is8Bit()); | 145 EXPECT_FALSE(testString.is8Bit()); |
| 146 testString.replaceWithLiteral(UChar(0x00E9), ""); | 146 testString.replace(UChar(0x00E9), ""); |
| 147 EXPECT_STREQ("rsum", testString.utf8().data()); | 147 EXPECT_STREQ("rsum", testString.utf8().data()); |
| 148 | 148 |
| 149 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); | 149 testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9"); |
| 150 EXPECT_FALSE(testString.is8Bit()); | 150 EXPECT_FALSE(testString.is8Bit()); |
| 151 testString.replaceWithLiteral('3', "NotFound"); | 151 testString.replace('3', "NotFound"); |
| 152 EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data()); | 152 EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST(StringTest, ComparisonOfSameStringVectors) | 155 TEST(StringTest, ComparisonOfSameStringVectors) |
| 156 { | 156 { |
| 157 Vector<String> stringVector; | 157 Vector<String> stringVector; |
| 158 stringVector.append("one"); | 158 stringVector.append("one"); |
| 159 stringVector.append("two"); | 159 stringVector.append("two"); |
| 160 | 160 |
| 161 Vector<String> sameStringVector; | 161 Vector<String> sameStringVector; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 EXPECT_EQ(CString("\"\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001
F\""), toCStringThroughPrinter(String("\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F", 8))); | 420 EXPECT_EQ(CString("\"\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001
F\""), toCStringThroughPrinter(String("\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F", 8))); |
| 421 EXPECT_EQ(CString("\"\\u007F\\u0080\\u0081\""), toCStringThroughPrinter("\x7
F\x80\x81")); | 421 EXPECT_EQ(CString("\"\\u007F\\u0080\\u0081\""), toCStringThroughPrinter("\x7
F\x80\x81")); |
| 422 EXPECT_EQ(CString("\"\""), toCStringThroughPrinter(emptyString())); | 422 EXPECT_EQ(CString("\"\""), toCStringThroughPrinter(emptyString())); |
| 423 EXPECT_EQ(CString("<null>"), toCStringThroughPrinter(String())); | 423 EXPECT_EQ(CString("<null>"), toCStringThroughPrinter(String())); |
| 424 | 424 |
| 425 static const UChar unicodeSample[] = { 0x30C6, 0x30B9, 0x30C8 }; // "Test" i
n Japanese. | 425 static const UChar unicodeSample[] = { 0x30C6, 0x30B9, 0x30C8 }; // "Test" i
n Japanese. |
| 426 EXPECT_EQ(CString("\"\\u30C6\\u30B9\\u30C8\""), toCStringThroughPrinter(Stri
ng(unicodeSample, WTF_ARRAY_LENGTH(unicodeSample)))); | 426 EXPECT_EQ(CString("\"\\u30C6\\u30B9\\u30C8\""), toCStringThroughPrinter(Stri
ng(unicodeSample, WTF_ARRAY_LENGTH(unicodeSample)))); |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace WTF | 429 } // namespace WTF |
| OLD | NEW |