| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 // append() has special code paths for String backed StringView instead of | 107 // append() has special code paths for String backed StringView instead of |
| 108 // just char* backed ones. | 108 // just char* backed ones. |
| 109 StringBuilder builder6; | 109 StringBuilder builder6; |
| 110 builder6.append(String("ghi"), 1, 2); | 110 builder6.append(String("ghi"), 1, 2); |
| 111 expectBuilderContent("hi", builder6); | 111 expectBuilderContent("hi", builder6); |
| 112 | 112 |
| 113 // Test appending UChar32 characters to StringBuilder. | 113 // Test appending UChar32 characters to StringBuilder. |
| 114 StringBuilder builderForUChar32Append; | 114 StringBuilder builderForUChar32Append; |
| 115 UChar32 frakturAChar = 0x1D504; | 115 UChar32 frakturAChar = 0x1D504; |
| 116 builderForUChar32Append.append( | 116 // The fraktur A is not in the BMP, so it's two UTF-16 code units long. |
| 117 frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 cod
e units long. | 117 builderForUChar32Append.append(frakturAChar); |
| 118 EXPECT_FALSE(builderForUChar32Append.is8Bit()); | 118 EXPECT_FALSE(builderForUChar32Append.is8Bit()); |
| 119 EXPECT_EQ(2U, builderForUChar32Append.length()); | 119 EXPECT_EQ(2U, builderForUChar32Append.length()); |
| 120 builderForUChar32Append.append(static_cast<UChar32>('A')); | 120 builderForUChar32Append.append(static_cast<UChar32>('A')); |
| 121 EXPECT_EQ(3U, builderForUChar32Append.length()); | 121 EXPECT_EQ(3U, builderForUChar32Append.length()); |
| 122 const UChar resultArray[] = {U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), | 122 const UChar resultArray[] = {U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), |
| 123 'A'}; | 123 'A'}; |
| 124 expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), | 124 expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), |
| 125 builderForUChar32Append); | 125 builderForUChar32Append); |
| 126 } | 126 } |
| 127 | 127 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 EXPECT_EQ(string.impl(), builder2.toAtomicString().impl()); | 138 EXPECT_EQ(string.impl(), builder2.toAtomicString().impl()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST(StringBuilderTest, ToString) { | 141 TEST(StringBuilderTest, ToString) { |
| 142 StringBuilder builder; | 142 StringBuilder builder; |
| 143 builder.append("0123456789"); | 143 builder.append("0123456789"); |
| 144 String string = builder.toString(); | 144 String string = builder.toString(); |
| 145 EXPECT_EQ(String("0123456789"), string); | 145 EXPECT_EQ(String("0123456789"), string); |
| 146 EXPECT_EQ(string.impl(), builder.toString().impl()); | 146 EXPECT_EQ(string.impl(), builder.toString().impl()); |
| 147 | 147 |
| 148 // Changing the StringBuilder should not affect the original result of toStrin
g(). | 148 // Changing the StringBuilder should not affect the original result of |
| 149 // toString(). |
| 149 builder.append("abcdefghijklmnopqrstuvwxyz"); | 150 builder.append("abcdefghijklmnopqrstuvwxyz"); |
| 150 EXPECT_EQ(String("0123456789"), string); | 151 EXPECT_EQ(String("0123456789"), string); |
| 151 | 152 |
| 152 // Changing the StringBuilder should not affect the original result of toStrin
g() in case the capacity is not changed. | 153 // Changing the StringBuilder should not affect the original result of |
| 154 // toString() in case the capacity is not changed. |
| 153 builder.reserveCapacity(200); | 155 builder.reserveCapacity(200); |
| 154 string = builder.toString(); | 156 string = builder.toString(); |
| 155 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string); | 157 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string); |
| 156 builder.append("ABC"); | 158 builder.append("ABC"); |
| 157 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string); | 159 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string); |
| 158 | 160 |
| 159 // Changing the original result of toString() should not affect the content of
the StringBuilder. | 161 // Changing the original result of toString() should not affect the content of |
| 162 // the StringBuilder. |
| 160 String string1 = builder.toString(); | 163 String string1 = builder.toString(); |
| 161 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1); | 164 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1); |
| 162 string1.append("DEF"); | 165 string1.append("DEF"); |
| 163 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), | 166 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), |
| 164 builder.toString()); | 167 builder.toString()); |
| 165 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1); | 168 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1); |
| 166 | 169 |
| 167 // Resizing the StringBuilder should not affect the original result of toStrin
g(). | 170 // Resizing the StringBuilder should not affect the original result of |
| 171 // toString(). |
| 168 string1 = builder.toString(); | 172 string1 = builder.toString(); |
| 169 builder.resize(10); | 173 builder.resize(10); |
| 170 builder.append("###"); | 174 builder.append("###"); |
| 171 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1); | 175 EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1); |
| 172 } | 176 } |
| 173 | 177 |
| 174 TEST(StringBuilderTest, Clear) { | 178 TEST(StringBuilderTest, Clear) { |
| 175 StringBuilder builder; | 179 StringBuilder builder; |
| 176 builder.append("0123456789"); | 180 builder.append("0123456789"); |
| 177 builder.clear(); | 181 builder.clear(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 StringBuilder reference; | 332 StringBuilder reference; |
| 329 reference.append(replacementCharacter); // Make it UTF-16. | 333 reference.append(replacementCharacter); // Make it UTF-16. |
| 330 reference.append(String::number(someNumber)); | 334 reference.append(String::number(someNumber)); |
| 331 StringBuilder test; | 335 StringBuilder test; |
| 332 test.append(replacementCharacter); | 336 test.append(replacementCharacter); |
| 333 test.appendNumber(someNumber); | 337 test.appendNumber(someNumber); |
| 334 EXPECT_EQ(reference, test); | 338 EXPECT_EQ(reference, test); |
| 335 } | 339 } |
| 336 | 340 |
| 337 } // namespace WTF | 341 } // namespace WTF |
| OLD | NEW |