OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // Finalization of types happens before the fields and functions have been | 56 // Finalization of types happens before the fields and functions have been |
57 // parsed. | 57 // parsed. |
58 ClassFinalizer::FinalizeTypesInClass(cls); | 58 ClassFinalizer::FinalizeTypesInClass(cls); |
59 | 59 |
60 // Create and populate the function arrays. | 60 // Create and populate the function arrays. |
61 const Array& functions = Array::Handle(Array::New(6)); | 61 const Array& functions = Array::Handle(Array::New(6)); |
62 Function& function = Function::Handle(); | 62 Function& function = Function::Handle(); |
63 String& function_name = String::Handle(); | 63 String& function_name = String::Handle(); |
64 function_name = Symbols::New(thread, "foo"); | 64 function_name = Symbols::New(thread, "foo"); |
65 function = Function::New( | 65 function = |
66 function_name, RawFunction::kRegularFunction, | 66 Function::New(function_name, RawFunction::kRegularFunction, false, false, |
67 false, false, false, false, false, cls, TokenPosition::kMinSource); | 67 false, false, false, cls, TokenPosition::kMinSource); |
68 functions.SetAt(0, function); | 68 functions.SetAt(0, function); |
69 function_name = Symbols::New(thread, "bar"); | 69 function_name = Symbols::New(thread, "bar"); |
70 function = Function::New( | 70 function = |
71 function_name, RawFunction::kRegularFunction, | 71 Function::New(function_name, RawFunction::kRegularFunction, false, false, |
72 false, false, false, false, false, cls, TokenPosition::kMinSource); | 72 false, false, false, cls, TokenPosition::kMinSource); |
73 | 73 |
74 const int kNumFixedParameters = 2; | 74 const int kNumFixedParameters = 2; |
75 const int kNumOptionalParameters = 3; | 75 const int kNumOptionalParameters = 3; |
76 const bool kAreOptionalPositional = true; | 76 const bool kAreOptionalPositional = true; |
77 function.set_num_fixed_parameters(kNumFixedParameters); | 77 function.set_num_fixed_parameters(kNumFixedParameters); |
78 function.SetNumOptionalParameters(kNumOptionalParameters, | 78 function.SetNumOptionalParameters(kNumOptionalParameters, |
79 kAreOptionalPositional); | 79 kAreOptionalPositional); |
80 functions.SetAt(1, function); | 80 functions.SetAt(1, function); |
81 | 81 |
82 function_name = Symbols::New(thread, "baz"); | 82 function_name = Symbols::New(thread, "baz"); |
83 function = Function::New( | 83 function = |
84 function_name, RawFunction::kRegularFunction, | 84 Function::New(function_name, RawFunction::kRegularFunction, false, false, |
85 false, false, false, false, false, cls, TokenPosition::kMinSource); | 85 false, false, false, cls, TokenPosition::kMinSource); |
86 functions.SetAt(2, function); | 86 functions.SetAt(2, function); |
87 | 87 |
88 function_name = Symbols::New(thread, "Foo"); | 88 function_name = Symbols::New(thread, "Foo"); |
89 function = Function::New( | 89 function = |
90 function_name, RawFunction::kRegularFunction, | 90 Function::New(function_name, RawFunction::kRegularFunction, true, false, |
91 true, false, false, false, false, cls, TokenPosition::kMinSource); | 91 false, false, false, cls, TokenPosition::kMinSource); |
92 | 92 |
93 functions.SetAt(3, function); | 93 functions.SetAt(3, function); |
94 function_name = Symbols::New(thread, "Bar"); | 94 function_name = Symbols::New(thread, "Bar"); |
95 function = Function::New( | 95 function = |
96 function_name, RawFunction::kRegularFunction, | 96 Function::New(function_name, RawFunction::kRegularFunction, true, false, |
97 true, false, false, false, false, cls, TokenPosition::kMinSource); | 97 false, false, false, cls, TokenPosition::kMinSource); |
98 functions.SetAt(4, function); | 98 functions.SetAt(4, function); |
99 function_name = Symbols::New(thread, "BaZ"); | 99 function_name = Symbols::New(thread, "BaZ"); |
100 function = Function::New( | 100 function = |
101 function_name, RawFunction::kRegularFunction, | 101 Function::New(function_name, RawFunction::kRegularFunction, true, false, |
102 true, false, false, false, false, cls, TokenPosition::kMinSource); | 102 false, false, false, cls, TokenPosition::kMinSource); |
103 functions.SetAt(5, function); | 103 functions.SetAt(5, function); |
104 | 104 |
105 // Setup the functions in the class. | 105 // Setup the functions in the class. |
106 cls.SetFunctions(functions); | 106 cls.SetFunctions(functions); |
107 | 107 |
108 // The class can now be finalized. | 108 // The class can now be finalized. |
109 cls.Finalize(); | 109 cls.Finalize(); |
110 | 110 |
111 function_name = String::New("Foo"); | 111 function_name = String::New("Foo"); |
112 function = cls.LookupDynamicFunction(function_name); | 112 function = cls.LookupDynamicFunction(function_name); |
(...skipping 22 matching lines...) Expand all Loading... |
135 function = cls.LookupDynamicFunction(function_name); | 135 function = cls.LookupDynamicFunction(function_name); |
136 EXPECT(!function.IsNull()); | 136 EXPECT(!function.IsNull()); |
137 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters()); | 137 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters()); |
138 EXPECT_EQ(kNumOptionalParameters, function.NumOptionalParameters()); | 138 EXPECT_EQ(kNumOptionalParameters, function.NumOptionalParameters()); |
139 } | 139 } |
140 | 140 |
141 | 141 |
142 VM_TEST_CASE(TypeArguments) { | 142 VM_TEST_CASE(TypeArguments) { |
143 const Type& type1 = Type::Handle(Type::Double()); | 143 const Type& type1 = Type::Handle(Type::Double()); |
144 const Type& type2 = Type::Handle(Type::StringType()); | 144 const Type& type2 = Type::Handle(Type::StringType()); |
145 const TypeArguments& type_arguments1 = TypeArguments::Handle( | 145 const TypeArguments& type_arguments1 = |
146 TypeArguments::New(2)); | 146 TypeArguments::Handle(TypeArguments::New(2)); |
147 type_arguments1.SetTypeAt(0, type1); | 147 type_arguments1.SetTypeAt(0, type1); |
148 type_arguments1.SetTypeAt(1, type2); | 148 type_arguments1.SetTypeAt(1, type2); |
149 const TypeArguments& type_arguments2 = TypeArguments::Handle( | 149 const TypeArguments& type_arguments2 = |
150 TypeArguments::New(2)); | 150 TypeArguments::Handle(TypeArguments::New(2)); |
151 type_arguments2.SetTypeAt(0, type1); | 151 type_arguments2.SetTypeAt(0, type1); |
152 type_arguments2.SetTypeAt(1, type2); | 152 type_arguments2.SetTypeAt(1, type2); |
153 EXPECT_NE(type_arguments1.raw(), type_arguments2.raw()); | 153 EXPECT_NE(type_arguments1.raw(), type_arguments2.raw()); |
154 OS::Print("1: %s\n", type_arguments1.ToCString()); | 154 OS::Print("1: %s\n", type_arguments1.ToCString()); |
155 OS::Print("2: %s\n", type_arguments2.ToCString()); | 155 OS::Print("2: %s\n", type_arguments2.ToCString()); |
156 EXPECT(type_arguments1.Equals(type_arguments2)); | 156 EXPECT(type_arguments1.Equals(type_arguments2)); |
157 TypeArguments& type_arguments3 = TypeArguments::Handle(); | 157 TypeArguments& type_arguments3 = TypeArguments::Handle(); |
158 type_arguments1.Canonicalize(); | 158 type_arguments1.Canonicalize(); |
159 type_arguments3 ^= type_arguments2.Canonicalize(); | 159 type_arguments3 ^= type_arguments2.Canonicalize(); |
160 EXPECT_EQ(type_arguments1.raw(), type_arguments3.raw()); | 160 EXPECT_EQ(type_arguments1.raw(), type_arguments3.raw()); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 VM_TEST_CASE(TokenStream) { | 164 VM_TEST_CASE(TokenStream) { |
165 Zone* zone = Thread::Current()->zone(); | 165 Zone* zone = Thread::Current()->zone(); |
166 String& source = String::Handle(zone, String::New("= ( 9 , .")); | 166 String& source = String::Handle(zone, String::New("= ( 9 , .")); |
167 String& private_key = String::Handle(zone, String::New("")); | 167 String& private_key = String::Handle(zone, String::New("")); |
168 const TokenStream& token_stream = TokenStream::Handle( | 168 const TokenStream& token_stream = |
169 zone, TokenStream::New(source, private_key, false)); | 169 TokenStream::Handle(zone, TokenStream::New(source, private_key, false)); |
170 TokenStream::Iterator iterator(zone, token_stream, TokenPosition::kMinSource); | 170 TokenStream::Iterator iterator(zone, token_stream, TokenPosition::kMinSource); |
171 iterator.Advance(); // Advance to '(' token. | 171 iterator.Advance(); // Advance to '(' token. |
172 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); | 172 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); |
173 iterator.Advance(); | 173 iterator.Advance(); |
174 iterator.Advance(); | 174 iterator.Advance(); |
175 iterator.Advance(); // Advance to '.' token. | 175 iterator.Advance(); // Advance to '.' token. |
176 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); | 176 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); |
177 iterator.Advance(); // Advance to end of stream. | 177 iterator.Advance(); // Advance to end of stream. |
178 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); | 178 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 VM_TEST_CASE(GenerateExactSource) { | 182 VM_TEST_CASE(GenerateExactSource) { |
183 // Verify the exact formatting of generated sources. | 183 // Verify the exact formatting of generated sources. |
184 const char* kScriptChars = | 184 const char* kScriptChars = |
185 "\n" | 185 "\n" |
186 "class A {\n" | 186 "class A {\n" |
187 " static bar() { return 42; }\n" | 187 " static bar() { return 42; }\n" |
188 " static fly() { return 5; }\n" | 188 " static fly() { return 5; }\n" |
189 " void catcher(x) {\n" | 189 " void catcher(x) {\n" |
190 " try {\n" | 190 " try {\n" |
191 " if (x is! List) {\n" | 191 " if (x is! List) {\n" |
192 " for (int i = 0; i < x; i++) {\n" | 192 " for (int i = 0; i < x; i++) {\n" |
193 " fly();\n" | 193 " fly();\n" |
194 " ++i;\n" | 194 " ++i;\n" |
195 " }\n" | 195 " }\n" |
196 " } else {\n" | 196 " } else {\n" |
197 " for (int i = 0; i < x; i--) {\n" | 197 " for (int i = 0; i < x; i--) {\n" |
198 " !fly();\n" | 198 " !fly();\n" |
199 " --i;\n" | 199 " --i;\n" |
200 " }\n" | 200 " }\n" |
201 " }\n" | 201 " }\n" |
202 " } on Blah catch (a) {\n" | 202 " } on Blah catch (a) {\n" |
203 " _print(17);\n" | 203 " _print(17);\n" |
204 " } catch (e, s) {\n" | 204 " } catch (e, s) {\n" |
205 " bar()\n" | 205 " bar()\n" |
206 " }\n" | 206 " }\n" |
207 " }\n" | 207 " }\n" |
208 "}\n"; | 208 "}\n"; |
209 | 209 |
210 String& url = String::Handle(String::New("dart-test:GenerateExactSource")); | 210 String& url = String::Handle(String::New("dart-test:GenerateExactSource")); |
211 String& source = String::Handle(String::New(kScriptChars)); | 211 String& source = String::Handle(String::New(kScriptChars)); |
212 Script& script = Script::Handle(Script::New(url, | 212 Script& script = |
213 source, | 213 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
214 RawScript::kScriptTag)); | |
215 script.Tokenize(String::Handle(String::New(""))); | 214 script.Tokenize(String::Handle(String::New(""))); |
216 const TokenStream& tokens = TokenStream::Handle(script.tokens()); | 215 const TokenStream& tokens = TokenStream::Handle(script.tokens()); |
217 const String& gen_source = String::Handle(tokens.GenerateSource()); | 216 const String& gen_source = String::Handle(tokens.GenerateSource()); |
218 EXPECT_STREQ(source.ToCString(), gen_source.ToCString()); | 217 EXPECT_STREQ(source.ToCString(), gen_source.ToCString()); |
219 } | 218 } |
220 | 219 |
221 | 220 |
222 TEST_CASE(Class_ComputeEndTokenPos) { | 221 TEST_CASE(Class_ComputeEndTokenPos) { |
223 const char* kScript = | 222 const char* kScript = |
224 "\n" | 223 "\n" |
225 "class A {\n" | 224 "class A {\n" |
226 " /**\n" | 225 " /**\n" |
227 " * Description of foo().\n" | 226 " * Description of foo().\n" |
228 " */\n" | 227 " */\n" |
229 " foo(a) { return '''\"}'''; }\n" | 228 " foo(a) { return '''\"}'''; }\n" |
230 " // }\n" | 229 " // }\n" |
231 " var bar = '\\'}';\n" | 230 " var bar = '\\'}';\n" |
232 " var baz = \"${foo('}')}\";\n" | 231 " var baz = \"${foo('}')}\";\n" |
233 "}\n"; | 232 "}\n"; |
234 Dart_Handle lib_h = TestCase::LoadTestScript(kScript, NULL); | 233 Dart_Handle lib_h = TestCase::LoadTestScript(kScript, NULL); |
235 EXPECT_VALID(lib_h); | 234 EXPECT_VALID(lib_h); |
236 Library& lib = Library::Handle(); | 235 Library& lib = Library::Handle(); |
237 lib ^= Api::UnwrapHandle(lib_h); | 236 lib ^= Api::UnwrapHandle(lib_h); |
238 EXPECT(!lib.IsNull()); | 237 EXPECT(!lib.IsNull()); |
239 const Class& cls = Class::Handle( | 238 const Class& cls = |
240 lib.LookupClass(String::Handle(String::New("A")))); | 239 Class::Handle(lib.LookupClass(String::Handle(String::New("A")))); |
241 EXPECT(!cls.IsNull()); | 240 EXPECT(!cls.IsNull()); |
242 const TokenPosition end_token_pos = cls.ComputeEndTokenPos(); | 241 const TokenPosition end_token_pos = cls.ComputeEndTokenPos(); |
243 const Script& scr = Script::Handle(cls.script()); | 242 const Script& scr = Script::Handle(cls.script()); |
244 intptr_t line; | 243 intptr_t line; |
245 intptr_t col; | 244 intptr_t col; |
246 scr.GetTokenLocation(end_token_pos, &line, &col); | 245 scr.GetTokenLocation(end_token_pos, &line, &col); |
247 EXPECT(line == 10 && col == 1); | 246 EXPECT(line == 10 && col == 1); |
248 } | 247 } |
249 | 248 |
250 | 249 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 EXPECT(!smi_object.IsSmi()); | 305 EXPECT(!smi_object.IsSmi()); |
307 | 306 |
308 EXPECT(smi.Equals(Smi::Handle(Smi::New(5)))); | 307 EXPECT(smi.Equals(Smi::Handle(Smi::New(5)))); |
309 EXPECT(!smi.Equals(Smi::Handle(Smi::New(6)))); | 308 EXPECT(!smi.Equals(Smi::Handle(Smi::New(6)))); |
310 EXPECT(smi.Equals(smi)); | 309 EXPECT(smi.Equals(smi)); |
311 EXPECT(!smi.Equals(Smi::Handle())); | 310 EXPECT(!smi.Equals(Smi::Handle())); |
312 | 311 |
313 EXPECT(Smi::IsValid(0)); | 312 EXPECT(Smi::IsValid(0)); |
314 EXPECT(Smi::IsValid(-15)); | 313 EXPECT(Smi::IsValid(-15)); |
315 EXPECT(Smi::IsValid(0xFFu)); | 314 EXPECT(Smi::IsValid(0xFFu)); |
316 // Upper two bits must be either 00 or 11. | 315 // Upper two bits must be either 00 or 11. |
317 #if defined(ARCH_IS_64_BIT) | 316 #if defined(ARCH_IS_64_BIT) |
318 EXPECT(!Smi::IsValid(kMaxInt64)); | 317 EXPECT(!Smi::IsValid(kMaxInt64)); |
319 EXPECT(Smi::IsValid(0x3FFFFFFFFFFFFFFF)); | 318 EXPECT(Smi::IsValid(0x3FFFFFFFFFFFFFFF)); |
320 EXPECT(Smi::IsValid(-1)); | 319 EXPECT(Smi::IsValid(-1)); |
321 #else | 320 #else |
322 EXPECT(!Smi::IsValid(kMaxInt32)); | 321 EXPECT(!Smi::IsValid(kMaxInt32)); |
323 EXPECT(Smi::IsValid(0x3FFFFFFF)); | 322 EXPECT(Smi::IsValid(0x3FFFFFFF)); |
324 EXPECT(Smi::IsValid(-1)); | 323 EXPECT(Smi::IsValid(-1)); |
325 EXPECT(!Smi::IsValid(0xFFFFFFFFu)); | 324 EXPECT(!Smi::IsValid(0xFFFFFFFFu)); |
326 #endif | 325 #endif |
(...skipping 11 matching lines...) Expand all Loading... |
338 | 337 |
339 Mint& mint1 = Mint::Handle(); | 338 Mint& mint1 = Mint::Handle(); |
340 mint1 ^= Integer::New(DART_2PART_UINT64_C(0x7FFFFFFF, 100)); | 339 mint1 ^= Integer::New(DART_2PART_UINT64_C(0x7FFFFFFF, 100)); |
341 Mint& mint2 = Mint::Handle(); | 340 Mint& mint2 = Mint::Handle(); |
342 mint2 ^= Integer::New(-DART_2PART_UINT64_C(0x7FFFFFFF, 100)); | 341 mint2 ^= Integer::New(-DART_2PART_UINT64_C(0x7FFFFFFF, 100)); |
343 EXPECT_EQ(-1, a.CompareWith(mint1)); | 342 EXPECT_EQ(-1, a.CompareWith(mint1)); |
344 EXPECT_EQ(1, a.CompareWith(mint2)); | 343 EXPECT_EQ(1, a.CompareWith(mint2)); |
345 EXPECT_EQ(-1, c.CompareWith(mint1)); | 344 EXPECT_EQ(-1, c.CompareWith(mint1)); |
346 EXPECT_EQ(1, c.CompareWith(mint2)); | 345 EXPECT_EQ(1, c.CompareWith(mint2)); |
347 | 346 |
348 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString( | 347 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); |
349 "10000000000000000000")); | 348 Bigint& big2 = |
350 Bigint& big2 = Bigint::Handle(Bigint::NewFromCString( | 349 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); |
351 "-10000000000000000000")); | |
352 EXPECT_EQ(-1, a.CompareWith(big1)); | 350 EXPECT_EQ(-1, a.CompareWith(big1)); |
353 EXPECT_EQ(1, a.CompareWith(big2)); | 351 EXPECT_EQ(1, a.CompareWith(big2)); |
354 EXPECT_EQ(-1, c.CompareWith(big1)); | 352 EXPECT_EQ(-1, c.CompareWith(big1)); |
355 EXPECT_EQ(1, c.CompareWith(big2)); | 353 EXPECT_EQ(1, c.CompareWith(big2)); |
356 } | 354 } |
357 | 355 |
358 | 356 |
359 VM_TEST_CASE(StringCompareTo) { | 357 VM_TEST_CASE(StringCompareTo) { |
360 const String& abcd = String::Handle(String::New("abcd")); | 358 const String& abcd = String::Handle(String::New("abcd")); |
361 const String& abce = String::Handle(String::New("abce")); | 359 const String& abce = String::Handle(String::New("abce")); |
362 EXPECT_EQ(0, abcd.CompareTo(abcd)); | 360 EXPECT_EQ(0, abcd.CompareTo(abcd)); |
363 EXPECT_EQ(0, abce.CompareTo(abce)); | 361 EXPECT_EQ(0, abce.CompareTo(abce)); |
364 EXPECT(abcd.CompareTo(abce) < 0); | 362 EXPECT(abcd.CompareTo(abce) < 0); |
365 EXPECT(abce.CompareTo(abcd) > 0); | 363 EXPECT(abce.CompareTo(abcd) > 0); |
366 | 364 |
367 const int kMonkeyLen = 4; | 365 const int kMonkeyLen = 4; |
368 const uint8_t monkey_utf8[kMonkeyLen] = { 0xf0, 0x9f, 0x90, 0xb5 }; | 366 const uint8_t monkey_utf8[kMonkeyLen] = {0xf0, 0x9f, 0x90, 0xb5}; |
369 const String& monkey_face = | 367 const String& monkey_face = |
370 String::Handle(String::FromUTF8(monkey_utf8, kMonkeyLen)); | 368 String::Handle(String::FromUTF8(monkey_utf8, kMonkeyLen)); |
371 const int kDogLen = 4; | 369 const int kDogLen = 4; |
372 // 0x1f436 DOG FACE. | 370 // 0x1f436 DOG FACE. |
373 const uint8_t dog_utf8[kDogLen] = { 0xf0, 0x9f, 0x90, 0xb6 }; | 371 const uint8_t dog_utf8[kDogLen] = {0xf0, 0x9f, 0x90, 0xb6}; |
374 const String& dog_face = | 372 const String& dog_face = String::Handle(String::FromUTF8(dog_utf8, kDogLen)); |
375 String::Handle(String::FromUTF8(dog_utf8, kDogLen)); | |
376 EXPECT_EQ(0, monkey_face.CompareTo(monkey_face)); | 373 EXPECT_EQ(0, monkey_face.CompareTo(monkey_face)); |
377 EXPECT_EQ(0, dog_face.CompareTo(dog_face)); | 374 EXPECT_EQ(0, dog_face.CompareTo(dog_face)); |
378 EXPECT(monkey_face.CompareTo(dog_face) < 0); | 375 EXPECT(monkey_face.CompareTo(dog_face) < 0); |
379 EXPECT(dog_face.CompareTo(monkey_face) > 0); | 376 EXPECT(dog_face.CompareTo(monkey_face) > 0); |
380 | 377 |
381 const int kDominoLen = 4; | 378 const int kDominoLen = 4; |
382 // 0x1f036 DOMINO TILE HORIZONTAL-00-05. | 379 // 0x1f036 DOMINO TILE HORIZONTAL-00-05. |
383 const uint8_t domino_utf8[kDominoLen] = { 0xf0, 0x9f, 0x80, 0xb6 }; | 380 const uint8_t domino_utf8[kDominoLen] = {0xf0, 0x9f, 0x80, 0xb6}; |
384 const String& domino = | 381 const String& domino = |
385 String::Handle(String::FromUTF8(domino_utf8, kDominoLen)); | 382 String::Handle(String::FromUTF8(domino_utf8, kDominoLen)); |
386 EXPECT_EQ(0, domino.CompareTo(domino)); | 383 EXPECT_EQ(0, domino.CompareTo(domino)); |
387 EXPECT(domino.CompareTo(dog_face) < 0); | 384 EXPECT(domino.CompareTo(dog_face) < 0); |
388 EXPECT(domino.CompareTo(monkey_face) < 0); | 385 EXPECT(domino.CompareTo(monkey_face) < 0); |
389 EXPECT(dog_face.CompareTo(domino) > 0); | 386 EXPECT(dog_face.CompareTo(domino) > 0); |
390 EXPECT(monkey_face.CompareTo(domino) > 0); | 387 EXPECT(monkey_face.CompareTo(domino) > 0); |
391 | 388 |
392 EXPECT(abcd.CompareTo(monkey_face) < 0); | 389 EXPECT(abcd.CompareTo(monkey_face) < 0); |
393 EXPECT(abce.CompareTo(monkey_face) < 0); | 390 EXPECT(abce.CompareTo(monkey_face) < 0); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 decoded = String::DecodeIRI(input); | 432 decoded = String::DecodeIRI(input); |
436 EXPECT(decoded.IsNull()); | 433 EXPECT(decoded.IsNull()); |
437 input = String::New("file%3g"); | 434 input = String::New("file%3g"); |
438 decoded = String::DecodeIRI(input); | 435 decoded = String::DecodeIRI(input); |
439 EXPECT(decoded.IsNull()); | 436 EXPECT(decoded.IsNull()); |
440 } | 437 } |
441 | 438 |
442 | 439 |
443 VM_TEST_CASE(StringIRITwoByte) { | 440 VM_TEST_CASE(StringIRITwoByte) { |
444 const intptr_t kInputLen = 3; | 441 const intptr_t kInputLen = 3; |
445 const uint16_t kInput[kInputLen] = { 'x', '/', 256 }; | 442 const uint16_t kInput[kInputLen] = {'x', '/', 256}; |
446 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen)); | 443 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen)); |
447 const intptr_t kOutputLen = 10; | 444 const intptr_t kOutputLen = 10; |
448 const uint16_t kOutput[kOutputLen] = | 445 const uint16_t kOutput[kOutputLen] = {'x', '%', '2', 'F', '%', |
449 { 'x', '%', '2', 'F', '%', 'C', '4', '%', '8', '0' }; | 446 'C', '4', '%', '8', '0'}; |
450 const String& output = String::Handle(String::FromUTF16(kOutput, kOutputLen)); | 447 const String& output = String::Handle(String::FromUTF16(kOutput, kOutputLen)); |
451 const String& encoded = String::Handle(String::New(String::EncodeIRI(input))); | 448 const String& encoded = String::Handle(String::New(String::EncodeIRI(input))); |
452 EXPECT(output.Equals(encoded)); | 449 EXPECT(output.Equals(encoded)); |
453 const String& decoded = String::Handle(String::DecodeIRI(output)); | 450 const String& decoded = String::Handle(String::DecodeIRI(output)); |
454 EXPECT(input.Equals(decoded)); | 451 EXPECT(input.Equals(decoded)); |
455 } | 452 } |
456 | 453 |
457 | 454 |
458 VM_TEST_CASE(Mint) { | 455 VM_TEST_CASE(Mint) { |
459 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot | 456 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot |
460 // be allocated if it does fit into a Smi. | 457 // be allocated if it does fit into a Smi. |
461 #if !defined(ARCH_IS_64_BIT) | 458 #if !defined(ARCH_IS_64_BIT) |
462 { Mint& med = Mint::Handle(); | 459 { |
| 460 Mint& med = Mint::Handle(); |
463 EXPECT(med.IsNull()); | 461 EXPECT(med.IsNull()); |
464 int64_t v = DART_2PART_UINT64_C(1, 0); | 462 int64_t v = DART_2PART_UINT64_C(1, 0); |
465 med ^= Integer::New(v); | 463 med ^= Integer::New(v); |
466 EXPECT_EQ(v, med.value()); | 464 EXPECT_EQ(v, med.value()); |
467 const String& smi_str = String::Handle(String::New("1")); | 465 const String& smi_str = String::Handle(String::New("1")); |
468 const String& mint1_str = String::Handle(String::New("2147419168")); | 466 const String& mint1_str = String::Handle(String::New("2147419168")); |
469 const String& mint2_str = String::Handle(String::New("-2147419168")); | 467 const String& mint2_str = String::Handle(String::New("-2147419168")); |
470 Integer& i = Integer::Handle(Integer::NewCanonical(smi_str)); | 468 Integer& i = Integer::Handle(Integer::NewCanonical(smi_str)); |
471 EXPECT(i.IsSmi()); | 469 EXPECT(i.IsSmi()); |
472 i = Integer::NewCanonical(mint1_str); | 470 i = Integer::NewCanonical(mint1_str); |
(...skipping 27 matching lines...) Expand all Loading... |
500 | 498 |
501 Mint& c = Mint::Handle(); | 499 Mint& c = Mint::Handle(); |
502 c ^= Integer::New(-DART_2PART_UINT64_C(3, 0)); | 500 c ^= Integer::New(-DART_2PART_UINT64_C(3, 0)); |
503 Smi& smi1 = Smi::Handle(Smi::New(4)); | 501 Smi& smi1 = Smi::Handle(Smi::New(4)); |
504 Smi& smi2 = Smi::Handle(Smi::New(-4)); | 502 Smi& smi2 = Smi::Handle(Smi::New(-4)); |
505 EXPECT_EQ(1, a.CompareWith(smi1)); | 503 EXPECT_EQ(1, a.CompareWith(smi1)); |
506 EXPECT_EQ(1, a.CompareWith(smi2)); | 504 EXPECT_EQ(1, a.CompareWith(smi2)); |
507 EXPECT_EQ(-1, c.CompareWith(smi1)); | 505 EXPECT_EQ(-1, c.CompareWith(smi1)); |
508 EXPECT_EQ(-1, c.CompareWith(smi2)); | 506 EXPECT_EQ(-1, c.CompareWith(smi2)); |
509 | 507 |
510 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString( | 508 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); |
511 "10000000000000000000")); | 509 Bigint& big2 = |
512 Bigint& big2 = Bigint::Handle(Bigint::NewFromCString( | 510 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); |
513 "-10000000000000000000")); | |
514 EXPECT_EQ(-1, a.CompareWith(big1)); | 511 EXPECT_EQ(-1, a.CompareWith(big1)); |
515 EXPECT_EQ(1, a.CompareWith(big2)); | 512 EXPECT_EQ(1, a.CompareWith(big2)); |
516 EXPECT_EQ(-1, c.CompareWith(big1)); | 513 EXPECT_EQ(-1, c.CompareWith(big1)); |
517 EXPECT_EQ(1, c.CompareWith(big2)); | 514 EXPECT_EQ(1, c.CompareWith(big2)); |
518 | 515 |
519 int64_t mint_value = DART_2PART_UINT64_C(0x7FFFFFFF, 64); | 516 int64_t mint_value = DART_2PART_UINT64_C(0x7FFFFFFF, 64); |
520 const String& mint_string = String::Handle(String::New("0x7FFFFFFF00000064")); | 517 const String& mint_string = String::Handle(String::New("0x7FFFFFFF00000064")); |
521 Mint& mint1 = Mint::Handle(); | 518 Mint& mint1 = Mint::Handle(); |
522 mint1 ^= Integer::NewCanonical(mint_string); | 519 mint1 ^= Integer::NewCanonical(mint_string); |
523 Mint& mint2 = Mint::Handle(); | 520 Mint& mint2 = Mint::Handle(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 EXPECT(dbl1.CanonicalizeEquals(dbl2)); | 576 EXPECT(dbl1.CanonicalizeEquals(dbl2)); |
580 const Double& dbl3 = Double::Handle(Double::New(3.3)); | 577 const Double& dbl3 = Double::Handle(Double::New(3.3)); |
581 EXPECT(!dbl1.OperatorEquals(dbl3)); | 578 EXPECT(!dbl1.OperatorEquals(dbl3)); |
582 EXPECT(!dbl1.OperatorEquals(Smi::Handle(Smi::New(3)))); | 579 EXPECT(!dbl1.OperatorEquals(Smi::Handle(Smi::New(3)))); |
583 EXPECT(!dbl1.OperatorEquals(Double::Handle())); | 580 EXPECT(!dbl1.OperatorEquals(Double::Handle())); |
584 const Double& nan0 = Double::Handle(Double::New(NAN)); | 581 const Double& nan0 = Double::Handle(Double::New(NAN)); |
585 EXPECT(isnan(nan0.value())); | 582 EXPECT(isnan(nan0.value())); |
586 EXPECT(nan0.IsIdenticalTo(nan0)); | 583 EXPECT(nan0.IsIdenticalTo(nan0)); |
587 EXPECT(nan0.CanonicalizeEquals(nan0)); | 584 EXPECT(nan0.CanonicalizeEquals(nan0)); |
588 EXPECT(!nan0.OperatorEquals(nan0)); | 585 EXPECT(!nan0.OperatorEquals(nan0)); |
589 const Double& nan1 = Double::Handle( | 586 const Double& nan1 = |
590 Double::New(bit_cast<double>(kMaxUint64 - 0))); | 587 Double::Handle(Double::New(bit_cast<double>(kMaxUint64 - 0))); |
591 const Double& nan2 = Double::Handle( | 588 const Double& nan2 = |
592 Double::New(bit_cast<double>(kMaxUint64 - 1))); | 589 Double::Handle(Double::New(bit_cast<double>(kMaxUint64 - 1))); |
593 EXPECT(isnan(nan1.value())); | 590 EXPECT(isnan(nan1.value())); |
594 EXPECT(isnan(nan2.value())); | 591 EXPECT(isnan(nan2.value())); |
595 EXPECT(!nan1.IsIdenticalTo(nan2)); | 592 EXPECT(!nan1.IsIdenticalTo(nan2)); |
596 EXPECT(!nan1.CanonicalizeEquals(nan2)); | 593 EXPECT(!nan1.CanonicalizeEquals(nan2)); |
597 EXPECT(!nan1.OperatorEquals(nan2)); | 594 EXPECT(!nan1.OperatorEquals(nan2)); |
598 } | 595 } |
599 { | 596 { |
600 const String& dbl_str0 = String::Handle(String::New("bla")); | 597 const String& dbl_str0 = String::Handle(String::New("bla")); |
601 const Double& dbl0 = Double::Handle(Double::New(dbl_str0)); | 598 const Double& dbl0 = Double::Handle(Double::New(dbl_str0)); |
602 EXPECT(dbl0.IsNull()); | 599 EXPECT(dbl0.IsNull()); |
(...skipping 18 matching lines...) Expand all Loading... |
621 b ^= Integer::NewCanonical(test); | 618 b ^= Integer::NewCanonical(test); |
622 const char* str = b.ToCString(); | 619 const char* str = b.ToCString(); |
623 EXPECT_STREQ(cstr, str); | 620 EXPECT_STREQ(cstr, str); |
624 | 621 |
625 int64_t t64 = DART_2PART_UINT64_C(1, 0); | 622 int64_t t64 = DART_2PART_UINT64_C(1, 0); |
626 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64)); | 623 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64)); |
627 EXPECT_EQ(t64, big.AsInt64Value()); | 624 EXPECT_EQ(t64, big.AsInt64Value()); |
628 big = Bigint::NewFromCString("10000000000000000000"); | 625 big = Bigint::NewFromCString("10000000000000000000"); |
629 EXPECT_EQ(1e19, big.AsDoubleValue()); | 626 EXPECT_EQ(1e19, big.AsDoubleValue()); |
630 | 627 |
631 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString( | 628 Bigint& big1 = |
632 "100000000000000000000")); | 629 Bigint::Handle(Bigint::NewFromCString("100000000000000000000")); |
633 Bigint& big2 = Bigint::Handle(Bigint::NewFromCString( | 630 Bigint& big2 = |
634 "100000000000000000010")); | 631 Bigint::Handle(Bigint::NewFromCString("100000000000000000010")); |
635 Bigint& big3 = Bigint::Handle(Bigint::NewFromCString( | 632 Bigint& big3 = |
636 "-10000000000000000000")); | 633 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); |
637 | 634 |
638 EXPECT_EQ(0, big1.CompareWith(big1)); | 635 EXPECT_EQ(0, big1.CompareWith(big1)); |
639 EXPECT_EQ(-1, big1.CompareWith(big2)); | 636 EXPECT_EQ(-1, big1.CompareWith(big2)); |
640 EXPECT_EQ(1, big2.CompareWith(big1)); | 637 EXPECT_EQ(1, big2.CompareWith(big1)); |
641 EXPECT_EQ(1, big1.CompareWith(big3)); | 638 EXPECT_EQ(1, big1.CompareWith(big3)); |
642 EXPECT_EQ(-1, big3.CompareWith(big1)); | 639 EXPECT_EQ(-1, big3.CompareWith(big1)); |
643 | 640 |
644 Smi& smi1 = Smi::Handle(Smi::New(5)); | 641 Smi& smi1 = Smi::Handle(Smi::New(5)); |
645 Smi& smi2 = Smi::Handle(Smi::New(-2)); | 642 Smi& smi2 = Smi::Handle(Smi::New(-2)); |
646 | 643 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 EXPECT_EQ(' ', str.CharAt(5)); | 684 EXPECT_EQ(' ', str.CharAt(5)); |
688 EXPECT_EQ('W', str.CharAt(6)); | 685 EXPECT_EQ('W', str.CharAt(6)); |
689 EXPECT_EQ('o', str.CharAt(7)); | 686 EXPECT_EQ('o', str.CharAt(7)); |
690 EXPECT_EQ('r', str.CharAt(8)); | 687 EXPECT_EQ('r', str.CharAt(8)); |
691 EXPECT_EQ('l', str.CharAt(9)); | 688 EXPECT_EQ('l', str.CharAt(9)); |
692 EXPECT_EQ('d', str.CharAt(10)); | 689 EXPECT_EQ('d', str.CharAt(10)); |
693 EXPECT_EQ('!', str.CharAt(11)); | 690 EXPECT_EQ('!', str.CharAt(11)); |
694 | 691 |
695 const uint8_t* motto = | 692 const uint8_t* motto = |
696 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); | 693 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); |
697 const String& str2 = String::Handle(String::FromUTF8(motto+7, 4)); | 694 const String& str2 = String::Handle(String::FromUTF8(motto + 7, 4)); |
698 EXPECT_EQ(4, str2.Length()); | 695 EXPECT_EQ(4, str2.Length()); |
699 EXPECT_EQ('b', str2.CharAt(0)); | 696 EXPECT_EQ('b', str2.CharAt(0)); |
700 EXPECT_EQ('e', str2.CharAt(1)); | 697 EXPECT_EQ('e', str2.CharAt(1)); |
701 EXPECT_EQ('s', str2.CharAt(2)); | 698 EXPECT_EQ('s', str2.CharAt(2)); |
702 EXPECT_EQ('c', str2.CharAt(3)); | 699 EXPECT_EQ('c', str2.CharAt(3)); |
703 | 700 |
704 const String& str3 = String::Handle(String::New(kHello)); | 701 const String& str3 = String::Handle(String::New(kHello)); |
705 EXPECT(str.Equals(str)); | 702 EXPECT(str.Equals(str)); |
706 EXPECT_EQ(str.Hash(), str.Hash()); | 703 EXPECT_EQ(str.Hash(), str.Hash()); |
707 EXPECT(!str.Equals(str2)); | 704 EXPECT(!str.Equals(str2)); |
708 EXPECT(str.Equals(str3)); | 705 EXPECT(str.Equals(str3)); |
709 EXPECT_EQ(str.Hash(), str3.Hash()); | 706 EXPECT_EQ(str.Hash(), str3.Hash()); |
710 EXPECT(str3.Equals(str)); | 707 EXPECT(str3.Equals(str)); |
711 | 708 |
712 const String& str4 = String::Handle(String::New("foo")); | 709 const String& str4 = String::Handle(String::New("foo")); |
713 const String& str5 = String::Handle(String::New("bar")); | 710 const String& str5 = String::Handle(String::New("bar")); |
714 const String& str6 = String::Handle(String::Concat(str4, str5)); | 711 const String& str6 = String::Handle(String::Concat(str4, str5)); |
715 const String& str7 = String::Handle(String::New("foobar")); | 712 const String& str7 = String::Handle(String::New("foobar")); |
716 EXPECT(str6.Equals(str7)); | 713 EXPECT(str6.Equals(str7)); |
717 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); | 714 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); |
718 | 715 |
719 const String& empty1 = String::Handle(String::New("")); | 716 const String& empty1 = String::Handle(String::New("")); |
720 const String& empty2 = String::Handle(String::New("")); | 717 const String& empty2 = String::Handle(String::New("")); |
721 EXPECT(empty1.Equals(empty2, 0, 0)); | 718 EXPECT(empty1.Equals(empty2, 0, 0)); |
722 | 719 |
723 const intptr_t kCharsLen = 8; | 720 const intptr_t kCharsLen = 8; |
724 const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 }; | 721 const uint8_t chars[kCharsLen] = {1, 2, 127, 64, 92, 0, 55, 55}; |
725 const String& str8 = String::Handle(String::FromUTF8(chars, kCharsLen)); | 722 const String& str8 = String::Handle(String::FromUTF8(chars, kCharsLen)); |
726 EXPECT_EQ(kCharsLen, str8.Length()); | 723 EXPECT_EQ(kCharsLen, str8.Length()); |
727 EXPECT_EQ(1, str8.CharAt(0)); | 724 EXPECT_EQ(1, str8.CharAt(0)); |
728 EXPECT_EQ(127, str8.CharAt(2)); | 725 EXPECT_EQ(127, str8.CharAt(2)); |
729 EXPECT_EQ(64, str8.CharAt(3)); | 726 EXPECT_EQ(64, str8.CharAt(3)); |
730 EXPECT_EQ(0, str8.CharAt(5)); | 727 EXPECT_EQ(0, str8.CharAt(5)); |
731 EXPECT_EQ(55, str8.CharAt(6)); | 728 EXPECT_EQ(55, str8.CharAt(6)); |
732 EXPECT_EQ(55, str8.CharAt(7)); | 729 EXPECT_EQ(55, str8.CharAt(7)); |
733 const intptr_t kCharsIndex = 3; | 730 const intptr_t kCharsIndex = 3; |
734 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); | 731 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); |
735 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); | 732 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); |
736 EXPECT_EQ(64, sub1.CharAt(0)); | 733 EXPECT_EQ(64, sub1.CharAt(0)); |
737 EXPECT_EQ(92, sub1.CharAt(1)); | 734 EXPECT_EQ(92, sub1.CharAt(1)); |
738 EXPECT_EQ(0, sub1.CharAt(2)); | 735 EXPECT_EQ(0, sub1.CharAt(2)); |
739 EXPECT_EQ(55, sub1.CharAt(3)); | 736 EXPECT_EQ(55, sub1.CharAt(3)); |
740 EXPECT_EQ(55, sub1.CharAt(4)); | 737 EXPECT_EQ(55, sub1.CharAt(4)); |
741 | 738 |
742 const intptr_t kWideCharsLen = 7; | 739 const intptr_t kWideCharsLen = 7; |
743 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; | 740 uint16_t wide_chars[kWideCharsLen] = {'H', 'e', 'l', 'l', 'o', 256, '!'}; |
744 const String& two_str = String::Handle(String::FromUTF16(wide_chars, | 741 const String& two_str = |
745 kWideCharsLen)); | 742 String::Handle(String::FromUTF16(wide_chars, kWideCharsLen)); |
746 EXPECT(two_str.IsInstance()); | 743 EXPECT(two_str.IsInstance()); |
747 EXPECT(two_str.IsString()); | 744 EXPECT(two_str.IsString()); |
748 EXPECT(two_str.IsTwoByteString()); | 745 EXPECT(two_str.IsTwoByteString()); |
749 EXPECT(!two_str.IsOneByteString()); | 746 EXPECT(!two_str.IsOneByteString()); |
750 EXPECT_EQ(kWideCharsLen, two_str.Length()); | 747 EXPECT_EQ(kWideCharsLen, two_str.Length()); |
751 EXPECT_EQ('H', two_str.CharAt(0)); | 748 EXPECT_EQ('H', two_str.CharAt(0)); |
752 EXPECT_EQ(256, two_str.CharAt(5)); | 749 EXPECT_EQ(256, two_str.CharAt(5)); |
753 const intptr_t kWideCharsIndex = 3; | 750 const intptr_t kWideCharsIndex = 3; |
754 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); | 751 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); |
755 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); | 752 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); |
756 EXPECT_EQ('l', sub2.CharAt(0)); | 753 EXPECT_EQ('l', sub2.CharAt(0)); |
757 EXPECT_EQ('o', sub2.CharAt(1)); | 754 EXPECT_EQ('o', sub2.CharAt(1)); |
758 EXPECT_EQ(256, sub2.CharAt(2)); | 755 EXPECT_EQ(256, sub2.CharAt(2)); |
759 EXPECT_EQ('!', sub2.CharAt(3)); | 756 EXPECT_EQ('!', sub2.CharAt(3)); |
760 | 757 |
761 { | 758 { |
762 const String& str1 = String::Handle(String::New("My.create")); | 759 const String& str1 = String::Handle(String::New("My.create")); |
763 const String& str2 = String::Handle(String::New("My")); | 760 const String& str2 = String::Handle(String::New("My")); |
764 const String& str3 = String::Handle(String::New("create")); | 761 const String& str3 = String::Handle(String::New("create")); |
765 EXPECT_EQ(true, str1.StartsWith(str2)); | 762 EXPECT_EQ(true, str1.StartsWith(str2)); |
766 EXPECT_EQ(false, str1.StartsWith(str3)); | 763 EXPECT_EQ(false, str1.StartsWith(str3)); |
767 } | 764 } |
768 | 765 |
769 const int32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; | 766 const int32_t four_chars[] = {'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r'}; |
770 const String& four_str = String::Handle(String::FromUTF32(four_chars, 7)); | 767 const String& four_str = String::Handle(String::FromUTF32(four_chars, 7)); |
771 EXPECT_EQ(four_str.Hash(), four_str.Hash()); | 768 EXPECT_EQ(four_str.Hash(), four_str.Hash()); |
772 EXPECT(four_str.IsTwoByteString()); | 769 EXPECT(four_str.IsTwoByteString()); |
773 EXPECT(!four_str.IsOneByteString()); | 770 EXPECT(!four_str.IsOneByteString()); |
774 EXPECT_EQ(8, four_str.Length()); | 771 EXPECT_EQ(8, four_str.Length()); |
775 EXPECT_EQ('C', four_str.CharAt(0)); | 772 EXPECT_EQ('C', four_str.CharAt(0)); |
776 EXPECT_EQ(0xFF, four_str.CharAt(1)); | 773 EXPECT_EQ(0xFF, four_str.CharAt(1)); |
777 EXPECT_EQ('h', four_str.CharAt(2)); | 774 EXPECT_EQ('h', four_str.CharAt(2)); |
778 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); | 775 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); |
779 EXPECT_EQ('a', four_str.CharAt(4)); | 776 EXPECT_EQ('a', four_str.CharAt(4)); |
780 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); | 777 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); |
781 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); | 778 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); |
782 EXPECT_EQ('r', four_str.CharAt(7)); | 779 EXPECT_EQ('r', four_str.CharAt(7)); |
783 | 780 |
784 // Create a 1-byte string from an array of 2-byte elements. | 781 // Create a 1-byte string from an array of 2-byte elements. |
785 { | 782 { |
786 const uint16_t char16[] = { 0x00, 0x7F, 0xFF }; | 783 const uint16_t char16[] = {0x00, 0x7F, 0xFF}; |
787 const String& str8 = String::Handle(String::FromUTF16(char16, 3)); | 784 const String& str8 = String::Handle(String::FromUTF16(char16, 3)); |
788 EXPECT(str8.IsOneByteString()); | 785 EXPECT(str8.IsOneByteString()); |
789 EXPECT(!str8.IsTwoByteString()); | 786 EXPECT(!str8.IsTwoByteString()); |
790 EXPECT_EQ(0x00, str8.CharAt(0)); | 787 EXPECT_EQ(0x00, str8.CharAt(0)); |
791 EXPECT_EQ(0x7F, str8.CharAt(1)); | 788 EXPECT_EQ(0x7F, str8.CharAt(1)); |
792 EXPECT_EQ(0xFF, str8.CharAt(2)); | 789 EXPECT_EQ(0xFF, str8.CharAt(2)); |
793 } | 790 } |
794 | 791 |
795 // Create a 1-byte string from an array of 4-byte elements. | 792 // Create a 1-byte string from an array of 4-byte elements. |
796 { | 793 { |
797 const int32_t char32[] = { 0x00, 0x1F, 0x7F }; | 794 const int32_t char32[] = {0x00, 0x1F, 0x7F}; |
798 const String& str8 = String::Handle(String::FromUTF32(char32, 3)); | 795 const String& str8 = String::Handle(String::FromUTF32(char32, 3)); |
799 EXPECT(str8.IsOneByteString()); | 796 EXPECT(str8.IsOneByteString()); |
800 EXPECT(!str8.IsTwoByteString()); | 797 EXPECT(!str8.IsTwoByteString()); |
801 EXPECT_EQ(0x00, str8.CharAt(0)); | 798 EXPECT_EQ(0x00, str8.CharAt(0)); |
802 EXPECT_EQ(0x1F, str8.CharAt(1)); | 799 EXPECT_EQ(0x1F, str8.CharAt(1)); |
803 EXPECT_EQ(0x7F, str8.CharAt(2)); | 800 EXPECT_EQ(0x7F, str8.CharAt(2)); |
804 } | 801 } |
805 | 802 |
806 // Create a 2-byte string from an array of 4-byte elements. | 803 // Create a 2-byte string from an array of 4-byte elements. |
807 { | 804 { |
808 const int32_t char32[] = { 0, 0x7FFF, 0xFFFF }; | 805 const int32_t char32[] = {0, 0x7FFF, 0xFFFF}; |
809 const String& str16 = String::Handle(String::FromUTF32(char32, 3)); | 806 const String& str16 = String::Handle(String::FromUTF32(char32, 3)); |
810 EXPECT(!str16.IsOneByteString()); | 807 EXPECT(!str16.IsOneByteString()); |
811 EXPECT(str16.IsTwoByteString()); | 808 EXPECT(str16.IsTwoByteString()); |
812 EXPECT_EQ(0x0000, str16.CharAt(0)); | 809 EXPECT_EQ(0x0000, str16.CharAt(0)); |
813 EXPECT_EQ(0x7FFF, str16.CharAt(1)); | 810 EXPECT_EQ(0x7FFF, str16.CharAt(1)); |
814 EXPECT_EQ(0xFFFF, str16.CharAt(2)); | 811 EXPECT_EQ(0xFFFF, str16.CharAt(2)); |
815 } | 812 } |
816 } | 813 } |
817 | 814 |
818 | 815 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 EXPECT_EQ(three_one_three_len, str8.Length()); | 1000 EXPECT_EQ(three_one_three_len, str8.Length()); |
1004 EXPECT(str8.Equals(three_one_three)); | 1001 EXPECT(str8.Equals(three_one_three)); |
1005 } | 1002 } |
1006 | 1003 |
1007 // Concatenate empty and non-empty 2-byte strings. | 1004 // Concatenate empty and non-empty 2-byte strings. |
1008 { | 1005 { |
1009 const String& str1 = String::Handle(String::New("")); | 1006 const String& str1 = String::Handle(String::New("")); |
1010 EXPECT(str1.IsOneByteString()); | 1007 EXPECT(str1.IsOneByteString()); |
1011 EXPECT_EQ(0, str1.Length()); | 1008 EXPECT_EQ(0, str1.Length()); |
1012 | 1009 |
1013 uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1010 uint16_t two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1014 intptr_t two_len = sizeof(two) / sizeof(two[0]); | 1011 intptr_t two_len = sizeof(two) / sizeof(two[0]); |
1015 const String& str2 = String::Handle(String::FromUTF16(two, two_len)); | 1012 const String& str2 = String::Handle(String::FromUTF16(two, two_len)); |
1016 EXPECT(str2.IsTwoByteString()); | 1013 EXPECT(str2.IsTwoByteString()); |
1017 EXPECT_EQ(two_len, str2.Length()); | 1014 EXPECT_EQ(two_len, str2.Length()); |
1018 | 1015 |
1019 // Concat | 1016 // Concat |
1020 | 1017 |
1021 const String& str3 = String::Handle(String::Concat(str1, str2)); | 1018 const String& str3 = String::Handle(String::Concat(str1, str2)); |
1022 EXPECT(str3.IsTwoByteString()); | 1019 EXPECT(str3.IsTwoByteString()); |
1023 EXPECT_EQ(two_len, str3.Length()); | 1020 EXPECT_EQ(two_len, str3.Length()); |
(...skipping 25 matching lines...) Expand all Loading... |
1049 EXPECT(str6.Equals(str2)); | 1046 EXPECT(str6.Equals(str2)); |
1050 | 1047 |
1051 const Array& array3 = Array::Handle(Array::New(3)); | 1048 const Array& array3 = Array::Handle(Array::New(3)); |
1052 EXPECT_EQ(3, array3.Length()); | 1049 EXPECT_EQ(3, array3.Length()); |
1053 array3.SetAt(0, str2); | 1050 array3.SetAt(0, str2); |
1054 array3.SetAt(1, str1); | 1051 array3.SetAt(1, str1); |
1055 array3.SetAt(2, str2); | 1052 array3.SetAt(2, str2); |
1056 const String& str7 = String::Handle(String::ConcatAll(array3)); | 1053 const String& str7 = String::Handle(String::ConcatAll(array3)); |
1057 EXPECT(str7.IsTwoByteString()); | 1054 EXPECT(str7.IsTwoByteString()); |
1058 EXPECT_EQ(two_len * 2, str7.Length()); | 1055 EXPECT_EQ(two_len * 2, str7.Length()); |
1059 uint16_t twotwo[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1056 uint16_t twotwo[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, |
1060 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1057 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1061 intptr_t twotwo_len = sizeof(twotwo) / sizeof(twotwo[0]); | 1058 intptr_t twotwo_len = sizeof(twotwo) / sizeof(twotwo[0]); |
1062 EXPECT(str7.IsTwoByteString()); | 1059 EXPECT(str7.IsTwoByteString()); |
1063 EXPECT(str7.Equals(twotwo, twotwo_len)); | 1060 EXPECT(str7.Equals(twotwo, twotwo_len)); |
1064 } | 1061 } |
1065 | 1062 |
1066 // Concatenating non-empty 2-byte strings. | 1063 // Concatenating non-empty 2-byte strings. |
1067 { | 1064 { |
1068 const uint16_t one[] = { 0x05D0, 0x05D9, 0x05D9, 0x05DF }; | 1065 const uint16_t one[] = {0x05D0, 0x05D9, 0x05D9, 0x05DF}; |
1069 intptr_t one_len = sizeof(one) / sizeof(one[0]); | 1066 intptr_t one_len = sizeof(one) / sizeof(one[0]); |
1070 const String& str1 = String::Handle(String::FromUTF16(one, one_len)); | 1067 const String& str1 = String::Handle(String::FromUTF16(one, one_len)); |
1071 EXPECT(str1.IsTwoByteString()); | 1068 EXPECT(str1.IsTwoByteString()); |
1072 EXPECT_EQ(one_len, str1.Length()); | 1069 EXPECT_EQ(one_len, str1.Length()); |
1073 | 1070 |
1074 const uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1071 const uint16_t two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1075 intptr_t two_len = sizeof(two) / sizeof(two[0]); | 1072 intptr_t two_len = sizeof(two) / sizeof(two[0]); |
1076 const String& str2 = String::Handle(String::FromUTF16(two, two_len)); | 1073 const String& str2 = String::Handle(String::FromUTF16(two, two_len)); |
1077 EXPECT(str2.IsTwoByteString()); | 1074 EXPECT(str2.IsTwoByteString()); |
1078 EXPECT_EQ(two_len, str2.Length()); | 1075 EXPECT_EQ(two_len, str2.Length()); |
1079 | 1076 |
1080 // Concat | 1077 // Concat |
1081 | 1078 |
1082 const String& one_two_str = String::Handle(String::Concat(str1, str2)); | 1079 const String& one_two_str = String::Handle(String::Concat(str1, str2)); |
1083 EXPECT(one_two_str.IsTwoByteString()); | 1080 EXPECT(one_two_str.IsTwoByteString()); |
1084 const uint16_t one_two[] = { 0x05D0, 0x05D9, 0x05D9, 0x05DF, | 1081 const uint16_t one_two[] = {0x05D0, 0x05D9, 0x05D9, 0x05DF, 0x05E6, |
1085 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1082 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1086 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); | 1083 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); |
1087 EXPECT_EQ(one_two_len, one_two_str.Length()); | 1084 EXPECT_EQ(one_two_len, one_two_str.Length()); |
1088 EXPECT(one_two_str.Equals(one_two, one_two_len)); | 1085 EXPECT(one_two_str.Equals(one_two, one_two_len)); |
1089 | 1086 |
1090 const String& two_one_str = String::Handle(String::Concat(str2, str1)); | 1087 const String& two_one_str = String::Handle(String::Concat(str2, str1)); |
1091 EXPECT(two_one_str.IsTwoByteString()); | 1088 EXPECT(two_one_str.IsTwoByteString()); |
1092 const uint16_t two_one[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1089 const uint16_t two_one[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, |
1093 0x05D0, 0x05D9, 0x05D9, 0x05DF }; | 1090 0x05D0, 0x05D9, 0x05D9, 0x05DF}; |
1094 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); | 1091 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); |
1095 EXPECT_EQ(two_one_len, two_one_str.Length()); | 1092 EXPECT_EQ(two_one_len, two_one_str.Length()); |
1096 EXPECT(two_one_str.Equals(two_one, two_one_len)); | 1093 EXPECT(two_one_str.Equals(two_one, two_one_len)); |
1097 | 1094 |
1098 // ConcatAll | 1095 // ConcatAll |
1099 | 1096 |
1100 const Array& array1 = Array::Handle(Array::New(2)); | 1097 const Array& array1 = Array::Handle(Array::New(2)); |
1101 EXPECT_EQ(2, array1.Length()); | 1098 EXPECT_EQ(2, array1.Length()); |
1102 array1.SetAt(0, str1); | 1099 array1.SetAt(0, str1); |
1103 array1.SetAt(1, str2); | 1100 array1.SetAt(1, str2); |
(...skipping 11 matching lines...) Expand all Loading... |
1115 EXPECT_EQ(two_one_len, str4.Length()); | 1112 EXPECT_EQ(two_one_len, str4.Length()); |
1116 EXPECT(str4.Equals(two_one, two_one_len)); | 1113 EXPECT(str4.Equals(two_one, two_one_len)); |
1117 | 1114 |
1118 const Array& array3 = Array::Handle(Array::New(3)); | 1115 const Array& array3 = Array::Handle(Array::New(3)); |
1119 EXPECT_EQ(3, array3.Length()); | 1116 EXPECT_EQ(3, array3.Length()); |
1120 array3.SetAt(0, str1); | 1117 array3.SetAt(0, str1); |
1121 array3.SetAt(1, str2); | 1118 array3.SetAt(1, str2); |
1122 array3.SetAt(2, str1); | 1119 array3.SetAt(2, str1); |
1123 const String& str5 = String::Handle(String::ConcatAll(array3)); | 1120 const String& str5 = String::Handle(String::ConcatAll(array3)); |
1124 EXPECT(str5.IsTwoByteString()); | 1121 EXPECT(str5.IsTwoByteString()); |
1125 const uint16_t one_two_one[] = { 0x05D0, 0x05D9, 0x05D9, 0x05DF, | 1122 const uint16_t one_two_one[] = {0x05D0, 0x05D9, 0x05D9, 0x05DF, 0x05E6, |
1126 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1123 0x05D5, 0x05D5, 0x05D9, 0x05D9, 0x05D0, |
1127 0x05D0, 0x05D9, 0x05D9, 0x05DF }; | 1124 0x05D9, 0x05D9, 0x05DF}; |
1128 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); | 1125 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); |
1129 EXPECT_EQ(one_two_one_len, str5.Length()); | 1126 EXPECT_EQ(one_two_one_len, str5.Length()); |
1130 EXPECT(str5.Equals(one_two_one, one_two_one_len)); | 1127 EXPECT(str5.Equals(one_two_one, one_two_one_len)); |
1131 | 1128 |
1132 const Array& array4 = Array::Handle(Array::New(3)); | 1129 const Array& array4 = Array::Handle(Array::New(3)); |
1133 EXPECT_EQ(3, array4.Length()); | 1130 EXPECT_EQ(3, array4.Length()); |
1134 array4.SetAt(0, str2); | 1131 array4.SetAt(0, str2); |
1135 array4.SetAt(1, str1); | 1132 array4.SetAt(1, str1); |
1136 array4.SetAt(2, str2); | 1133 array4.SetAt(2, str2); |
1137 const String& str6 = String::Handle(String::ConcatAll(array4)); | 1134 const String& str6 = String::Handle(String::ConcatAll(array4)); |
1138 EXPECT(str6.IsTwoByteString()); | 1135 EXPECT(str6.IsTwoByteString()); |
1139 const uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1136 const uint16_t two_one_two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, |
1140 0x05D0, 0x05D9, 0x05D9, 0x05DF, | 1137 0x05D0, 0x05D9, 0x05D9, 0x05DF, 0x05E6, |
1141 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1138 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1142 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); | 1139 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); |
1143 EXPECT_EQ(two_one_two_len, str6.Length()); | 1140 EXPECT_EQ(two_one_two_len, str6.Length()); |
1144 EXPECT(str6.Equals(two_one_two, two_one_two_len)); | 1141 EXPECT(str6.Equals(two_one_two, two_one_two_len)); |
1145 } | 1142 } |
1146 | 1143 |
1147 // Concatenated emtpy and non-empty strings built from 4-byte elements. | 1144 // Concatenated emtpy and non-empty strings built from 4-byte elements. |
1148 { | 1145 { |
1149 const String& str1 = String::Handle(String::New("")); | 1146 const String& str1 = String::Handle(String::New("")); |
1150 EXPECT(str1.IsOneByteString()); | 1147 EXPECT(str1.IsOneByteString()); |
1151 EXPECT_EQ(0, str1.Length()); | 1148 EXPECT_EQ(0, str1.Length()); |
1152 | 1149 |
1153 int32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; | 1150 int32_t four[] = {0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1}; |
1154 intptr_t four_len = sizeof(four) / sizeof(four[0]); | 1151 intptr_t four_len = sizeof(four) / sizeof(four[0]); |
1155 intptr_t expected_len = (four_len * 2); | 1152 intptr_t expected_len = (four_len * 2); |
1156 const String& str2 = String::Handle(String::FromUTF32(four, four_len)); | 1153 const String& str2 = String::Handle(String::FromUTF32(four, four_len)); |
1157 EXPECT(str2.IsTwoByteString()); | 1154 EXPECT(str2.IsTwoByteString()); |
1158 EXPECT_EQ(expected_len, str2.Length()); | 1155 EXPECT_EQ(expected_len, str2.Length()); |
1159 | 1156 |
1160 // Concat | 1157 // Concat |
1161 | 1158 |
1162 const String& str3 = String::Handle(String::Concat(str1, str2)); | 1159 const String& str3 = String::Handle(String::Concat(str1, str2)); |
1163 EXPECT_EQ(expected_len, str3.Length()); | 1160 EXPECT_EQ(expected_len, str3.Length()); |
(...skipping 24 matching lines...) Expand all Loading... |
1188 EXPECT_EQ(expected_len, str6.Length()); | 1185 EXPECT_EQ(expected_len, str6.Length()); |
1189 EXPECT(str6.Equals(str2)); | 1186 EXPECT(str6.Equals(str2)); |
1190 | 1187 |
1191 const Array& array3 = Array::Handle(Array::New(3)); | 1188 const Array& array3 = Array::Handle(Array::New(3)); |
1192 EXPECT_EQ(3, array3.Length()); | 1189 EXPECT_EQ(3, array3.Length()); |
1193 array3.SetAt(0, str2); | 1190 array3.SetAt(0, str2); |
1194 array3.SetAt(1, str1); | 1191 array3.SetAt(1, str1); |
1195 array3.SetAt(2, str2); | 1192 array3.SetAt(2, str2); |
1196 const String& str7 = String::Handle(String::ConcatAll(array3)); | 1193 const String& str7 = String::Handle(String::ConcatAll(array3)); |
1197 EXPECT(str7.IsTwoByteString()); | 1194 EXPECT(str7.IsTwoByteString()); |
1198 int32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, | 1195 int32_t fourfour[] = {0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, |
1199 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; | 1196 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1}; |
1200 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); | 1197 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); |
1201 EXPECT_EQ((fourfour_len * 2), str7.Length()); | 1198 EXPECT_EQ((fourfour_len * 2), str7.Length()); |
1202 const String& fourfour_str = | 1199 const String& fourfour_str = |
1203 String::Handle(String::FromUTF32(fourfour, fourfour_len)); | 1200 String::Handle(String::FromUTF32(fourfour, fourfour_len)); |
1204 EXPECT(str7.Equals(fourfour_str)); | 1201 EXPECT(str7.Equals(fourfour_str)); |
1205 } | 1202 } |
1206 | 1203 |
1207 // Concatenate non-empty strings built from 4-byte elements. | 1204 // Concatenate non-empty strings built from 4-byte elements. |
1208 { | 1205 { |
1209 const int32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1206 const int32_t one[] = {0x105D0, 0x105D9, 0x105D9, 0x105DF}; |
1210 intptr_t one_len = sizeof(one) / sizeof(one[0]); | 1207 intptr_t one_len = sizeof(one) / sizeof(one[0]); |
1211 const String& onestr = String::Handle(String::FromUTF32(one, one_len)); | 1208 const String& onestr = String::Handle(String::FromUTF32(one, one_len)); |
1212 EXPECT(onestr.IsTwoByteString()); | 1209 EXPECT(onestr.IsTwoByteString()); |
1213 EXPECT_EQ((one_len *2), onestr.Length()); | 1210 EXPECT_EQ((one_len * 2), onestr.Length()); |
1214 | 1211 |
1215 const int32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; | 1212 const int32_t two[] = {0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9}; |
1216 intptr_t two_len = sizeof(two) / sizeof(two[0]); | 1213 intptr_t two_len = sizeof(two) / sizeof(two[0]); |
1217 const String& twostr = String::Handle(String::FromUTF32(two, two_len)); | 1214 const String& twostr = String::Handle(String::FromUTF32(two, two_len)); |
1218 EXPECT(twostr.IsTwoByteString()); | 1215 EXPECT(twostr.IsTwoByteString()); |
1219 EXPECT_EQ((two_len * 2), twostr.Length()); | 1216 EXPECT_EQ((two_len * 2), twostr.Length()); |
1220 | 1217 |
1221 // Concat | 1218 // Concat |
1222 | 1219 |
1223 const String& str1 = String::Handle(String::Concat(onestr, twostr)); | 1220 const String& str1 = String::Handle(String::Concat(onestr, twostr)); |
1224 EXPECT(str1.IsTwoByteString()); | 1221 EXPECT(str1.IsTwoByteString()); |
1225 const int32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1222 const int32_t one_two[] = {0x105D0, 0x105D9, 0x105D9, 0x105DF, 0x105E6, |
1226 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; | 1223 0x105D5, 0x105D5, 0x105D9, 0x105D9}; |
1227 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); | 1224 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); |
1228 EXPECT_EQ((one_two_len * 2), str1.Length()); | 1225 EXPECT_EQ((one_two_len * 2), str1.Length()); |
1229 const String& one_two_str = | 1226 const String& one_two_str = |
1230 String::Handle(String::FromUTF32(one_two, one_two_len)); | 1227 String::Handle(String::FromUTF32(one_two, one_two_len)); |
1231 EXPECT(str1.Equals(one_two_str)); | 1228 EXPECT(str1.Equals(one_two_str)); |
1232 | 1229 |
1233 const String& str2 = String::Handle(String::Concat(twostr, onestr)); | 1230 const String& str2 = String::Handle(String::Concat(twostr, onestr)); |
1234 EXPECT(str2.IsTwoByteString()); | 1231 EXPECT(str2.IsTwoByteString()); |
1235 const int32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, | 1232 const int32_t two_one[] = {0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, |
1236 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1233 0x105D0, 0x105D9, 0x105D9, 0x105DF}; |
1237 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); | 1234 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); |
1238 EXPECT_EQ((two_one_len * 2), str2.Length()); | 1235 EXPECT_EQ((two_one_len * 2), str2.Length()); |
1239 const String& two_one_str = | 1236 const String& two_one_str = |
1240 String::Handle(String::FromUTF32(two_one, two_one_len)); | 1237 String::Handle(String::FromUTF32(two_one, two_one_len)); |
1241 EXPECT(str2.Equals(two_one_str)); | 1238 EXPECT(str2.Equals(two_one_str)); |
1242 | 1239 |
1243 // ConcatAll | 1240 // ConcatAll |
1244 | 1241 |
1245 const Array& array1 = Array::Handle(Array::New(2)); | 1242 const Array& array1 = Array::Handle(Array::New(2)); |
1246 EXPECT_EQ(2, array1.Length()); | 1243 EXPECT_EQ(2, array1.Length()); |
(...skipping 13 matching lines...) Expand all Loading... |
1260 EXPECT_EQ((two_one_len * 2), str4.Length()); | 1257 EXPECT_EQ((two_one_len * 2), str4.Length()); |
1261 EXPECT(str4.Equals(two_one_str)); | 1258 EXPECT(str4.Equals(two_one_str)); |
1262 | 1259 |
1263 const Array& array3 = Array::Handle(Array::New(3)); | 1260 const Array& array3 = Array::Handle(Array::New(3)); |
1264 EXPECT_EQ(3, array3.Length()); | 1261 EXPECT_EQ(3, array3.Length()); |
1265 array3.SetAt(0, onestr); | 1262 array3.SetAt(0, onestr); |
1266 array3.SetAt(1, twostr); | 1263 array3.SetAt(1, twostr); |
1267 array3.SetAt(2, onestr); | 1264 array3.SetAt(2, onestr); |
1268 const String& str5 = String::Handle(String::ConcatAll(array3)); | 1265 const String& str5 = String::Handle(String::ConcatAll(array3)); |
1269 EXPECT(str5.IsTwoByteString()); | 1266 EXPECT(str5.IsTwoByteString()); |
1270 const int32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1267 const int32_t one_two_one[] = {0x105D0, 0x105D9, 0x105D9, 0x105DF, 0x105E6, |
1271 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1268 0x105D5, 0x105D5, 0x105D9, 0x105D9, 0x105D0, |
1272 0x105D9, | 1269 0x105D9, 0x105D9, 0x105DF}; |
1273 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | |
1274 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); | 1270 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); |
1275 EXPECT_EQ((one_two_one_len * 2), str5.Length()); | 1271 EXPECT_EQ((one_two_one_len * 2), str5.Length()); |
1276 const String& one_two_one_str = | 1272 const String& one_two_one_str = |
1277 String::Handle(String::FromUTF32(one_two_one, one_two_one_len)); | 1273 String::Handle(String::FromUTF32(one_two_one, one_two_one_len)); |
1278 EXPECT(str5.Equals(one_two_one_str)); | 1274 EXPECT(str5.Equals(one_two_one_str)); |
1279 | 1275 |
1280 const Array& array4 = Array::Handle(Array::New(3)); | 1276 const Array& array4 = Array::Handle(Array::New(3)); |
1281 EXPECT_EQ(3, array4.Length()); | 1277 EXPECT_EQ(3, array4.Length()); |
1282 array4.SetAt(0, twostr); | 1278 array4.SetAt(0, twostr); |
1283 array4.SetAt(1, onestr); | 1279 array4.SetAt(1, onestr); |
1284 array4.SetAt(2, twostr); | 1280 array4.SetAt(2, twostr); |
1285 const String& str6 = String::Handle(String::ConcatAll(array4)); | 1281 const String& str6 = String::Handle(String::ConcatAll(array4)); |
1286 EXPECT(str6.IsTwoByteString()); | 1282 EXPECT(str6.IsTwoByteString()); |
1287 const int32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1283 const int32_t two_one_two[] = {0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, |
1288 0x105D9, | 1284 0x105D0, 0x105D9, 0x105D9, 0x105DF, 0x105E6, |
1289 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1285 0x105D5, 0x105D5, 0x105D9, 0x105D9}; |
1290 0x105E6, 0x105D5, 0x105D5, 0x105D9, | |
1291 0x105D9 }; | |
1292 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); | 1286 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); |
1293 EXPECT_EQ((two_one_two_len * 2), str6.Length()); | 1287 EXPECT_EQ((two_one_two_len * 2), str6.Length()); |
1294 const String& two_one_two_str = | 1288 const String& two_one_two_str = |
1295 String::Handle(String::FromUTF32(two_one_two, two_one_two_len)); | 1289 String::Handle(String::FromUTF32(two_one_two, two_one_two_len)); |
1296 EXPECT(str6.Equals(two_one_two_str)); | 1290 EXPECT(str6.Equals(two_one_two_str)); |
1297 } | 1291 } |
1298 | 1292 |
1299 // Concatenate 1-byte strings and 2-byte strings. | 1293 // Concatenate 1-byte strings and 2-byte strings. |
1300 { | 1294 { |
1301 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; | 1295 const uint8_t one[] = {'o', 'n', 'e', ' ', 'b', 'y', 't', 'e'}; |
1302 intptr_t one_len = sizeof(one) / sizeof(one[0]); | 1296 intptr_t one_len = sizeof(one) / sizeof(one[0]); |
1303 const String& onestr = String::Handle(String::FromLatin1(one, one_len)); | 1297 const String& onestr = String::Handle(String::FromLatin1(one, one_len)); |
1304 EXPECT(onestr.IsOneByteString()); | 1298 EXPECT(onestr.IsOneByteString()); |
1305 EXPECT_EQ(one_len, onestr.Length()); | 1299 EXPECT_EQ(one_len, onestr.Length()); |
1306 EXPECT(onestr.EqualsLatin1(one, one_len)); | 1300 EXPECT(onestr.EqualsLatin1(one, one_len)); |
1307 | 1301 |
1308 uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1302 uint16_t two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1309 intptr_t two_len = sizeof(two) / sizeof(two[0]); | 1303 intptr_t two_len = sizeof(two) / sizeof(two[0]); |
1310 const String& twostr = String::Handle(String::FromUTF16(two, two_len)); | 1304 const String& twostr = String::Handle(String::FromUTF16(two, two_len)); |
1311 EXPECT(twostr.IsTwoByteString()); | 1305 EXPECT(twostr.IsTwoByteString()); |
1312 EXPECT_EQ(two_len, twostr.Length()); | 1306 EXPECT_EQ(two_len, twostr.Length()); |
1313 EXPECT(twostr.Equals(two, two_len)); | 1307 EXPECT(twostr.Equals(two, two_len)); |
1314 | 1308 |
1315 // Concat | 1309 // Concat |
1316 | 1310 |
1317 const String& one_two_str = String::Handle(String::Concat(onestr, twostr)); | 1311 const String& one_two_str = String::Handle(String::Concat(onestr, twostr)); |
1318 EXPECT(one_two_str.IsTwoByteString()); | 1312 EXPECT(one_two_str.IsTwoByteString()); |
1319 uint16_t one_two[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e', | 1313 uint16_t one_two[] = {'o', 'n', 'e', ' ', 'b', 'y', 't', |
1320 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1314 'e', 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1321 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); | 1315 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); |
1322 EXPECT_EQ(one_two_len, one_two_str.Length()); | 1316 EXPECT_EQ(one_two_len, one_two_str.Length()); |
1323 EXPECT(one_two_str.Equals(one_two, one_two_len)); | 1317 EXPECT(one_two_str.Equals(one_two, one_two_len)); |
1324 | 1318 |
1325 const String& two_one_str = String::Handle(String::Concat(twostr, onestr)); | 1319 const String& two_one_str = String::Handle(String::Concat(twostr, onestr)); |
1326 EXPECT(two_one_str.IsTwoByteString()); | 1320 EXPECT(two_one_str.IsTwoByteString()); |
1327 uint16_t two_one[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1321 uint16_t two_one[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 'o', 'n', |
1328 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; | 1322 'e', ' ', 'b', 'y', 't', 'e'}; |
1329 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); | 1323 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); |
1330 EXPECT_EQ(two_one_len, two_one_str.Length()); | 1324 EXPECT_EQ(two_one_len, two_one_str.Length()); |
1331 EXPECT(two_one_str.Equals(two_one, two_one_len)); | 1325 EXPECT(two_one_str.Equals(two_one, two_one_len)); |
1332 | 1326 |
1333 // ConcatAll | 1327 // ConcatAll |
1334 | 1328 |
1335 const Array& array1 = Array::Handle(Array::New(3)); | 1329 const Array& array1 = Array::Handle(Array::New(3)); |
1336 EXPECT_EQ(3, array1.Length()); | 1330 EXPECT_EQ(3, array1.Length()); |
1337 array1.SetAt(0, onestr); | 1331 array1.SetAt(0, onestr); |
1338 array1.SetAt(1, twostr); | 1332 array1.SetAt(1, twostr); |
1339 array1.SetAt(2, onestr); | 1333 array1.SetAt(2, onestr); |
1340 const String& one_two_one_str = String::Handle(String::ConcatAll(array1)); | 1334 const String& one_two_one_str = String::Handle(String::ConcatAll(array1)); |
1341 EXPECT(one_two_one_str.IsTwoByteString()); | 1335 EXPECT(one_two_one_str.IsTwoByteString()); |
1342 EXPECT_EQ(onestr.Length()*2 + twostr.Length(), one_two_one_str.Length()); | 1336 EXPECT_EQ(onestr.Length() * 2 + twostr.Length(), one_two_one_str.Length()); |
1343 uint16_t one_two_one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e', | 1337 uint16_t one_two_one[] = {'o', 'n', 'e', ' ', 'b', 'y', 't', |
1344 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1338 'e', 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 'o', |
1345 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; | 1339 'n', 'e', ' ', 'b', 'y', 't', 'e'}; |
1346 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); | 1340 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); |
1347 EXPECT(one_two_one_str.Equals(one_two_one, one_two_one_len)); | 1341 EXPECT(one_two_one_str.Equals(one_two_one, one_two_one_len)); |
1348 | 1342 |
1349 const Array& array2 = Array::Handle(Array::New(3)); | 1343 const Array& array2 = Array::Handle(Array::New(3)); |
1350 EXPECT_EQ(3, array2.Length()); | 1344 EXPECT_EQ(3, array2.Length()); |
1351 array2.SetAt(0, twostr); | 1345 array2.SetAt(0, twostr); |
1352 array2.SetAt(1, onestr); | 1346 array2.SetAt(1, onestr); |
1353 array2.SetAt(2, twostr); | 1347 array2.SetAt(2, twostr); |
1354 const String& two_one_two_str = String::Handle(String::ConcatAll(array2)); | 1348 const String& two_one_two_str = String::Handle(String::ConcatAll(array2)); |
1355 EXPECT(two_one_two_str.IsTwoByteString()); | 1349 EXPECT(two_one_two_str.IsTwoByteString()); |
1356 EXPECT_EQ(twostr.Length()*2 + onestr.Length(), two_one_two_str.Length()); | 1350 EXPECT_EQ(twostr.Length() * 2 + onestr.Length(), two_one_two_str.Length()); |
1357 uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, | 1351 uint16_t two_one_two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 'o', |
1358 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e', | 1352 'n', 'e', ' ', 'b', 'y', 't', |
1359 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; | 1353 'e', 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1360 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); | 1354 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); |
1361 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len)); | 1355 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len)); |
1362 } | 1356 } |
1363 } | 1357 } |
1364 | 1358 |
1365 | 1359 |
1366 VM_TEST_CASE(StringHashConcat) { | 1360 VM_TEST_CASE(StringHashConcat) { |
1367 EXPECT_EQ(String::Handle(String::New("onebyte")).Hash(), | 1361 EXPECT_EQ(String::Handle(String::New("onebyte")).Hash(), |
1368 String::HashConcat(String::Handle(String::New("one")), | 1362 String::HashConcat(String::Handle(String::New("one")), |
1369 String::Handle(String::New("byte")))); | 1363 String::Handle(String::New("byte")))); |
1370 uint16_t clef_utf16[] = { 0xD834, 0xDD1E }; | 1364 uint16_t clef_utf16[] = {0xD834, 0xDD1E}; |
1371 const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2)); | 1365 const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2)); |
1372 int32_t clef_utf32[] = { 0x1D11E }; | 1366 int32_t clef_utf32[] = {0x1D11E}; |
1373 EXPECT(clef.Equals(clef_utf32, 1)); | 1367 EXPECT(clef.Equals(clef_utf32, 1)); |
1374 intptr_t hash32 = String::Hash(clef_utf32, 1); | 1368 intptr_t hash32 = String::Hash(clef_utf32, 1); |
1375 EXPECT_EQ(hash32, clef.Hash()); | 1369 EXPECT_EQ(hash32, clef.Hash()); |
1376 EXPECT_EQ(hash32, String::HashConcat( | 1370 EXPECT_EQ(hash32, String::HashConcat( |
1377 String::Handle(String::FromUTF16(clef_utf16, 1)), | 1371 String::Handle(String::FromUTF16(clef_utf16, 1)), |
1378 String::Handle(String::FromUTF16(clef_utf16 + 1, 1)))); | 1372 String::Handle(String::FromUTF16(clef_utf16 + 1, 1)))); |
1379 } | 1373 } |
1380 | 1374 |
1381 | 1375 |
1382 VM_TEST_CASE(StringSubStringDifferentWidth) { | 1376 VM_TEST_CASE(StringSubStringDifferentWidth) { |
1383 // Create 1-byte substring from a 1-byte source string. | 1377 // Create 1-byte substring from a 1-byte source string. |
1384 const char* onechars = | 1378 const char* onechars = "\xC3\xB6\xC3\xB1\xC3\xA9"; |
1385 "\xC3\xB6\xC3\xB1\xC3\xA9"; | |
1386 | 1379 |
1387 const String& onestr = String::Handle(String::New(onechars)); | 1380 const String& onestr = String::Handle(String::New(onechars)); |
1388 EXPECT(!onestr.IsNull()); | 1381 EXPECT(!onestr.IsNull()); |
1389 EXPECT(onestr.IsOneByteString()); | 1382 EXPECT(onestr.IsOneByteString()); |
1390 EXPECT(!onestr.IsTwoByteString()); | 1383 EXPECT(!onestr.IsTwoByteString()); |
1391 | 1384 |
1392 const String& onesub = String::Handle(String::SubString(onestr, 0)); | 1385 const String& onesub = String::Handle(String::SubString(onestr, 0)); |
1393 EXPECT(!onesub.IsNull()); | 1386 EXPECT(!onesub.IsNull()); |
1394 EXPECT(onestr.IsOneByteString()); | 1387 EXPECT(onestr.IsOneByteString()); |
1395 EXPECT(!onestr.IsTwoByteString()); | 1388 EXPECT(!onestr.IsTwoByteString()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 "\xC3\x9C\xC3\x9D\xC3\x9E\xC3\x9F" | 1456 "\xC3\x9C\xC3\x9D\xC3\x9E\xC3\x9F" |
1464 "\xC3\xA0\xC3\xA1\xC3\xA2\xC3\xA3" | 1457 "\xC3\xA0\xC3\xA1\xC3\xA2\xC3\xA3" |
1465 "\xC3\xA4\xC3\xA5\xC3\xA6\xC3\xA7" | 1458 "\xC3\xA4\xC3\xA5\xC3\xA6\xC3\xA7" |
1466 "\xC3\xA8\xC3\xA9\xC3\xAA\xC3\xAB" | 1459 "\xC3\xA8\xC3\xA9\xC3\xAA\xC3\xAB" |
1467 "\xC3\xAC\xC3\xAD\xC3\xAE\xC3\xAF" | 1460 "\xC3\xAC\xC3\xAD\xC3\xAE\xC3\xAF" |
1468 "\xC3\xB0\xC3\xB1\xC3\xB2\xC3\xB3" | 1461 "\xC3\xB0\xC3\xB1\xC3\xB2\xC3\xB3" |
1469 "\xC3\xB4\xC3\xB5\xC3\xB6\xC3\xB7" | 1462 "\xC3\xB4\xC3\xB5\xC3\xB6\xC3\xB7" |
1470 "\xC3\xB8\xC3\xB9\xC3\xBA\xC3\xBB" | 1463 "\xC3\xB8\xC3\xB9\xC3\xBA\xC3\xBB" |
1471 "\xC3\xBC\xC3\xBD\xC3\xBE\xC3\xBF"; | 1464 "\xC3\xBC\xC3\xBD\xC3\xBE\xC3\xBF"; |
1472 const uint8_t expected[] = { | 1465 const uint8_t expected[] = { |
1473 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, | 1466 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, |
1474 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, | 1467 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, |
1475 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, | 1468 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, |
1476 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, | 1469 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, |
1477 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, | 1470 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, |
1478 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, | 1471 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, |
1479 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, | 1472 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, |
1480 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, | 1473 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, |
1481 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, | |
1482 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, | |
1483 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, | |
1484 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, | |
1485 }; | 1474 }; |
1486 const String& str = String::Handle(String::New(src)); | 1475 const String& str = String::Handle(String::New(src)); |
1487 EXPECT(str.IsOneByteString()); | 1476 EXPECT(str.IsOneByteString()); |
1488 intptr_t expected_length = sizeof(expected); | 1477 intptr_t expected_length = sizeof(expected); |
1489 EXPECT_EQ(expected_length, str.Length()); | 1478 EXPECT_EQ(expected_length, str.Length()); |
1490 for (int i = 0; i < str.Length(); ++i) { | 1479 for (int i = 0; i < str.Length(); ++i) { |
1491 EXPECT_EQ(expected[i], str.CharAt(i)); | 1480 EXPECT_EQ(expected[i], str.CharAt(i)); |
1492 } | 1481 } |
1493 } | 1482 } |
1494 | 1483 |
1495 // Create a 2-byte string from a UTF-8 encoded string literal. | 1484 // Create a 2-byte string from a UTF-8 encoded string literal. |
1496 { | 1485 { |
1497 const char* src = | 1486 const char* src = |
1498 "\xD7\x92\xD7\x9C\xD7\xA2\xD7\x93" | 1487 "\xD7\x92\xD7\x9C\xD7\xA2\xD7\x93" |
1499 "\xD7\x91\xD7\xA8\xD7\x9B\xD7\x94"; | 1488 "\xD7\x91\xD7\xA8\xD7\x9B\xD7\x94"; |
1500 const uint16_t expected[] = { | 1489 const uint16_t expected[] = {0x5D2, 0x5DC, 0x5E2, 0x5D3, |
1501 0x5D2, 0x5DC, 0x5E2, 0x5D3, | 1490 0x5D1, 0x5E8, 0x5DB, 0x5D4}; |
1502 0x5D1, 0x5E8, 0x5DB, 0x5D4 | |
1503 }; | |
1504 const String& str = String::Handle(String::New(src)); | 1491 const String& str = String::Handle(String::New(src)); |
1505 EXPECT(str.IsTwoByteString()); | 1492 EXPECT(str.IsTwoByteString()); |
1506 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1493 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1507 EXPECT_EQ(expected_size, str.Length()); | 1494 EXPECT_EQ(expected_size, str.Length()); |
1508 for (int i = 0; i < str.Length(); ++i) { | 1495 for (int i = 0; i < str.Length(); ++i) { |
1509 EXPECT_EQ(expected[i], str.CharAt(i)); | 1496 EXPECT_EQ(expected[i], str.CharAt(i)); |
1510 } | 1497 } |
1511 } | 1498 } |
1512 | 1499 |
1513 // Create a BMP 2-byte string from UTF-8 encoded 1- and 2-byte | 1500 // Create a BMP 2-byte string from UTF-8 encoded 1- and 2-byte |
1514 // characters. | 1501 // characters. |
1515 { | 1502 { |
1516 const char* src = | 1503 const char* src = |
1517 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1504 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
1518 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1505 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
1519 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1506 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
1520 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1507 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
1521 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1508 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
1522 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1509 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
1523 "\xEE\x80\x80\xEF\x80\x80"; | 1510 "\xEE\x80\x80\xEF\x80\x80"; |
1524 const intptr_t expected[] = { | 1511 const intptr_t expected[] = { |
1525 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1512 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
1526 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1513 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
1527 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 | 1514 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000}; |
1528 }; | |
1529 const String& str = String::Handle(String::New(src)); | 1515 const String& str = String::Handle(String::New(src)); |
1530 EXPECT(str.IsTwoByteString()); | 1516 EXPECT(str.IsTwoByteString()); |
1531 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1517 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1532 EXPECT_EQ(expected_size, str.Length()); | 1518 EXPECT_EQ(expected_size, str.Length()); |
1533 for (int i = 0; i < str.Length(); ++i) { | 1519 for (int i = 0; i < str.Length(); ++i) { |
1534 EXPECT_EQ(expected[i], str.CharAt(i)); | 1520 EXPECT_EQ(expected[i], str.CharAt(i)); |
1535 } | 1521 } |
1536 } | 1522 } |
1537 | 1523 |
1538 // Create a 2-byte string with supplementary characters from a UTF-8 | 1524 // Create a 2-byte string with supplementary characters from a UTF-8 |
1539 // string literal. | 1525 // string literal. |
1540 { | 1526 { |
1541 const char* src = | 1527 const char* src = |
1542 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" | 1528 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" |
1543 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; | 1529 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; |
1544 const intptr_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, | 1530 const intptr_t expected[] = {0xd835, 0xdc60, 0xd835, 0xdc61, |
1545 0xd835, 0xdc62, 0xd835, 0xdc63 }; | 1531 0xd835, 0xdc62, 0xd835, 0xdc63}; |
1546 const String& str = String::Handle(String::New(src)); | 1532 const String& str = String::Handle(String::New(src)); |
1547 EXPECT(str.IsTwoByteString()); | 1533 EXPECT(str.IsTwoByteString()); |
1548 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); | 1534 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); |
1549 EXPECT_EQ(expected_size, str.Length()); | 1535 EXPECT_EQ(expected_size, str.Length()); |
1550 for (int i = 0; i < str.Length(); ++i) { | 1536 for (int i = 0; i < str.Length(); ++i) { |
1551 EXPECT_EQ(expected[i], str.CharAt(i)); | 1537 EXPECT_EQ(expected[i], str.CharAt(i)); |
1552 } | 1538 } |
1553 } | 1539 } |
1554 | 1540 |
1555 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte | 1541 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte |
1556 // characters. | 1542 // characters. |
1557 { | 1543 { |
1558 const char* src = | 1544 const char* src = |
1559 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" | 1545 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" |
1560 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" | 1546 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" |
1561 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" | 1547 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" |
1562 "\xEC\x80\x80\xED\x80\x80\xEE\x80" | 1548 "\xEC\x80\x80\xED\x80\x80\xEE\x80" |
1563 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" | 1549 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" |
1564 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" | 1550 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" |
1565 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; | 1551 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; |
1566 const intptr_t expected[] = { | 1552 const intptr_t expected[] = { |
1567 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, | 1553 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, |
1568 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, | 1554 0xC000, 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, |
1569 0xD838, 0xDC00, 0xD83c, 0xDC00, | 1555 0xD834, 0xDC00, 0xD838, 0xDC00, 0xD83c, 0xDC00, |
1570 }; | 1556 }; |
1571 const String& str = String::Handle(String::New(src)); | 1557 const String& str = String::Handle(String::New(src)); |
1572 EXPECT(str.IsTwoByteString()); | 1558 EXPECT(str.IsTwoByteString()); |
1573 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1559 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1574 EXPECT_EQ(expected_size, str.Length()); | 1560 EXPECT_EQ(expected_size, str.Length()); |
1575 for (int i = 0; i < str.Length(); ++i) { | 1561 for (int i = 0; i < str.Length(); ++i) { |
1576 EXPECT_EQ(expected[i], str.CharAt(i)); | 1562 EXPECT_EQ(expected[i], str.CharAt(i)); |
1577 } | 1563 } |
1578 } | 1564 } |
1579 | 1565 |
1580 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte | 1566 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte |
1581 // characters. | 1567 // characters. |
1582 { | 1568 { |
1583 const char* src = | 1569 const char* src = |
1584 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1570 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
1585 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1571 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
1586 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1572 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
1587 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1573 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
1588 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1574 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
1589 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1575 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
1590 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" | 1576 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" |
1591 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" | 1577 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" |
1592 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" | 1578 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" |
1593 "\x80\x80"; | 1579 "\x80\x80"; |
1594 const intptr_t expected[] = { | 1580 const intptr_t expected[] = { |
1595 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1581 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, 0x00C0, |
1596 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1582 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, |
1597 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, | 1583 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, |
1598 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, | 1584 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, 0xD83c, 0xDC00, |
1599 0xD83c, 0xDC00, | |
1600 }; | 1585 }; |
1601 const String& str = String::Handle(String::New(src)); | 1586 const String& str = String::Handle(String::New(src)); |
1602 EXPECT(str.IsTwoByteString()); | 1587 EXPECT(str.IsTwoByteString()); |
1603 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1588 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1604 EXPECT_EQ(expected_size, str.Length()); | 1589 EXPECT_EQ(expected_size, str.Length()); |
1605 for (int i = 0; i < str.Length(); ++i) { | 1590 for (int i = 0; i < str.Length(); ++i) { |
1606 EXPECT_EQ(expected[i], str.CharAt(i)); | 1591 EXPECT_EQ(expected[i], str.CharAt(i)); |
1607 } | 1592 } |
1608 } | 1593 } |
1609 } | 1594 } |
(...skipping 18 matching lines...) Expand all Loading... |
1628 EXPECT(twostr.Equals("\xD7\x90\xD7\x91\xD7\x92")); | 1613 EXPECT(twostr.Equals("\xD7\x90\xD7\x91\xD7\x92")); |
1629 EXPECT(!twostr.Equals("\xD7\x90\xD7\x91\xD7\x92\xD7\x93")); | 1614 EXPECT(!twostr.Equals("\xD7\x90\xD7\x91\xD7\x92\xD7\x93")); |
1630 | 1615 |
1631 const char* foursrc = "\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2"; | 1616 const char* foursrc = "\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2"; |
1632 const String& fourstr = String::Handle(String::New(foursrc)); | 1617 const String& fourstr = String::Handle(String::New(foursrc)); |
1633 EXPECT(fourstr.IsTwoByteString()); | 1618 EXPECT(fourstr.IsTwoByteString()); |
1634 EXPECT(!fourstr.Equals("")); | 1619 EXPECT(!fourstr.Equals("")); |
1635 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0")); | 1620 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0")); |
1636 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1")); | 1621 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1")); |
1637 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2")); | 1622 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2")); |
1638 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1" | 1623 EXPECT( |
1639 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3")); | 1624 !fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1" |
| 1625 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3")); |
1640 } | 1626 } |
1641 | 1627 |
1642 | 1628 |
1643 VM_TEST_CASE(StringEqualsUTF32) { | 1629 VM_TEST_CASE(StringEqualsUTF32) { |
1644 const String& empty = String::Handle(String::New("")); | 1630 const String& empty = String::Handle(String::New("")); |
1645 const String& t_str = String::Handle(String::New("t")); | 1631 const String& t_str = String::Handle(String::New("t")); |
1646 const String& th_str = String::Handle(String::New("th")); | 1632 const String& th_str = String::Handle(String::New("th")); |
1647 const int32_t chars[] = {'t', 'h', 'i', 's'}; | 1633 const int32_t chars[] = {'t', 'h', 'i', 's'}; |
1648 EXPECT(!empty.Equals(chars, -1)); | 1634 EXPECT(!empty.Equals(chars, -1)); |
1649 EXPECT(empty.Equals(chars, 0)); | 1635 EXPECT(empty.Equals(chars, 0)); |
1650 EXPECT(!empty.Equals(chars, 1)); | 1636 EXPECT(!empty.Equals(chars, 1)); |
1651 EXPECT(!t_str.Equals(chars, 0)); | 1637 EXPECT(!t_str.Equals(chars, 0)); |
1652 EXPECT(t_str.Equals(chars, 1)); | 1638 EXPECT(t_str.Equals(chars, 1)); |
1653 EXPECT(!t_str.Equals(chars, 2)); | 1639 EXPECT(!t_str.Equals(chars, 2)); |
1654 EXPECT(!th_str.Equals(chars, 1)); | 1640 EXPECT(!th_str.Equals(chars, 1)); |
1655 EXPECT(th_str.Equals(chars, 2)); | 1641 EXPECT(th_str.Equals(chars, 2)); |
1656 EXPECT(!th_str.Equals(chars, 3)); | 1642 EXPECT(!th_str.Equals(chars, 3)); |
1657 } | 1643 } |
1658 | 1644 |
1659 | 1645 |
1660 VM_TEST_CASE(ExternalOneByteString) { | 1646 VM_TEST_CASE(ExternalOneByteString) { |
1661 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 }; | 1647 uint8_t characters[] = {0xF6, 0xF1, 0xE9}; |
1662 intptr_t len = ARRAY_SIZE(characters); | 1648 intptr_t len = ARRAY_SIZE(characters); |
1663 | 1649 |
1664 const String& str = | 1650 const String& str = String::Handle( |
1665 String::Handle( | 1651 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1666 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); | |
1667 EXPECT(!str.IsOneByteString()); | 1652 EXPECT(!str.IsOneByteString()); |
1668 EXPECT(str.IsExternalOneByteString()); | 1653 EXPECT(str.IsExternalOneByteString()); |
1669 EXPECT_EQ(str.Length(), len); | 1654 EXPECT_EQ(str.Length(), len); |
1670 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9")); | 1655 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9")); |
1671 | 1656 |
1672 const String& copy = String::Handle(String::SubString(str, 0, len)); | 1657 const String& copy = String::Handle(String::SubString(str, 0, len)); |
1673 EXPECT(!copy.IsExternalOneByteString()); | 1658 EXPECT(!copy.IsExternalOneByteString()); |
1674 EXPECT(copy.IsOneByteString()); | 1659 EXPECT(copy.IsOneByteString()); |
1675 EXPECT_EQ(len, copy.Length()); | 1660 EXPECT_EQ(len, copy.Length()); |
1676 EXPECT(copy.Equals(str)); | 1661 EXPECT(copy.Equals(str)); |
1677 | 1662 |
1678 const String& concat = String::Handle(String::Concat(str, str)); | 1663 const String& concat = String::Handle(String::Concat(str, str)); |
1679 EXPECT(!concat.IsExternalOneByteString()); | 1664 EXPECT(!concat.IsExternalOneByteString()); |
1680 EXPECT(concat.IsOneByteString()); | 1665 EXPECT(concat.IsOneByteString()); |
1681 EXPECT_EQ(len * 2, concat.Length()); | 1666 EXPECT_EQ(len * 2, concat.Length()); |
1682 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9")); | 1667 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9")); |
1683 | 1668 |
1684 const String& substr = String::Handle(String::SubString(str, 1, 1)); | 1669 const String& substr = String::Handle(String::SubString(str, 1, 1)); |
1685 EXPECT(!substr.IsExternalOneByteString()); | 1670 EXPECT(!substr.IsExternalOneByteString()); |
1686 EXPECT(substr.IsOneByteString()); | 1671 EXPECT(substr.IsOneByteString()); |
1687 EXPECT_EQ(1, substr.Length()); | 1672 EXPECT_EQ(1, substr.Length()); |
1688 EXPECT(substr.Equals("\xC3\xB1")); | 1673 EXPECT(substr.Equals("\xC3\xB1")); |
1689 } | 1674 } |
1690 | 1675 |
1691 | 1676 |
1692 VM_TEST_CASE(EscapeSpecialCharactersOneByteString) { | 1677 VM_TEST_CASE(EscapeSpecialCharactersOneByteString) { |
1693 uint8_t characters[] = | 1678 uint8_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1694 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; | 1679 '\v', '\r', '\\', '$', 'z'}; |
1695 intptr_t len = ARRAY_SIZE(characters); | 1680 intptr_t len = ARRAY_SIZE(characters); |
1696 | 1681 |
1697 const String& str = | 1682 const String& str = |
1698 String::Handle( | 1683 String::Handle(OneByteString::New(characters, len, Heap::kNew)); |
1699 OneByteString::New(characters, len, Heap::kNew)); | |
1700 EXPECT(str.IsOneByteString()); | 1684 EXPECT(str.IsOneByteString()); |
1701 EXPECT_EQ(str.Length(), len); | 1685 EXPECT_EQ(str.Length(), len); |
1702 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); | 1686 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); |
1703 const String& escaped_str = | 1687 const String& escaped_str = |
1704 String::Handle(String::EscapeSpecialCharacters(str)); | 1688 String::Handle(String::EscapeSpecialCharacters(str)); |
1705 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1689 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1706 | 1690 |
1707 const String& escaped_empty_str = | 1691 const String& escaped_empty_str = |
1708 String::Handle(String::EscapeSpecialCharacters(Symbols::Empty())); | 1692 String::Handle(String::EscapeSpecialCharacters(Symbols::Empty())); |
1709 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1693 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1710 } | 1694 } |
1711 | 1695 |
1712 | 1696 |
1713 VM_TEST_CASE(EscapeSpecialCharactersExternalOneByteString) { | 1697 VM_TEST_CASE(EscapeSpecialCharactersExternalOneByteString) { |
1714 uint8_t characters[] = | 1698 uint8_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1715 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; | 1699 '\v', '\r', '\\', '$', 'z'}; |
1716 intptr_t len = ARRAY_SIZE(characters); | 1700 intptr_t len = ARRAY_SIZE(characters); |
1717 | 1701 |
1718 const String& str = | 1702 const String& str = String::Handle( |
1719 String::Handle( | 1703 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1720 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); | |
1721 EXPECT(!str.IsOneByteString()); | 1704 EXPECT(!str.IsOneByteString()); |
1722 EXPECT(str.IsExternalOneByteString()); | 1705 EXPECT(str.IsExternalOneByteString()); |
1723 EXPECT_EQ(str.Length(), len); | 1706 EXPECT_EQ(str.Length(), len); |
1724 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); | 1707 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); |
1725 const String& escaped_str = | 1708 const String& escaped_str = |
1726 String::Handle(String::EscapeSpecialCharacters(str)); | 1709 String::Handle(String::EscapeSpecialCharacters(str)); |
1727 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1710 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1728 | 1711 |
1729 const String& empty_str = | 1712 const String& empty_str = String::Handle( |
1730 String::Handle( | 1713 ExternalOneByteString::New(characters, 0, NULL, NULL, Heap::kNew)); |
1731 ExternalOneByteString::New(characters, 0, NULL, NULL, Heap::kNew)); | |
1732 const String& escaped_empty_str = | 1714 const String& escaped_empty_str = |
1733 String::Handle(String::EscapeSpecialCharacters(empty_str)); | 1715 String::Handle(String::EscapeSpecialCharacters(empty_str)); |
1734 EXPECT_EQ(empty_str.Length(), 0); | 1716 EXPECT_EQ(empty_str.Length(), 0); |
1735 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1717 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1736 } | 1718 } |
1737 | 1719 |
1738 VM_TEST_CASE(EscapeSpecialCharactersTwoByteString) { | 1720 VM_TEST_CASE(EscapeSpecialCharactersTwoByteString) { |
1739 uint16_t characters[] = | 1721 uint16_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1740 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; | 1722 '\v', '\r', '\\', '$', 'z'}; |
1741 intptr_t len = ARRAY_SIZE(characters); | 1723 intptr_t len = ARRAY_SIZE(characters); |
1742 | 1724 |
1743 const String& str = | 1725 const String& str = |
1744 String::Handle(TwoByteString::New(characters, len, Heap::kNew)); | 1726 String::Handle(TwoByteString::New(characters, len, Heap::kNew)); |
1745 EXPECT(str.IsTwoByteString()); | 1727 EXPECT(str.IsTwoByteString()); |
1746 EXPECT_EQ(str.Length(), len); | 1728 EXPECT_EQ(str.Length(), len); |
1747 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); | 1729 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); |
1748 const String& escaped_str = | 1730 const String& escaped_str = |
1749 String::Handle(String::EscapeSpecialCharacters(str)); | 1731 String::Handle(String::EscapeSpecialCharacters(str)); |
1750 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1732 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1751 | 1733 |
1752 const String& empty_str = | 1734 const String& empty_str = |
1753 String::Handle(TwoByteString::New(static_cast<intptr_t>(0), Heap::kNew)); | 1735 String::Handle(TwoByteString::New(static_cast<intptr_t>(0), Heap::kNew)); |
1754 const String& escaped_empty_str = | 1736 const String& escaped_empty_str = |
1755 String::Handle(String::EscapeSpecialCharacters(empty_str)); | 1737 String::Handle(String::EscapeSpecialCharacters(empty_str)); |
1756 EXPECT_EQ(empty_str.Length(), 0); | 1738 EXPECT_EQ(empty_str.Length(), 0); |
1757 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1739 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1758 } | 1740 } |
1759 | 1741 |
1760 | 1742 |
1761 VM_TEST_CASE(EscapeSpecialCharactersExternalTwoByteString) { | 1743 VM_TEST_CASE(EscapeSpecialCharactersExternalTwoByteString) { |
1762 uint16_t characters[] = | 1744 uint16_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1763 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; | 1745 '\v', '\r', '\\', '$', 'z'}; |
1764 intptr_t len = ARRAY_SIZE(characters); | 1746 intptr_t len = ARRAY_SIZE(characters); |
1765 | 1747 |
1766 const String& str = | 1748 const String& str = String::Handle( |
1767 String::Handle( | 1749 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1768 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); | |
1769 EXPECT(str.IsExternalTwoByteString()); | 1750 EXPECT(str.IsExternalTwoByteString()); |
1770 EXPECT_EQ(str.Length(), len); | 1751 EXPECT_EQ(str.Length(), len); |
1771 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); | 1752 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); |
1772 const String& escaped_str = | 1753 const String& escaped_str = |
1773 String::Handle(String::EscapeSpecialCharacters(str)); | 1754 String::Handle(String::EscapeSpecialCharacters(str)); |
1774 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1755 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1775 | 1756 |
1776 const String& empty_str = | 1757 const String& empty_str = String::Handle( |
1777 String::Handle( | 1758 ExternalTwoByteString::New(characters, 0, NULL, NULL, Heap::kNew)); |
1778 ExternalTwoByteString::New(characters, 0, NULL, NULL, Heap::kNew)); | |
1779 const String& escaped_empty_str = | 1759 const String& escaped_empty_str = |
1780 String::Handle(String::EscapeSpecialCharacters(empty_str)); | 1760 String::Handle(String::EscapeSpecialCharacters(empty_str)); |
1781 EXPECT_EQ(empty_str.Length(), 0); | 1761 EXPECT_EQ(empty_str.Length(), 0); |
1782 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1762 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1783 } | 1763 } |
1784 | 1764 |
1785 | 1765 |
1786 VM_TEST_CASE(ExternalTwoByteString) { | 1766 VM_TEST_CASE(ExternalTwoByteString) { |
1787 uint16_t characters[] = { 0x1E6B, 0x1E85, 0x1E53 }; | 1767 uint16_t characters[] = {0x1E6B, 0x1E85, 0x1E53}; |
1788 intptr_t len = ARRAY_SIZE(characters); | 1768 intptr_t len = ARRAY_SIZE(characters); |
1789 | 1769 |
1790 const String& str = | 1770 const String& str = String::Handle( |
1791 String::Handle( | 1771 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1792 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); | |
1793 EXPECT(!str.IsTwoByteString()); | 1772 EXPECT(!str.IsTwoByteString()); |
1794 EXPECT(str.IsExternalTwoByteString()); | 1773 EXPECT(str.IsExternalTwoByteString()); |
1795 EXPECT_EQ(str.Length(), len); | 1774 EXPECT_EQ(str.Length(), len); |
1796 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); | 1775 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); |
1797 | 1776 |
1798 const String& copy = String::Handle(String::SubString(str, 0, len)); | 1777 const String& copy = String::Handle(String::SubString(str, 0, len)); |
1799 EXPECT(!copy.IsExternalTwoByteString()); | 1778 EXPECT(!copy.IsExternalTwoByteString()); |
1800 EXPECT(copy.IsTwoByteString()); | 1779 EXPECT(copy.IsTwoByteString()); |
1801 EXPECT_EQ(len, copy.Length()); | 1780 EXPECT_EQ(len, copy.Length()); |
1802 EXPECT(copy.Equals(str)); | 1781 EXPECT(copy.Equals(str)); |
1803 | 1782 |
1804 const String& concat = String::Handle(String::Concat(str, str)); | 1783 const String& concat = String::Handle(String::Concat(str, str)); |
1805 EXPECT(!concat.IsExternalTwoByteString()); | 1784 EXPECT(!concat.IsExternalTwoByteString()); |
1806 EXPECT(concat.IsTwoByteString()); | 1785 EXPECT(concat.IsTwoByteString()); |
1807 EXPECT_EQ(len * 2, concat.Length()); | 1786 EXPECT_EQ(len * 2, concat.Length()); |
1808 EXPECT(concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93" | 1787 EXPECT( |
1809 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); | 1788 concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93" |
| 1789 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); |
1810 | 1790 |
1811 const String& substr = String::Handle(String::SubString(str, 1, 1)); | 1791 const String& substr = String::Handle(String::SubString(str, 1, 1)); |
1812 EXPECT(!substr.IsExternalTwoByteString()); | 1792 EXPECT(!substr.IsExternalTwoByteString()); |
1813 EXPECT(substr.IsTwoByteString()); | 1793 EXPECT(substr.IsTwoByteString()); |
1814 EXPECT_EQ(1, substr.Length()); | 1794 EXPECT_EQ(1, substr.Length()); |
1815 EXPECT(substr.Equals("\xE1\xBA\x85")); | 1795 EXPECT(substr.Equals("\xE1\xBA\x85")); |
1816 } | 1796 } |
1817 | 1797 |
1818 | 1798 |
1819 VM_TEST_CASE(Symbol) { | 1799 VM_TEST_CASE(Symbol) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 EXPECT_EQ(nine.raw(), Symbols::New(thread, "Neun")); | 1840 EXPECT_EQ(nine.raw(), Symbols::New(thread, "Neun")); |
1861 EXPECT_EQ(ten.raw(), Symbols::New(thread, "Zehn")); | 1841 EXPECT_EQ(ten.raw(), Symbols::New(thread, "Zehn")); |
1862 | 1842 |
1863 // Symbols from Strings. | 1843 // Symbols from Strings. |
1864 eins = String::New("Eins"); | 1844 eins = String::New("Eins"); |
1865 EXPECT(!eins.IsSymbol()); | 1845 EXPECT(!eins.IsSymbol()); |
1866 String& ein_symbol = String::Handle(Symbols::New(thread, eins)); | 1846 String& ein_symbol = String::Handle(Symbols::New(thread, eins)); |
1867 EXPECT_EQ(one.raw(), ein_symbol.raw()); | 1847 EXPECT_EQ(one.raw(), ein_symbol.raw()); |
1868 EXPECT(one.raw() != eins.raw()); | 1848 EXPECT(one.raw() != eins.raw()); |
1869 | 1849 |
1870 uint16_t char16[] = { 'E', 'l', 'f' }; | 1850 uint16_t char16[] = {'E', 'l', 'f'}; |
1871 String& elf1 = String::Handle(Symbols::FromUTF16(thread, char16, 3)); | 1851 String& elf1 = String::Handle(Symbols::FromUTF16(thread, char16, 3)); |
1872 int32_t char32[] = { 'E', 'l', 'f' }; | 1852 int32_t char32[] = {'E', 'l', 'f'}; |
1873 String& elf2 = String::Handle(Symbols::FromUTF32(thread, char32, 3)); | 1853 String& elf2 = String::Handle(Symbols::FromUTF32(thread, char32, 3)); |
1874 EXPECT(elf1.IsSymbol()); | 1854 EXPECT(elf1.IsSymbol()); |
1875 EXPECT(elf2.IsSymbol()); | 1855 EXPECT(elf2.IsSymbol()); |
1876 EXPECT_EQ(elf1.raw(), Symbols::New(thread, "Elf")); | 1856 EXPECT_EQ(elf1.raw(), Symbols::New(thread, "Elf")); |
1877 EXPECT_EQ(elf2.raw(), Symbols::New(thread, "Elf")); | 1857 EXPECT_EQ(elf2.raw(), Symbols::New(thread, "Elf")); |
1878 } | 1858 } |
1879 | 1859 |
1880 | 1860 |
1881 VM_TEST_CASE(SymbolUnicode) { | 1861 VM_TEST_CASE(SymbolUnicode) { |
1882 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. | 1862 uint16_t monkey_utf16[] = {0xd83d, 0xdc35}; // Unicode Monkey Face. |
1883 String& monkey = String::Handle(Symbols::FromUTF16(thread, monkey_utf16, 2)); | 1863 String& monkey = String::Handle(Symbols::FromUTF16(thread, monkey_utf16, 2)); |
1884 EXPECT(monkey.IsSymbol()); | 1864 EXPECT(monkey.IsSymbol()); |
1885 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; | 1865 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; |
1886 EXPECT_EQ(monkey.raw(), Symbols::New(thread, monkey_utf8)); | 1866 EXPECT_EQ(monkey.raw(), Symbols::New(thread, monkey_utf8)); |
1887 | 1867 |
1888 int32_t kMonkeyFace = 0x1f435; | 1868 int32_t kMonkeyFace = 0x1f435; |
1889 String& monkey2 = String::Handle(Symbols::FromCharCode(thread, kMonkeyFace)); | 1869 String& monkey2 = String::Handle(Symbols::FromCharCode(thread, kMonkeyFace)); |
1890 EXPECT_EQ(monkey.raw(), monkey2.raw()); | 1870 EXPECT_EQ(monkey.raw(), monkey2.raw()); |
1891 | 1871 |
1892 // Unicode cat face with tears of joy. | 1872 // Unicode cat face with tears of joy. |
1893 int32_t kCatFaceWithTearsOfJoy = 0x1f639; | 1873 int32_t kCatFaceWithTearsOfJoy = 0x1f639; |
1894 String& cat = String::Handle(Symbols::FromCharCode(thread, | 1874 String& cat = |
1895 kCatFaceWithTearsOfJoy)); | 1875 String::Handle(Symbols::FromCharCode(thread, kCatFaceWithTearsOfJoy)); |
1896 | 1876 |
1897 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; | 1877 uint16_t cat_utf16[] = {0xd83d, 0xde39}; |
1898 String& cat2 = String::Handle(Symbols::FromUTF16(thread, cat_utf16, 2)); | 1878 String& cat2 = String::Handle(Symbols::FromUTF16(thread, cat_utf16, 2)); |
1899 EXPECT(cat2.IsSymbol()); | 1879 EXPECT(cat2.IsSymbol()); |
1900 EXPECT_EQ(cat2.raw(), cat.raw()); | 1880 EXPECT_EQ(cat2.raw(), cat.raw()); |
1901 } | 1881 } |
1902 | 1882 |
1903 | 1883 |
1904 VM_TEST_CASE(Bool) { | 1884 VM_TEST_CASE(Bool) { |
1905 EXPECT(Bool::True().value()); | 1885 EXPECT(Bool::True().value()); |
1906 EXPECT(!Bool::False().value()); | 1886 EXPECT(!Bool::False().value()); |
1907 } | 1887 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 | 1927 |
1948 array.MakeImmutable(); | 1928 array.MakeImmutable(); |
1949 Object& obj = Object::Handle(array.raw()); | 1929 Object& obj = Object::Handle(array.raw()); |
1950 EXPECT(obj.IsArray()); | 1930 EXPECT(obj.IsArray()); |
1951 } | 1931 } |
1952 | 1932 |
1953 | 1933 |
1954 static void TestIllegalArrayLength(intptr_t length) { | 1934 static void TestIllegalArrayLength(intptr_t length) { |
1955 char buffer[1024]; | 1935 char buffer[1024]; |
1956 OS::SNPrint(buffer, sizeof(buffer), | 1936 OS::SNPrint(buffer, sizeof(buffer), |
1957 "main() {\n" | 1937 "main() {\n" |
1958 " new List(%" Pd ");\n" | 1938 " new List(%" Pd |
1959 "}\n", | 1939 ");\n" |
1960 length); | 1940 "}\n", |
| 1941 length); |
1961 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1942 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
1962 EXPECT_VALID(lib); | 1943 EXPECT_VALID(lib); |
1963 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1944 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1964 OS::SNPrint(buffer, sizeof(buffer), | 1945 OS::SNPrint(buffer, sizeof(buffer), |
1965 "Unhandled exception:\n" | 1946 "Unhandled exception:\n" |
1966 "RangeError (length): Invalid value: " | 1947 "RangeError (length): Invalid value: " |
1967 "Not in range 0..%" Pd ", inclusive: %" Pd, | 1948 "Not in range 0..%" Pd ", inclusive: %" Pd, |
1968 Array::kMaxElements, length); | 1949 Array::kMaxElements, length); |
1969 EXPECT_ERROR(result, buffer); | 1950 EXPECT_ERROR(result, buffer); |
1970 } | 1951 } |
1971 | 1952 |
1972 | 1953 |
1973 TEST_CASE(ArrayLengthNegativeOne) { TestIllegalArrayLength(-1); } | 1954 TEST_CASE(ArrayLengthNegativeOne) { |
1974 TEST_CASE(ArrayLengthSmiMin) { TestIllegalArrayLength(kSmiMin); } | 1955 TestIllegalArrayLength(-1); |
| 1956 } |
| 1957 TEST_CASE(ArrayLengthSmiMin) { |
| 1958 TestIllegalArrayLength(kSmiMin); |
| 1959 } |
1975 TEST_CASE(ArrayLengthOneTooMany) { | 1960 TEST_CASE(ArrayLengthOneTooMany) { |
1976 const intptr_t kOneTooMany = Array::kMaxElements + 1; | 1961 const intptr_t kOneTooMany = Array::kMaxElements + 1; |
1977 ASSERT(kOneTooMany >= 0); | 1962 ASSERT(kOneTooMany >= 0); |
1978 TestIllegalArrayLength(kOneTooMany); | 1963 TestIllegalArrayLength(kOneTooMany); |
1979 } | 1964 } |
1980 | 1965 |
1981 | 1966 |
1982 TEST_CASE(ArrayLengthMaxElements) { | 1967 TEST_CASE(ArrayLengthMaxElements) { |
1983 char buffer[1024]; | 1968 char buffer[1024]; |
1984 OS::SNPrint(buffer, sizeof(buffer), | 1969 OS::SNPrint(buffer, sizeof(buffer), |
1985 "main() {\n" | 1970 "main() {\n" |
1986 " return new List(%" Pd ");\n" | 1971 " return new List(%" Pd |
1987 "}\n", | 1972 ");\n" |
1988 Array::kMaxElements); | 1973 "}\n", |
| 1974 Array::kMaxElements); |
1989 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1975 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
1990 EXPECT_VALID(lib); | 1976 EXPECT_VALID(lib); |
1991 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1977 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1992 if (Dart_IsError(result)) { | 1978 if (Dart_IsError(result)) { |
1993 EXPECT_ERROR(result, "Out of Memory"); | 1979 EXPECT_ERROR(result, "Out of Memory"); |
1994 } else { | 1980 } else { |
1995 const intptr_t kExpected = Array::kMaxElements; | 1981 const intptr_t kExpected = Array::kMaxElements; |
1996 intptr_t actual = 0; | 1982 intptr_t actual = 0; |
1997 EXPECT_VALID(Dart_ListLength(result, &actual)); | 1983 EXPECT_VALID(Dart_ListLength(result, &actual)); |
1998 EXPECT_EQ(kExpected, actual); | 1984 EXPECT_EQ(kExpected, actual); |
1999 } | 1985 } |
2000 } | 1986 } |
2001 | 1987 |
2002 | 1988 |
2003 static void TestIllegalTypedDataLength(const char* class_name, | 1989 static void TestIllegalTypedDataLength(const char* class_name, |
2004 intptr_t length) { | 1990 intptr_t length) { |
2005 char buffer[1024]; | 1991 char buffer[1024]; |
2006 OS::SNPrint(buffer, sizeof(buffer), | 1992 OS::SNPrint(buffer, sizeof(buffer), |
2007 "import 'dart:typed_data';\n" | 1993 "import 'dart:typed_data';\n" |
2008 "main() {\n" | 1994 "main() {\n" |
2009 " new %s(%" Pd ");\n" | 1995 " new %s(%" Pd |
2010 "}\n", | 1996 ");\n" |
2011 class_name, length); | 1997 "}\n", |
| 1998 class_name, length); |
2012 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1999 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
2013 EXPECT_VALID(lib); | 2000 EXPECT_VALID(lib); |
2014 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2001 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2015 OS::SNPrint(buffer, sizeof(buffer), "%" Pd, length); | 2002 OS::SNPrint(buffer, sizeof(buffer), "%" Pd, length); |
2016 EXPECT_ERROR(result, "Invalid argument(s)"); | 2003 EXPECT_ERROR(result, "Invalid argument(s)"); |
2017 EXPECT_ERROR(result, buffer); | 2004 EXPECT_ERROR(result, buffer); |
2018 } | 2005 } |
2019 | 2006 |
2020 | 2007 |
2021 TEST_CASE(Int8ListLengthNegativeOne) { | 2008 TEST_CASE(Int8ListLengthNegativeOne) { |
2022 TestIllegalTypedDataLength("Int8List", -1); | 2009 TestIllegalTypedDataLength("Int8List", -1); |
2023 } | 2010 } |
2024 TEST_CASE(Int8ListLengthSmiMin) { | 2011 TEST_CASE(Int8ListLengthSmiMin) { |
2025 TestIllegalTypedDataLength("Int8List", kSmiMin); | 2012 TestIllegalTypedDataLength("Int8List", kSmiMin); |
2026 } | 2013 } |
2027 TEST_CASE(Int8ListLengthOneTooMany) { | 2014 TEST_CASE(Int8ListLengthOneTooMany) { |
2028 const intptr_t kOneTooMany = | 2015 const intptr_t kOneTooMany = |
2029 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; | 2016 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; |
2030 ASSERT(kOneTooMany >= 0); | 2017 ASSERT(kOneTooMany >= 0); |
2031 TestIllegalTypedDataLength("Int8List", kOneTooMany); | 2018 TestIllegalTypedDataLength("Int8List", kOneTooMany); |
2032 } | 2019 } |
2033 | 2020 |
2034 | 2021 |
2035 TEST_CASE(Int8ListLengthMaxElements) { | 2022 TEST_CASE(Int8ListLengthMaxElements) { |
2036 const intptr_t max_elements = TypedData::MaxElements(kTypedDataInt8ArrayCid); | 2023 const intptr_t max_elements = TypedData::MaxElements(kTypedDataInt8ArrayCid); |
2037 char buffer[1024]; | 2024 char buffer[1024]; |
2038 OS::SNPrint(buffer, sizeof(buffer), | 2025 OS::SNPrint(buffer, sizeof(buffer), |
2039 "import 'dart:typed_data';\n" | 2026 "import 'dart:typed_data';\n" |
2040 "main() {\n" | 2027 "main() {\n" |
2041 " return new Int8List(%" Pd ");\n" | 2028 " return new Int8List(%" Pd |
2042 "}\n", | 2029 ");\n" |
2043 max_elements); | 2030 "}\n", |
| 2031 max_elements); |
2044 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 2032 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
2045 EXPECT_VALID(lib); | 2033 EXPECT_VALID(lib); |
2046 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2034 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2047 if (Dart_IsError(result)) { | 2035 if (Dart_IsError(result)) { |
2048 EXPECT_ERROR(result, "Out of Memory"); | 2036 EXPECT_ERROR(result, "Out of Memory"); |
2049 } else { | 2037 } else { |
2050 intptr_t actual = 0; | 2038 intptr_t actual = 0; |
2051 EXPECT_VALID(Dart_ListLength(result, &actual)); | 2039 EXPECT_VALID(Dart_ListLength(result, &actual)); |
2052 EXPECT_EQ(max_elements, actual); | 2040 EXPECT_EQ(max_elements, actual); |
2053 } | 2041 } |
2054 } | 2042 } |
2055 | 2043 |
2056 | 2044 |
2057 VM_TEST_CASE(StringCodePointIterator) { | 2045 VM_TEST_CASE(StringCodePointIterator) { |
2058 const String& str0 = String::Handle(String::New("")); | 2046 const String& str0 = String::Handle(String::New("")); |
2059 String::CodePointIterator it0(str0); | 2047 String::CodePointIterator it0(str0); |
2060 EXPECT(!it0.Next()); | 2048 EXPECT(!it0.Next()); |
2061 | 2049 |
2062 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); | 2050 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); |
2063 String::CodePointIterator it1(str1); | 2051 String::CodePointIterator it1(str1); |
2064 EXPECT(it1.Next()); | 2052 EXPECT(it1.Next()); |
2065 EXPECT_EQ(' ', it1.Current()); | 2053 EXPECT_EQ(' ', it1.Current()); |
2066 EXPECT(it1.Next()); | 2054 EXPECT(it1.Next()); |
2067 EXPECT_EQ(0xE7, it1.Current()); | 2055 EXPECT_EQ(0xE7, it1.Current()); |
2068 EXPECT(it1.Next()); | 2056 EXPECT(it1.Next()); |
2069 EXPECT_EQ(' ', it1.Current()); | 2057 EXPECT_EQ(' ', it1.Current()); |
2070 EXPECT(!it1.Next()); | 2058 EXPECT(!it1.Next()); |
2071 | 2059 |
2072 const String& str2 = String::Handle(String::New("\xD7\x92\xD7\x9C" | 2060 const String& str2 = |
2073 "\xD7\xA2\xD7\x93" | 2061 String::Handle(String::New("\xD7\x92\xD7\x9C" |
2074 "\xD7\x91\xD7\xA8" | 2062 "\xD7\xA2\xD7\x93" |
2075 "\xD7\x9B\xD7\x94")); | 2063 "\xD7\x91\xD7\xA8" |
| 2064 "\xD7\x9B\xD7\x94")); |
2076 String::CodePointIterator it2(str2); | 2065 String::CodePointIterator it2(str2); |
2077 EXPECT(it2.Next()); | 2066 EXPECT(it2.Next()); |
2078 EXPECT_EQ(0x5D2, it2.Current()); | 2067 EXPECT_EQ(0x5D2, it2.Current()); |
2079 EXPECT(it2.Next()); | 2068 EXPECT(it2.Next()); |
2080 EXPECT_EQ(0x5DC, it2.Current()); | 2069 EXPECT_EQ(0x5DC, it2.Current()); |
2081 EXPECT(it2.Next()); | 2070 EXPECT(it2.Next()); |
2082 EXPECT_EQ(0x5E2, it2.Current()); | 2071 EXPECT_EQ(0x5E2, it2.Current()); |
2083 EXPECT(it2.Next()); | 2072 EXPECT(it2.Next()); |
2084 EXPECT_EQ(0x5D3, it2.Current()); | 2073 EXPECT_EQ(0x5D3, it2.Current()); |
2085 EXPECT(it2.Next()); | 2074 EXPECT(it2.Next()); |
2086 EXPECT_EQ(0x5D1, it2.Current()); | 2075 EXPECT_EQ(0x5D1, it2.Current()); |
2087 EXPECT(it2.Next()); | 2076 EXPECT(it2.Next()); |
2088 EXPECT_EQ(0x5E8, it2.Current()); | 2077 EXPECT_EQ(0x5E8, it2.Current()); |
2089 EXPECT(it2.Next()); | 2078 EXPECT(it2.Next()); |
2090 EXPECT_EQ(0x5DB, it2.Current()); | 2079 EXPECT_EQ(0x5DB, it2.Current()); |
2091 EXPECT(it2.Next()); | 2080 EXPECT(it2.Next()); |
2092 EXPECT_EQ(0x5D4, it2.Current()); | 2081 EXPECT_EQ(0x5D4, it2.Current()); |
2093 EXPECT(!it2.Next()); | 2082 EXPECT(!it2.Next()); |
2094 | 2083 |
2095 const String& str3 = String::Handle(String::New("\xF0\x9D\x91\xA0" | 2084 const String& str3 = |
2096 "\xF0\x9D\x91\xA1" | 2085 String::Handle(String::New("\xF0\x9D\x91\xA0" |
2097 "\xF0\x9D\x91\xA2" | 2086 "\xF0\x9D\x91\xA1" |
2098 "\xF0\x9D\x91\xA3")); | 2087 "\xF0\x9D\x91\xA2" |
| 2088 "\xF0\x9D\x91\xA3")); |
2099 String::CodePointIterator it3(str3); | 2089 String::CodePointIterator it3(str3); |
2100 EXPECT(it3.Next()); | 2090 EXPECT(it3.Next()); |
2101 EXPECT_EQ(0x1D460, it3.Current()); | 2091 EXPECT_EQ(0x1D460, it3.Current()); |
2102 EXPECT(it3.Next()); | 2092 EXPECT(it3.Next()); |
2103 EXPECT_EQ(0x1D461, it3.Current()); | 2093 EXPECT_EQ(0x1D461, it3.Current()); |
2104 EXPECT(it3.Next()); | 2094 EXPECT(it3.Next()); |
2105 EXPECT_EQ(0x1D462, it3.Current()); | 2095 EXPECT_EQ(0x1D462, it3.Current()); |
2106 EXPECT(it3.Next()); | 2096 EXPECT(it3.Next()); |
2107 EXPECT_EQ(0x1D463, it3.Current()); | 2097 EXPECT_EQ(0x1D463, it3.Current()); |
2108 EXPECT(!it3.Next()); | 2098 EXPECT(!it3.Next()); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2242 EXPECT_EQ(1, new_array.Length()); | 2232 EXPECT_EQ(1, new_array.Length()); |
2243 heap->CollectAllGarbage(); | 2233 heap->CollectAllGarbage(); |
2244 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld); | 2234 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld); |
2245 // Page should shrink. | 2235 // Page should shrink. |
2246 EXPECT_LT(capacity_after, capacity_before); | 2236 EXPECT_LT(capacity_after, capacity_before); |
2247 EXPECT_EQ(1, new_array.Length()); | 2237 EXPECT_EQ(1, new_array.Length()); |
2248 } | 2238 } |
2249 | 2239 |
2250 | 2240 |
2251 VM_TEST_CASE(InternalTypedData) { | 2241 VM_TEST_CASE(InternalTypedData) { |
2252 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 }; | 2242 uint8_t data[] = {253, 254, 255, 0, 1, 2, 3, 4}; |
2253 intptr_t data_length = ARRAY_SIZE(data); | 2243 intptr_t data_length = ARRAY_SIZE(data); |
2254 | 2244 |
2255 const TypedData& int8_array = | 2245 const TypedData& int8_array = |
2256 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, data_length)); | 2246 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, data_length)); |
2257 EXPECT(!int8_array.IsNull()); | 2247 EXPECT(!int8_array.IsNull()); |
2258 EXPECT_EQ(data_length, int8_array.Length()); | 2248 EXPECT_EQ(data_length, int8_array.Length()); |
2259 for (intptr_t i = 0; i < data_length; ++i) { | 2249 for (intptr_t i = 0; i < data_length; ++i) { |
2260 int8_array.SetInt8(i, data[i]); | 2250 int8_array.SetInt8(i, data[i]); |
2261 } | 2251 } |
2262 | 2252 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 for (intptr_t i = 0; i < data_length; ++i) { | 2288 for (intptr_t i = 0; i < data_length; ++i) { |
2299 int8_array.SetInt8(i, 123 + i); | 2289 int8_array.SetInt8(i, 123 + i); |
2300 } | 2290 } |
2301 for (intptr_t i = 0; i < data_length; ++i) { | 2291 for (intptr_t i = 0; i < data_length; ++i) { |
2302 EXPECT(int8_array.GetInt8(i) != int8_array2.GetInt8(i)); | 2292 EXPECT(int8_array.GetInt8(i) != int8_array2.GetInt8(i)); |
2303 } | 2293 } |
2304 } | 2294 } |
2305 | 2295 |
2306 | 2296 |
2307 VM_TEST_CASE(ExternalTypedData) { | 2297 VM_TEST_CASE(ExternalTypedData) { |
2308 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 }; | 2298 uint8_t data[] = {253, 254, 255, 0, 1, 2, 3, 4}; |
2309 intptr_t data_length = ARRAY_SIZE(data); | 2299 intptr_t data_length = ARRAY_SIZE(data); |
2310 | 2300 |
2311 const ExternalTypedData& int8_array = | 2301 const ExternalTypedData& int8_array = |
2312 ExternalTypedData::Handle( | 2302 ExternalTypedData::Handle(ExternalTypedData::New( |
2313 ExternalTypedData::New(kExternalTypedDataInt8ArrayCid, | 2303 kExternalTypedDataInt8ArrayCid, data, data_length)); |
2314 data, | |
2315 data_length)); | |
2316 EXPECT(!int8_array.IsNull()); | 2304 EXPECT(!int8_array.IsNull()); |
2317 EXPECT_EQ(data_length, int8_array.Length()); | 2305 EXPECT_EQ(data_length, int8_array.Length()); |
2318 | 2306 |
2319 const ExternalTypedData& uint8_array = | 2307 const ExternalTypedData& uint8_array = |
2320 ExternalTypedData::Handle( | 2308 ExternalTypedData::Handle(ExternalTypedData::New( |
2321 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, | 2309 kExternalTypedDataUint8ArrayCid, data, data_length)); |
2322 data, | |
2323 data_length)); | |
2324 EXPECT(!uint8_array.IsNull()); | 2310 EXPECT(!uint8_array.IsNull()); |
2325 EXPECT_EQ(data_length, uint8_array.Length()); | 2311 EXPECT_EQ(data_length, uint8_array.Length()); |
2326 | 2312 |
2327 const ExternalTypedData& uint8_clamped_array = | 2313 const ExternalTypedData& uint8_clamped_array = |
2328 ExternalTypedData::Handle( | 2314 ExternalTypedData::Handle(ExternalTypedData::New( |
2329 ExternalTypedData::New(kExternalTypedDataUint8ClampedArrayCid, | 2315 kExternalTypedDataUint8ClampedArrayCid, data, data_length)); |
2330 data, | |
2331 data_length)); | |
2332 EXPECT(!uint8_clamped_array.IsNull()); | 2316 EXPECT(!uint8_clamped_array.IsNull()); |
2333 EXPECT_EQ(data_length, uint8_clamped_array.Length()); | 2317 EXPECT_EQ(data_length, uint8_clamped_array.Length()); |
2334 | 2318 |
2335 EXPECT_EQ(-3, int8_array.GetInt8(0)); | 2319 EXPECT_EQ(-3, int8_array.GetInt8(0)); |
2336 EXPECT_EQ(253, uint8_array.GetUint8(0)); | 2320 EXPECT_EQ(253, uint8_array.GetUint8(0)); |
2337 EXPECT_EQ(253, uint8_clamped_array.GetUint8(0)); | 2321 EXPECT_EQ(253, uint8_clamped_array.GetUint8(0)); |
2338 | 2322 |
2339 EXPECT_EQ(-2, int8_array.GetInt8(1)); | 2323 EXPECT_EQ(-2, int8_array.GetInt8(1)); |
2340 EXPECT_EQ(254, uint8_array.GetUint8(1)); | 2324 EXPECT_EQ(254, uint8_array.GetUint8(1)); |
2341 EXPECT_EQ(254, uint8_clamped_array.GetUint8(1)); | 2325 EXPECT_EQ(254, uint8_clamped_array.GetUint8(1)); |
2342 | 2326 |
2343 EXPECT_EQ(-1, int8_array.GetInt8(2)); | 2327 EXPECT_EQ(-1, int8_array.GetInt8(2)); |
2344 EXPECT_EQ(255, uint8_array.GetUint8(2)); | 2328 EXPECT_EQ(255, uint8_array.GetUint8(2)); |
2345 EXPECT_EQ(255, uint8_clamped_array.GetUint8(2)); | 2329 EXPECT_EQ(255, uint8_clamped_array.GetUint8(2)); |
2346 | 2330 |
2347 EXPECT_EQ(0, int8_array.GetInt8(3)); | 2331 EXPECT_EQ(0, int8_array.GetInt8(3)); |
2348 EXPECT_EQ(0, uint8_array.GetUint8(3)); | 2332 EXPECT_EQ(0, uint8_array.GetUint8(3)); |
2349 EXPECT_EQ(0, uint8_clamped_array.GetUint8(3)); | 2333 EXPECT_EQ(0, uint8_clamped_array.GetUint8(3)); |
2350 | 2334 |
2351 EXPECT_EQ(1, int8_array.GetInt8(4)); | 2335 EXPECT_EQ(1, int8_array.GetInt8(4)); |
2352 EXPECT_EQ(1, uint8_array.GetUint8(4)); | 2336 EXPECT_EQ(1, uint8_array.GetUint8(4)); |
2353 EXPECT_EQ(1, uint8_clamped_array.GetUint8(4)); | 2337 EXPECT_EQ(1, uint8_clamped_array.GetUint8(4)); |
2354 | 2338 |
2355 EXPECT_EQ(2, int8_array.GetInt8(5)); | 2339 EXPECT_EQ(2, int8_array.GetInt8(5)); |
2356 EXPECT_EQ(2, uint8_array.GetUint8(5)); | 2340 EXPECT_EQ(2, uint8_array.GetUint8(5)); |
2357 EXPECT_EQ(2, uint8_clamped_array.GetUint8(5)); | 2341 EXPECT_EQ(2, uint8_clamped_array.GetUint8(5)); |
2358 | 2342 |
2359 for (intptr_t i = 0 ; i < int8_array.Length(); ++i) { | 2343 for (intptr_t i = 0; i < int8_array.Length(); ++i) { |
2360 EXPECT_EQ(int8_array.GetUint8(i), uint8_array.GetUint8(i)); | 2344 EXPECT_EQ(int8_array.GetUint8(i), uint8_array.GetUint8(i)); |
2361 } | 2345 } |
2362 | 2346 |
2363 int8_array.SetInt8(2, -123); | 2347 int8_array.SetInt8(2, -123); |
2364 uint8_array.SetUint8(0, 123); | 2348 uint8_array.SetUint8(0, 123); |
2365 for (intptr_t i = 0 ; i < int8_array.Length(); ++i) { | 2349 for (intptr_t i = 0; i < int8_array.Length(); ++i) { |
2366 EXPECT_EQ(int8_array.GetInt8(i), uint8_array.GetInt8(i)); | 2350 EXPECT_EQ(int8_array.GetInt8(i), uint8_array.GetInt8(i)); |
2367 } | 2351 } |
2368 | 2352 |
2369 uint8_clamped_array.SetUint8(0, 123); | 2353 uint8_clamped_array.SetUint8(0, 123); |
2370 for (intptr_t i = 0 ; i < int8_array.Length(); ++i) { | 2354 for (intptr_t i = 0; i < int8_array.Length(); ++i) { |
2371 EXPECT_EQ(int8_array.GetUint8(i), uint8_clamped_array.GetUint8(i)); | 2355 EXPECT_EQ(int8_array.GetUint8(i), uint8_clamped_array.GetUint8(i)); |
2372 } | 2356 } |
2373 } | 2357 } |
2374 | 2358 |
2375 | 2359 |
2376 TEST_CASE(Script) { | 2360 TEST_CASE(Script) { |
2377 const char* url_chars = "builtin:test-case"; | 2361 const char* url_chars = "builtin:test-case"; |
2378 const char* source_chars = "This will not compile."; | 2362 const char* source_chars = "This will not compile."; |
2379 const String& url = String::Handle(String::New(url_chars)); | 2363 const String& url = String::Handle(String::New(url_chars)); |
2380 const String& source = String::Handle(String::New(source_chars)); | 2364 const String& source = String::Handle(String::New(source_chars)); |
2381 const Script& script = Script::Handle(Script::New(url, | 2365 const Script& script = |
2382 source, | 2366 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
2383 RawScript::kScriptTag)); | |
2384 EXPECT(!script.IsNull()); | 2367 EXPECT(!script.IsNull()); |
2385 EXPECT(script.IsScript()); | 2368 EXPECT(script.IsScript()); |
2386 String& str = String::Handle(script.url()); | 2369 String& str = String::Handle(script.url()); |
2387 EXPECT_EQ(17, str.Length()); | 2370 EXPECT_EQ(17, str.Length()); |
2388 EXPECT_EQ('b', str.CharAt(0)); | 2371 EXPECT_EQ('b', str.CharAt(0)); |
2389 EXPECT_EQ(':', str.CharAt(7)); | 2372 EXPECT_EQ(':', str.CharAt(7)); |
2390 EXPECT_EQ('e', str.CharAt(16)); | 2373 EXPECT_EQ('e', str.CharAt(16)); |
2391 str = script.Source(); | 2374 str = script.Source(); |
2392 EXPECT_EQ(22, str.Length()); | 2375 EXPECT_EQ(22, str.Length()); |
2393 EXPECT_EQ('T', str.CharAt(0)); | 2376 EXPECT_EQ('T', str.CharAt(0)); |
2394 EXPECT_EQ('n', str.CharAt(10)); | 2377 EXPECT_EQ('n', str.CharAt(10)); |
2395 EXPECT_EQ('.', str.CharAt(21)); | 2378 EXPECT_EQ('.', str.CharAt(21)); |
2396 | 2379 |
2397 const char* kScript = "main() {}"; | 2380 const char* kScript = "main() {}"; |
2398 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 2381 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
2399 EXPECT_VALID(h_lib); | 2382 EXPECT_VALID(h_lib); |
2400 Library& lib = Library::Handle(); | 2383 Library& lib = Library::Handle(); |
2401 lib ^= Api::UnwrapHandle(h_lib); | 2384 lib ^= Api::UnwrapHandle(h_lib); |
2402 EXPECT(!lib.IsNull()); | 2385 EXPECT(!lib.IsNull()); |
2403 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | 2386 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
2404 EXPECT_VALID(result); | 2387 EXPECT_VALID(result); |
2405 } | 2388 } |
2406 | 2389 |
2407 | 2390 |
2408 VM_TEST_CASE(EmbeddedScript) { | 2391 VM_TEST_CASE(EmbeddedScript) { |
2409 const char* url_chars = "builtin:test-case"; | 2392 const char* url_chars = "builtin:test-case"; |
2410 const char* text = | 2393 const char* text = |
2411 /* 1 */ "<!DOCTYPE html>\n" | 2394 /* 1 */ |
2412 /* 2 */ " ... more junk ...\n" | 2395 "<!DOCTYPE html>\n" |
2413 /* 3 */ " <script type='application/dart'>main() {\n" | 2396 /* 2 */ |
2414 /* 4 */ " return 'foo';\n" | 2397 " ... more junk ...\n" |
2415 /* 5 */ " }\n" | 2398 /* 3 */ |
| 2399 " <script type='application/dart'>main() {\n" |
| 2400 /* 4 */ |
| 2401 " return 'foo';\n" |
| 2402 /* 5 */ |
| 2403 " }\n" |
2416 /* 6 */ "</script>\n"; | 2404 /* 6 */ "</script>\n"; |
2417 const char* line1 = text; | 2405 const char* line1 = text; |
2418 const char* line2 = strstr(line1, "\n") + 1; | 2406 const char* line2 = strstr(line1, "\n") + 1; |
2419 const char* line3 = strstr(line2, "\n") + 1; | 2407 const char* line3 = strstr(line2, "\n") + 1; |
2420 const char* line4 = strstr(line3, "\n") + 1; | 2408 const char* line4 = strstr(line3, "\n") + 1; |
2421 const char* line5 = strstr(line4, "\n") + 1; | 2409 const char* line5 = strstr(line4, "\n") + 1; |
2422 | 2410 |
2423 const int first_dart_line = 3; | 2411 const int first_dart_line = 3; |
2424 EXPECT(strstr(line3, "main") != NULL); | 2412 EXPECT(strstr(line3, "main") != NULL); |
2425 const int last_dart_line = 5; | 2413 const int last_dart_line = 5; |
(...skipping 10 matching lines...) Expand all Loading... |
2436 int line_offset = 2; | 2424 int line_offset = 2; |
2437 // Dart script starts with "main" on line 3. | 2425 // Dart script starts with "main" on line 3. |
2438 intptr_t col_offset = script_begin - line3; | 2426 intptr_t col_offset = script_begin - line3; |
2439 EXPECT(col_offset > 0); | 2427 EXPECT(col_offset > 0); |
2440 | 2428 |
2441 char* src_chars = strdup(script_begin); | 2429 char* src_chars = strdup(script_begin); |
2442 src_chars[script_length] = '\0'; | 2430 src_chars[script_length] = '\0'; |
2443 | 2431 |
2444 const String& url = String::Handle(String::New(url_chars)); | 2432 const String& url = String::Handle(String::New(url_chars)); |
2445 const String& source = String::Handle(String::New(src_chars)); | 2433 const String& source = String::Handle(String::New(src_chars)); |
2446 const Script& script = Script::Handle( | 2434 const Script& script = |
2447 Script::New(url, source, RawScript::kScriptTag)); | 2435 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
2448 script.SetLocationOffset(line_offset, col_offset); | 2436 script.SetLocationOffset(line_offset, col_offset); |
2449 | 2437 |
2450 String& str = String::Handle(); | 2438 String& str = String::Handle(); |
2451 str = script.GetLine(first_dart_line); | 2439 str = script.GetLine(first_dart_line); |
2452 EXPECT_STREQ("main() {", str.ToCString()); | 2440 EXPECT_STREQ("main() {", str.ToCString()); |
2453 str = script.GetLine(last_dart_line); | 2441 str = script.GetLine(last_dart_line); |
2454 EXPECT_STREQ(" }", str.ToCString()); | 2442 EXPECT_STREQ(" }", str.ToCString()); |
2455 | 2443 |
2456 script.Tokenize(String::Handle(String::New("ABC"))); | 2444 script.Tokenize(String::Handle(String::New("ABC"))); |
2457 // Tokens: 0: kIDENT, 1: kLPAREN, 2: kRPAREN, 3: kLBRACE, 4: kNEWLINE, | 2445 // Tokens: 0: kIDENT, 1: kLPAREN, 2: kRPAREN, 3: kLBRACE, 4: kNEWLINE, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 const intptr_t parent_scope_function_level = 0; | 2515 const intptr_t parent_scope_function_level = 0; |
2528 LocalScope* parent_scope = | 2516 LocalScope* parent_scope = |
2529 new LocalScope(NULL, parent_scope_function_level, 0); | 2517 new LocalScope(NULL, parent_scope_function_level, 0); |
2530 | 2518 |
2531 const intptr_t local_scope_function_level = 1; | 2519 const intptr_t local_scope_function_level = 1; |
2532 LocalScope* local_scope = | 2520 LocalScope* local_scope = |
2533 new LocalScope(parent_scope, local_scope_function_level, 0); | 2521 new LocalScope(parent_scope, local_scope_function_level, 0); |
2534 | 2522 |
2535 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); | 2523 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); |
2536 const String& a = String::ZoneHandle(Symbols::New(thread, "a")); | 2524 const String& a = String::ZoneHandle(Symbols::New(thread, "a")); |
2537 LocalVariable* var_a = | 2525 LocalVariable* var_a = new LocalVariable( |
2538 new LocalVariable(TokenPosition::kNoSource, | 2526 TokenPosition::kNoSource, TokenPosition::kNoSource, a, dynamic_type); |
2539 TokenPosition::kNoSource, | |
2540 a, | |
2541 dynamic_type); | |
2542 parent_scope->AddVariable(var_a); | 2527 parent_scope->AddVariable(var_a); |
2543 | 2528 |
2544 const String& b = String::ZoneHandle(Symbols::New(thread, "b")); | 2529 const String& b = String::ZoneHandle(Symbols::New(thread, "b")); |
2545 LocalVariable* var_b = | 2530 LocalVariable* var_b = new LocalVariable( |
2546 new LocalVariable(TokenPosition::kNoSource, | 2531 TokenPosition::kNoSource, TokenPosition::kNoSource, b, dynamic_type); |
2547 TokenPosition::kNoSource, | |
2548 b, | |
2549 dynamic_type); | |
2550 local_scope->AddVariable(var_b); | 2532 local_scope->AddVariable(var_b); |
2551 | 2533 |
2552 const String& c = String::ZoneHandle(Symbols::New(thread, "c")); | 2534 const String& c = String::ZoneHandle(Symbols::New(thread, "c")); |
2553 LocalVariable* var_c = | 2535 LocalVariable* var_c = new LocalVariable( |
2554 new LocalVariable(TokenPosition::kNoSource, | 2536 TokenPosition::kNoSource, TokenPosition::kNoSource, c, dynamic_type); |
2555 TokenPosition::kNoSource, | |
2556 c, | |
2557 dynamic_type); | |
2558 parent_scope->AddVariable(var_c); | 2537 parent_scope->AddVariable(var_c); |
2559 | 2538 |
2560 bool test_only = false; // Please, insert alias. | 2539 bool test_only = false; // Please, insert alias. |
2561 var_a = local_scope->LookupVariable(a, test_only); | 2540 var_a = local_scope->LookupVariable(a, test_only); |
2562 EXPECT(var_a->is_captured()); | 2541 EXPECT(var_a->is_captured()); |
2563 EXPECT_EQ(parent_scope_function_level, var_a->owner()->function_level()); | 2542 EXPECT_EQ(parent_scope_function_level, var_a->owner()->function_level()); |
2564 EXPECT(local_scope->LocalLookupVariable(a) == var_a); // Alias. | 2543 EXPECT(local_scope->LocalLookupVariable(a) == var_a); // Alias. |
2565 | 2544 |
2566 var_b = local_scope->LookupVariable(b, test_only); | 2545 var_b = local_scope->LookupVariable(b, test_only); |
2567 EXPECT(!var_b->is_captured()); | 2546 EXPECT(!var_b->is_captured()); |
2568 EXPECT_EQ(local_scope_function_level, var_b->owner()->function_level()); | 2547 EXPECT_EQ(local_scope_function_level, var_b->owner()->function_level()); |
2569 EXPECT(local_scope->LocalLookupVariable(b) == var_b); | 2548 EXPECT(local_scope->LocalLookupVariable(b) == var_b); |
2570 | 2549 |
2571 test_only = true; // Please, do not insert alias. | 2550 test_only = true; // Please, do not insert alias. |
2572 var_c = local_scope->LookupVariable(c, test_only); | 2551 var_c = local_scope->LookupVariable(c, test_only); |
2573 EXPECT(!var_c->is_captured()); | 2552 EXPECT(!var_c->is_captured()); |
2574 EXPECT_EQ(parent_scope_function_level, var_c->owner()->function_level()); | 2553 EXPECT_EQ(parent_scope_function_level, var_c->owner()->function_level()); |
2575 // c is not in local_scope. | 2554 // c is not in local_scope. |
2576 EXPECT(local_scope->LocalLookupVariable(c) == NULL); | 2555 EXPECT(local_scope->LocalLookupVariable(c) == NULL); |
2577 | 2556 |
2578 test_only = false; // Please, insert alias. | 2557 test_only = false; // Please, insert alias. |
2579 var_c = local_scope->LookupVariable(c, test_only); | 2558 var_c = local_scope->LookupVariable(c, test_only); |
2580 EXPECT(var_c->is_captured()); | 2559 EXPECT(var_c->is_captured()); |
2581 | 2560 |
2582 EXPECT_EQ(3, local_scope->num_variables()); // a, b, and c alias. | 2561 EXPECT_EQ(3, local_scope->num_variables()); // a, b, and c alias. |
2583 EXPECT_EQ(2, local_scope->NumCapturedVariables()); // a, c alias. | 2562 EXPECT_EQ(2, local_scope->NumCapturedVariables()); // a, c alias. |
2584 | 2563 |
2585 const int first_parameter_index = 0; | 2564 const int first_parameter_index = 0; |
2586 const int num_parameters = 0; | 2565 const int num_parameters = 0; |
2587 const int first_frame_index = -1; | 2566 const int first_frame_index = -1; |
2588 bool found_captured_vars = false; | 2567 bool found_captured_vars = false; |
2589 int next_frame_index = parent_scope->AllocateVariables(first_parameter_index, | 2568 int next_frame_index = parent_scope->AllocateVariables( |
2590 num_parameters, | 2569 first_parameter_index, num_parameters, first_frame_index, NULL, |
2591 first_frame_index, | 2570 &found_captured_vars); |
2592 NULL, | |
2593 &found_captured_vars); | |
2594 EXPECT_EQ(first_frame_index, next_frame_index); // a and c not in frame. | 2571 EXPECT_EQ(first_frame_index, next_frame_index); // a and c not in frame. |
2595 const intptr_t parent_scope_context_level = 1; | 2572 const intptr_t parent_scope_context_level = 1; |
2596 EXPECT_EQ(parent_scope_context_level, parent_scope->context_level()); | 2573 EXPECT_EQ(parent_scope_context_level, parent_scope->context_level()); |
2597 EXPECT(found_captured_vars); | 2574 EXPECT(found_captured_vars); |
2598 | 2575 |
2599 const intptr_t local_scope_context_level = 5; | 2576 const intptr_t local_scope_context_level = 5; |
2600 const ContextScope& context_scope = ContextScope::Handle( | 2577 const ContextScope& context_scope = ContextScope::Handle( |
2601 local_scope->PreserveOuterScope(local_scope_context_level)); | 2578 local_scope->PreserveOuterScope(local_scope_context_level)); |
2602 LocalScope* outer_scope = LocalScope::RestoreOuterScope(context_scope); | 2579 LocalScope* outer_scope = LocalScope::RestoreOuterScope(context_scope); |
2603 EXPECT_EQ(2, outer_scope->num_variables()); | 2580 EXPECT_EQ(2, outer_scope->num_variables()); |
(...skipping 18 matching lines...) Expand all Loading... |
2622 VM_TEST_CASE(Closure) { | 2599 VM_TEST_CASE(Closure) { |
2623 // Allocate the class first. | 2600 // Allocate the class first. |
2624 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 2601 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
2625 const Script& script = Script::Handle(); | 2602 const Script& script = Script::Handle(); |
2626 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 2603 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
2627 const Array& functions = Array::Handle(Array::New(1)); | 2604 const Array& functions = Array::Handle(Array::New(1)); |
2628 | 2605 |
2629 const Context& context = Context::Handle(Context::New(0)); | 2606 const Context& context = Context::Handle(Context::New(0)); |
2630 Function& parent = Function::Handle(); | 2607 Function& parent = Function::Handle(); |
2631 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); | 2608 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
2632 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 2609 parent = |
2633 false, false, false, false, false, cls, | 2610 Function::New(parent_name, RawFunction::kRegularFunction, false, false, |
2634 TokenPosition::kMinSource); | 2611 false, false, false, cls, TokenPosition::kMinSource); |
2635 functions.SetAt(0, parent); | 2612 functions.SetAt(0, parent); |
2636 cls.SetFunctions(functions); | 2613 cls.SetFunctions(functions); |
2637 | 2614 |
2638 Function& function = Function::Handle(); | 2615 Function& function = Function::Handle(); |
2639 const String& function_name = String::Handle(Symbols::New(thread, "foo")); | 2616 const String& function_name = String::Handle(Symbols::New(thread, "foo")); |
2640 function = Function::NewClosureFunction( | 2617 function = Function::NewClosureFunction(function_name, parent, |
2641 function_name, parent, TokenPosition::kMinSource); | 2618 TokenPosition::kMinSource); |
2642 const Closure& closure = Closure::Handle(Closure::New(function, context)); | 2619 const Closure& closure = Closure::Handle(Closure::New(function, context)); |
2643 const Class& closure_class = Class::Handle(closure.clazz()); | 2620 const Class& closure_class = Class::Handle(closure.clazz()); |
2644 EXPECT_EQ(closure_class.id(), kClosureCid); | 2621 EXPECT_EQ(closure_class.id(), kClosureCid); |
2645 const Function& closure_function = Function::Handle(closure.function()); | 2622 const Function& closure_function = Function::Handle(closure.function()); |
2646 EXPECT_EQ(closure_function.raw(), function.raw()); | 2623 EXPECT_EQ(closure_function.raw(), function.raw()); |
2647 const Context& closure_context = Context::Handle(closure.context()); | 2624 const Context& closure_context = Context::Handle(closure.context()); |
2648 EXPECT_EQ(closure_context.raw(), context.raw()); | 2625 EXPECT_EQ(closure_context.raw(), context.raw()); |
2649 } | 2626 } |
2650 | 2627 |
2651 | 2628 |
2652 VM_TEST_CASE(ObjectPrinting) { | 2629 VM_TEST_CASE(ObjectPrinting) { |
2653 // Simple Smis. | 2630 // Simple Smis. |
2654 EXPECT_STREQ("2", Smi::Handle(Smi::New(2)).ToCString()); | 2631 EXPECT_STREQ("2", Smi::Handle(Smi::New(2)).ToCString()); |
2655 EXPECT_STREQ("-15", Smi::Handle(Smi::New(-15)).ToCString()); | 2632 EXPECT_STREQ("-15", Smi::Handle(Smi::New(-15)).ToCString()); |
2656 | 2633 |
2657 // bool class and true/false values. | 2634 // bool class and true/false values. |
2658 ObjectStore* object_store = Isolate::Current()->object_store(); | 2635 ObjectStore* object_store = Isolate::Current()->object_store(); |
2659 const Class& bool_class = Class::Handle(object_store->bool_class()); | 2636 const Class& bool_class = Class::Handle(object_store->bool_class()); |
2660 EXPECT_STREQ("Library:'dart:core' Class: bool", | 2637 EXPECT_STREQ("Library:'dart:core' Class: bool", bool_class.ToCString()); |
2661 bool_class.ToCString()); | |
2662 EXPECT_STREQ("true", Bool::True().ToCString()); | 2638 EXPECT_STREQ("true", Bool::True().ToCString()); |
2663 EXPECT_STREQ("false", Bool::False().ToCString()); | 2639 EXPECT_STREQ("false", Bool::False().ToCString()); |
2664 | 2640 |
2665 // Strings. | 2641 // Strings. |
2666 EXPECT_STREQ("Sugarbowl", | 2642 EXPECT_STREQ("Sugarbowl", |
2667 String::Handle(String::New("Sugarbowl")).ToCString()); | 2643 String::Handle(String::New("Sugarbowl")).ToCString()); |
2668 } | 2644 } |
2669 | 2645 |
2670 | 2646 |
2671 VM_TEST_CASE(CheckedHandle) { | 2647 VM_TEST_CASE(CheckedHandle) { |
(...skipping 23 matching lines...) Expand all Loading... |
2695 } | 2671 } |
2696 | 2672 |
2697 | 2673 |
2698 static RawFunction* CreateFunction(const char* name) { | 2674 static RawFunction* CreateFunction(const char* name) { |
2699 Thread* thread = Thread::Current(); | 2675 Thread* thread = Thread::Current(); |
2700 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); | 2676 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); |
2701 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); | 2677 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); |
2702 const Script& script = Script::Handle(); | 2678 const Script& script = Script::Handle(); |
2703 const Class& owner_class = | 2679 const Class& owner_class = |
2704 Class::Handle(CreateDummyClass(class_name, script)); | 2680 Class::Handle(CreateDummyClass(class_name, script)); |
2705 const Library& owner_library = | 2681 const Library& owner_library = Library::Handle(CreateDummyLibrary(lib_name)); |
2706 Library::Handle(CreateDummyLibrary(lib_name)); | |
2707 owner_class.set_library(owner_library); | 2682 owner_class.set_library(owner_library); |
2708 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); | 2683 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); |
2709 return Function::New(function_name, RawFunction::kRegularFunction, | 2684 return Function::New(function_name, RawFunction::kRegularFunction, true, |
2710 true, false, false, false, false, owner_class, | 2685 false, false, false, false, owner_class, |
2711 TokenPosition::kMinSource); | 2686 TokenPosition::kMinSource); |
2712 } | 2687 } |
2713 | 2688 |
2714 | 2689 |
2715 // Test for Code and Instruction object creation. | 2690 // Test for Code and Instruction object creation. |
2716 VM_TEST_CASE(Code) { | 2691 VM_TEST_CASE(Code) { |
2717 extern void GenerateIncrement(Assembler* assembler); | 2692 extern void GenerateIncrement(Assembler * assembler); |
2718 Assembler _assembler_; | 2693 Assembler _assembler_; |
2719 GenerateIncrement(&_assembler_); | 2694 GenerateIncrement(&_assembler_); |
2720 const Function& function = Function::Handle(CreateFunction("Test_Code")); | 2695 const Function& function = Function::Handle(CreateFunction("Test_Code")); |
2721 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2696 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2722 function.AttachCode(code); | 2697 function.AttachCode(code); |
2723 const Instructions& instructions = Instructions::Handle(code.instructions()); | 2698 const Instructions& instructions = Instructions::Handle(code.instructions()); |
2724 uword payload_start = instructions.PayloadStart(); | 2699 uword payload_start = instructions.PayloadStart(); |
2725 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); | 2700 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); |
2726 const Object& result = Object::Handle( | 2701 const Object& result = |
2727 DartEntry::InvokeFunction(function, Array::empty_array())); | 2702 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2728 EXPECT_EQ(1, Smi::Cast(result).Value()); | 2703 EXPECT_EQ(1, Smi::Cast(result).Value()); |
2729 } | 2704 } |
2730 | 2705 |
2731 | 2706 |
2732 // Test for immutability of generated instructions. The test crashes with a | 2707 // Test for immutability of generated instructions. The test crashes with a |
2733 // segmentation fault when writing into it. | 2708 // segmentation fault when writing into it. |
2734 VM_TEST_CASE(CodeImmutability) { | 2709 VM_TEST_CASE(CodeImmutability) { |
2735 extern void GenerateIncrement(Assembler* assembler); | 2710 extern void GenerateIncrement(Assembler * assembler); |
2736 Assembler _assembler_; | 2711 Assembler _assembler_; |
2737 GenerateIncrement(&_assembler_); | 2712 GenerateIncrement(&_assembler_); |
2738 const Function& function = Function::Handle(CreateFunction("Test_Code")); | 2713 const Function& function = Function::Handle(CreateFunction("Test_Code")); |
2739 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2714 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2740 function.AttachCode(code); | 2715 function.AttachCode(code); |
2741 Instructions& instructions = Instructions::Handle(code.instructions()); | 2716 Instructions& instructions = Instructions::Handle(code.instructions()); |
2742 uword payload_start = instructions.PayloadStart(); | 2717 uword payload_start = instructions.PayloadStart(); |
2743 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); | 2718 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); |
2744 // Try writing into the generated code, expected to crash. | 2719 // Try writing into the generated code, expected to crash. |
2745 *(reinterpret_cast<char*>(payload_start) + 1) = 1; | 2720 *(reinterpret_cast<char*>(payload_start) + 1) = 1; |
2746 if (!FLAG_write_protect_code) { | 2721 if (!FLAG_write_protect_code) { |
2747 // Since this test is expected to crash, crash if write protection of code | 2722 // Since this test is expected to crash, crash if write protection of code |
2748 // is switched off. | 2723 // is switched off. |
2749 // TODO(regis, fschneider): Should this be FATAL() instead? | 2724 // TODO(regis, fschneider): Should this be FATAL() instead? |
2750 OS::DebugBreak(); | 2725 OS::DebugBreak(); |
2751 } | 2726 } |
2752 } | 2727 } |
2753 | 2728 |
2754 | 2729 |
2755 // Test for Embedded String object in the instructions. | 2730 // Test for Embedded String object in the instructions. |
2756 VM_TEST_CASE(EmbedStringInCode) { | 2731 VM_TEST_CASE(EmbedStringInCode) { |
2757 extern void GenerateEmbedStringInCode(Assembler* assembler, const char* str); | 2732 extern void GenerateEmbedStringInCode(Assembler * assembler, const char* str); |
2758 const char* kHello = "Hello World!"; | 2733 const char* kHello = "Hello World!"; |
2759 word expected_length = static_cast<word>(strlen(kHello)); | 2734 word expected_length = static_cast<word>(strlen(kHello)); |
2760 Assembler _assembler_; | 2735 Assembler _assembler_; |
2761 GenerateEmbedStringInCode(&_assembler_, kHello); | 2736 GenerateEmbedStringInCode(&_assembler_, kHello); |
2762 const Function& function = | 2737 const Function& function = |
2763 Function::Handle(CreateFunction("Test_EmbedStringInCode")); | 2738 Function::Handle(CreateFunction("Test_EmbedStringInCode")); |
2764 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2739 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2765 function.AttachCode(code); | 2740 function.AttachCode(code); |
2766 const Object& result = | 2741 const Object& result = |
2767 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2742 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2768 EXPECT(result.raw()->IsHeapObject()); | 2743 EXPECT(result.raw()->IsHeapObject()); |
2769 String& string_object = String::Handle(); | 2744 String& string_object = String::Handle(); |
2770 string_object ^= result.raw(); | 2745 string_object ^= result.raw(); |
2771 EXPECT(string_object.Length() == expected_length); | 2746 EXPECT(string_object.Length() == expected_length); |
2772 for (int i = 0; i < expected_length; i ++) { | 2747 for (int i = 0; i < expected_length; i++) { |
2773 EXPECT(string_object.CharAt(i) == kHello[i]); | 2748 EXPECT(string_object.CharAt(i) == kHello[i]); |
2774 } | 2749 } |
2775 } | 2750 } |
2776 | 2751 |
2777 | 2752 |
2778 // Test for Embedded Smi object in the instructions. | 2753 // Test for Embedded Smi object in the instructions. |
2779 VM_TEST_CASE(EmbedSmiInCode) { | 2754 VM_TEST_CASE(EmbedSmiInCode) { |
2780 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); | 2755 extern void GenerateEmbedSmiInCode(Assembler * assembler, intptr_t value); |
2781 const intptr_t kSmiTestValue = 5; | 2756 const intptr_t kSmiTestValue = 5; |
2782 Assembler _assembler_; | 2757 Assembler _assembler_; |
2783 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2758 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
2784 const Function& function = | 2759 const Function& function = |
2785 Function::Handle(CreateFunction("Test_EmbedSmiInCode")); | 2760 Function::Handle(CreateFunction("Test_EmbedSmiInCode")); |
2786 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2761 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2787 function.AttachCode(code); | 2762 function.AttachCode(code); |
2788 const Object& result = | 2763 const Object& result = |
2789 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2764 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2790 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); | 2765 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); |
2791 } | 2766 } |
2792 | 2767 |
2793 | 2768 |
2794 #if defined(ARCH_IS_64_BIT) | 2769 #if defined(ARCH_IS_64_BIT) |
2795 // Test for Embedded Smi object in the instructions. | 2770 // Test for Embedded Smi object in the instructions. |
2796 VM_TEST_CASE(EmbedSmiIn64BitCode) { | 2771 VM_TEST_CASE(EmbedSmiIn64BitCode) { |
2797 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); | 2772 extern void GenerateEmbedSmiInCode(Assembler * assembler, intptr_t value); |
2798 const intptr_t kSmiTestValue = DART_INT64_C(5) << 32; | 2773 const intptr_t kSmiTestValue = DART_INT64_C(5) << 32; |
2799 Assembler _assembler_; | 2774 Assembler _assembler_; |
2800 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2775 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
2801 const Function& function = | 2776 const Function& function = |
2802 Function::Handle(CreateFunction("Test_EmbedSmiIn64BitCode")); | 2777 Function::Handle(CreateFunction("Test_EmbedSmiIn64BitCode")); |
2803 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2778 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2804 function.AttachCode(code); | 2779 function.AttachCode(code); |
2805 const Object& result = | 2780 const Object& result = |
2806 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2781 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2807 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); | 2782 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); |
2808 } | 2783 } |
2809 #endif // ARCH_IS_64_BIT | 2784 #endif // ARCH_IS_64_BIT |
2810 | 2785 |
2811 | 2786 |
2812 VM_TEST_CASE(ExceptionHandlers) { | 2787 VM_TEST_CASE(ExceptionHandlers) { |
2813 const int kNumEntries = 4; | 2788 const int kNumEntries = 4; |
2814 // Add an exception handler table to the code. | 2789 // Add an exception handler table to the code. |
2815 ExceptionHandlers& exception_handlers = ExceptionHandlers::Handle(); | 2790 ExceptionHandlers& exception_handlers = ExceptionHandlers::Handle(); |
2816 exception_handlers ^= ExceptionHandlers::New(kNumEntries); | 2791 exception_handlers ^= ExceptionHandlers::New(kNumEntries); |
2817 const bool kNeedsStacktrace = true; | 2792 const bool kNeedsStacktrace = true; |
2818 const bool kNoStacktrace = false; | 2793 const bool kNoStacktrace = false; |
2819 exception_handlers.SetHandlerInfo(0, -1, 20u, kNeedsStacktrace, false); | 2794 exception_handlers.SetHandlerInfo(0, -1, 20u, kNeedsStacktrace, false); |
2820 exception_handlers.SetHandlerInfo(1, 0, 30u, kNeedsStacktrace, false); | 2795 exception_handlers.SetHandlerInfo(1, 0, 30u, kNeedsStacktrace, false); |
2821 exception_handlers.SetHandlerInfo(2, -1, 40u, kNoStacktrace, true); | 2796 exception_handlers.SetHandlerInfo(2, -1, 40u, kNoStacktrace, true); |
2822 exception_handlers.SetHandlerInfo(3, 1, 150u, kNoStacktrace, true); | 2797 exception_handlers.SetHandlerInfo(3, 1, 150u, kNoStacktrace, true); |
2823 | 2798 |
2824 extern void GenerateIncrement(Assembler* assembler); | 2799 extern void GenerateIncrement(Assembler * assembler); |
2825 Assembler _assembler_; | 2800 Assembler _assembler_; |
2826 GenerateIncrement(&_assembler_); | 2801 GenerateIncrement(&_assembler_); |
2827 Code& code = Code::Handle(Code::FinalizeCode( | 2802 Code& code = Code::Handle(Code::FinalizeCode( |
2828 Function::Handle(CreateFunction("Test_Code")), &_assembler_)); | 2803 Function::Handle(CreateFunction("Test_Code")), &_assembler_)); |
2829 code.set_exception_handlers(exception_handlers); | 2804 code.set_exception_handlers(exception_handlers); |
2830 | 2805 |
2831 // Verify the exception handler table entries by accessing them. | 2806 // Verify the exception handler table entries by accessing them. |
2832 const ExceptionHandlers& handlers = | 2807 const ExceptionHandlers& handlers = |
2833 ExceptionHandlers::Handle(code.exception_handlers()); | 2808 ExceptionHandlers::Handle(code.exception_handlers()); |
2834 EXPECT_EQ(kNumEntries, handlers.num_entries()); | 2809 EXPECT_EQ(kNumEntries, handlers.num_entries()); |
2835 RawExceptionHandlers::HandlerInfo info; | 2810 RawExceptionHandlers::HandlerInfo info; |
2836 handlers.GetHandlerInfo(0, &info); | 2811 handlers.GetHandlerInfo(0, &info); |
2837 EXPECT_EQ(-1, handlers.OuterTryIndex(0)); | 2812 EXPECT_EQ(-1, handlers.OuterTryIndex(0)); |
2838 EXPECT_EQ(-1, info.outer_try_index); | 2813 EXPECT_EQ(-1, info.outer_try_index); |
2839 EXPECT_EQ(20u, handlers.HandlerPCOffset(0)); | 2814 EXPECT_EQ(20u, handlers.HandlerPCOffset(0)); |
2840 EXPECT(handlers.NeedsStacktrace(0)); | 2815 EXPECT(handlers.NeedsStacktrace(0)); |
2841 EXPECT(!handlers.HasCatchAll(0)); | 2816 EXPECT(!handlers.HasCatchAll(0)); |
2842 EXPECT_EQ(20u, info.handler_pc_offset); | 2817 EXPECT_EQ(20u, info.handler_pc_offset); |
2843 EXPECT_EQ(1, handlers.OuterTryIndex(3)); | 2818 EXPECT_EQ(1, handlers.OuterTryIndex(3)); |
2844 EXPECT_EQ(150u, handlers.HandlerPCOffset(3)); | 2819 EXPECT_EQ(150u, handlers.HandlerPCOffset(3)); |
2845 EXPECT(!handlers.NeedsStacktrace(3)); | 2820 EXPECT(!handlers.NeedsStacktrace(3)); |
2846 EXPECT(handlers.HasCatchAll(3)); | 2821 EXPECT(handlers.HasCatchAll(3)); |
2847 } | 2822 } |
2848 | 2823 |
2849 | 2824 |
2850 VM_TEST_CASE(PcDescriptors) { | 2825 VM_TEST_CASE(PcDescriptors) { |
2851 DescriptorList* builder = new DescriptorList(0); | 2826 DescriptorList* builder = new DescriptorList(0); |
2852 | 2827 |
2853 // kind, pc_offset, deopt_id, token_pos, try_index | 2828 // kind, pc_offset, deopt_id, token_pos, try_index |
2854 builder->AddDescriptor(RawPcDescriptors::kOther, | 2829 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 1, TokenPosition(20), 1); |
2855 10, 1, TokenPosition(20), 1); | 2830 builder->AddDescriptor(RawPcDescriptors::kDeopt, 20, 2, TokenPosition(30), 0); |
2856 builder->AddDescriptor(RawPcDescriptors::kDeopt, | 2831 builder->AddDescriptor(RawPcDescriptors::kOther, 30, 3, TokenPosition(40), 1); |
2857 20, 2, TokenPosition(30), 0); | 2832 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 4, TokenPosition(40), 2); |
2858 builder->AddDescriptor(RawPcDescriptors::kOther, | 2833 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 5, TokenPosition(80), 3); |
2859 30, 3, TokenPosition(40), 1); | 2834 builder->AddDescriptor(RawPcDescriptors::kOther, 80, 6, TokenPosition(150), |
2860 builder->AddDescriptor(RawPcDescriptors::kOther, | 2835 3); |
2861 10, 4, TokenPosition(40), 2); | |
2862 builder->AddDescriptor(RawPcDescriptors::kOther, | |
2863 10, 5, TokenPosition(80), 3); | |
2864 builder->AddDescriptor(RawPcDescriptors::kOther, | |
2865 80, 6, TokenPosition(150), 3); | |
2866 | 2836 |
2867 PcDescriptors& descriptors = PcDescriptors::Handle(); | 2837 PcDescriptors& descriptors = PcDescriptors::Handle(); |
2868 descriptors ^= builder->FinalizePcDescriptors(0); | 2838 descriptors ^= builder->FinalizePcDescriptors(0); |
2869 | 2839 |
2870 extern void GenerateIncrement(Assembler* assembler); | 2840 extern void GenerateIncrement(Assembler * assembler); |
2871 Assembler _assembler_; | 2841 Assembler _assembler_; |
2872 GenerateIncrement(&_assembler_); | 2842 GenerateIncrement(&_assembler_); |
2873 Code& code = Code::Handle(Code::FinalizeCode( | 2843 Code& code = Code::Handle(Code::FinalizeCode( |
2874 Function::Handle(CreateFunction("Test_Code")), &_assembler_)); | 2844 Function::Handle(CreateFunction("Test_Code")), &_assembler_)); |
2875 code.set_pc_descriptors(descriptors); | 2845 code.set_pc_descriptors(descriptors); |
2876 | 2846 |
2877 // Verify the PcDescriptor entries by accessing them. | 2847 // Verify the PcDescriptor entries by accessing them. |
2878 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors()); | 2848 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors()); |
2879 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind); | 2849 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind); |
2880 | 2850 |
(...skipping 26 matching lines...) Expand all Loading... |
2907 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); | 2877 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); |
2908 | 2878 |
2909 EXPECT_EQ(false, iter.MoveNext()); | 2879 EXPECT_EQ(false, iter.MoveNext()); |
2910 } | 2880 } |
2911 | 2881 |
2912 | 2882 |
2913 VM_TEST_CASE(PcDescriptorsLargeDeltas) { | 2883 VM_TEST_CASE(PcDescriptorsLargeDeltas) { |
2914 DescriptorList* builder = new DescriptorList(0); | 2884 DescriptorList* builder = new DescriptorList(0); |
2915 | 2885 |
2916 // kind, pc_offset, deopt_id, token_pos, try_index | 2886 // kind, pc_offset, deopt_id, token_pos, try_index |
2917 builder->AddDescriptor(RawPcDescriptors::kOther, | 2887 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 1, TokenPosition(200), |
2918 100, 1, TokenPosition(200), 1); | 2888 1); |
2919 builder->AddDescriptor(RawPcDescriptors::kDeopt, | 2889 builder->AddDescriptor(RawPcDescriptors::kDeopt, 200, 2, TokenPosition(300), |
2920 200, 2, TokenPosition(300), 0); | 2890 0); |
2921 builder->AddDescriptor(RawPcDescriptors::kOther, | 2891 builder->AddDescriptor(RawPcDescriptors::kOther, 300, 3, TokenPosition(400), |
2922 300, 3, TokenPosition(400), 1); | 2892 1); |
2923 builder->AddDescriptor(RawPcDescriptors::kOther, | 2893 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 4, TokenPosition(0), 2); |
2924 100, 4, TokenPosition(0), 2); | 2894 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 5, TokenPosition(800), |
2925 builder->AddDescriptor(RawPcDescriptors::kOther, | 2895 3); |
2926 100, 5, TokenPosition(800), 3); | 2896 builder->AddDescriptor(RawPcDescriptors::kOther, 800, 6, TokenPosition(150), |
2927 builder->AddDescriptor(RawPcDescriptors::kOther, | 2897 3); |
2928 800, 6, TokenPosition(150), 3); | |
2929 | 2898 |
2930 PcDescriptors& descriptors = PcDescriptors::Handle(); | 2899 PcDescriptors& descriptors = PcDescriptors::Handle(); |
2931 descriptors ^= builder->FinalizePcDescriptors(0); | 2900 descriptors ^= builder->FinalizePcDescriptors(0); |
2932 | 2901 |
2933 extern void GenerateIncrement(Assembler* assembler); | 2902 extern void GenerateIncrement(Assembler * assembler); |
2934 Assembler _assembler_; | 2903 Assembler _assembler_; |
2935 GenerateIncrement(&_assembler_); | 2904 GenerateIncrement(&_assembler_); |
2936 Code& code = Code::Handle(Code::FinalizeCode( | 2905 Code& code = Code::Handle(Code::FinalizeCode( |
2937 Function::Handle(CreateFunction("Test_Code")), &_assembler_)); | 2906 Function::Handle(CreateFunction("Test_Code")), &_assembler_)); |
2938 code.set_pc_descriptors(descriptors); | 2907 code.set_pc_descriptors(descriptors); |
2939 | 2908 |
2940 // Verify the PcDescriptor entries by accessing them. | 2909 // Verify the PcDescriptor entries by accessing them. |
2941 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors()); | 2910 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors()); |
2942 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind); | 2911 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind); |
2943 | 2912 |
(...skipping 23 matching lines...) Expand all Loading... |
2967 EXPECT_EQ(3, iter.TryIndex()); | 2936 EXPECT_EQ(3, iter.TryIndex()); |
2968 EXPECT_EQ(static_cast<uword>(800), iter.PcOffset()); | 2937 EXPECT_EQ(static_cast<uword>(800), iter.PcOffset()); |
2969 EXPECT_EQ(150, iter.TokenPos().value()); | 2938 EXPECT_EQ(150, iter.TokenPos().value()); |
2970 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); | 2939 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); |
2971 | 2940 |
2972 EXPECT_EQ(false, iter.MoveNext()); | 2941 EXPECT_EQ(false, iter.MoveNext()); |
2973 } | 2942 } |
2974 | 2943 |
2975 | 2944 |
2976 static RawClass* CreateTestClass(const char* name) { | 2945 static RawClass* CreateTestClass(const char* name) { |
2977 const String& class_name = String::Handle(Symbols::New(Thread::Current(), | 2946 const String& class_name = |
2978 name)); | 2947 String::Handle(Symbols::New(Thread::Current(), name)); |
2979 const Class& cls = Class::Handle( | 2948 const Class& cls = |
2980 CreateDummyClass(class_name, Script::Handle())); | 2949 Class::Handle(CreateDummyClass(class_name, Script::Handle())); |
2981 return cls.raw(); | 2950 return cls.raw(); |
2982 } | 2951 } |
2983 | 2952 |
2984 | 2953 |
2985 static RawField* CreateTestField(const char* name) { | 2954 static RawField* CreateTestField(const char* name) { |
2986 const Class& cls = Class::Handle(CreateTestClass("global:")); | 2955 const Class& cls = Class::Handle(CreateTestClass("global:")); |
2987 const String& field_name = String::Handle(Symbols::New(Thread::Current(), | 2956 const String& field_name = |
2988 name)); | 2957 String::Handle(Symbols::New(Thread::Current(), name)); |
2989 const Field& field = | 2958 const Field& field = Field::Handle( |
2990 Field::Handle(Field::New(field_name, true, false, false, true, cls, | 2959 Field::New(field_name, true, false, false, true, cls, |
2991 Object::dynamic_type(), TokenPosition::kMinSource)); | 2960 Object::dynamic_type(), TokenPosition::kMinSource)); |
2992 return field.raw(); | 2961 return field.raw(); |
2993 } | 2962 } |
2994 | 2963 |
2995 | 2964 |
2996 VM_TEST_CASE(ClassDictionaryIterator) { | 2965 VM_TEST_CASE(ClassDictionaryIterator) { |
2997 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); | 2966 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); |
2998 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); | 2967 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); |
2999 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8")); | 2968 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8")); |
3000 Field& tee = Field::ZoneHandle(CreateTestField("TEE")); | 2969 Field& tee = Field::ZoneHandle(CreateTestField("TEE")); |
3001 String& url = String::ZoneHandle(String::New("SBB")); | 2970 String& url = String::ZoneHandle(String::New("SBB")); |
3002 Library& lib = Library::Handle(Library::New(url)); | 2971 Library& lib = Library::Handle(Library::New(url)); |
3003 lib.AddClass(ae66); | 2972 lib.AddClass(ae66); |
3004 lib.AddObject(ce68, String::ZoneHandle(ce68.name())); | 2973 lib.AddObject(ce68, String::ZoneHandle(ce68.name())); |
3005 lib.AddClass(re44); | 2974 lib.AddClass(re44); |
3006 lib.AddObject(tee, String::ZoneHandle(tee.name())); | 2975 lib.AddObject(tee, String::ZoneHandle(tee.name())); |
3007 ClassDictionaryIterator iterator(lib); | 2976 ClassDictionaryIterator iterator(lib); |
3008 int count = 0; | 2977 int count = 0; |
3009 Class& cls = Class::Handle(); | 2978 Class& cls = Class::Handle(); |
3010 while (iterator.HasNext()) { | 2979 while (iterator.HasNext()) { |
3011 cls = iterator.GetNextClass(); | 2980 cls = iterator.GetNextClass(); |
3012 EXPECT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); | 2981 EXPECT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); |
3013 count++; | 2982 count++; |
3014 } | 2983 } |
3015 EXPECT(count == 2); | 2984 EXPECT(count == 2); |
3016 } | 2985 } |
3017 | 2986 |
3018 | 2987 |
3019 static RawFunction* GetDummyTarget(const char* name) { | 2988 static RawFunction* GetDummyTarget(const char* name) { |
3020 const String& function_name = String::Handle(Symbols::New(Thread::Current(), | 2989 const String& function_name = |
3021 name)); | 2990 String::Handle(Symbols::New(Thread::Current(), name)); |
3022 const Class& cls = Class::Handle( | 2991 const Class& cls = |
3023 CreateDummyClass(function_name, Script::Handle())); | 2992 Class::Handle(CreateDummyClass(function_name, Script::Handle())); |
3024 const bool is_static = false; | 2993 const bool is_static = false; |
3025 const bool is_const = false; | 2994 const bool is_const = false; |
3026 const bool is_abstract = false; | 2995 const bool is_abstract = false; |
3027 const bool is_external = false; | 2996 const bool is_external = false; |
3028 const bool is_native = false; | 2997 const bool is_native = false; |
3029 return Function::New(function_name, | 2998 return Function::New(function_name, RawFunction::kRegularFunction, is_static, |
3030 RawFunction::kRegularFunction, | 2999 is_const, is_abstract, is_external, is_native, cls, |
3031 is_static, | |
3032 is_const, | |
3033 is_abstract, | |
3034 is_external, | |
3035 is_native, | |
3036 cls, | |
3037 TokenPosition::kMinSource); | 3000 TokenPosition::kMinSource); |
3038 } | 3001 } |
3039 | 3002 |
3040 | 3003 |
3041 VM_TEST_CASE(ICData) { | 3004 VM_TEST_CASE(ICData) { |
3042 Function& function = Function::Handle(GetDummyTarget("Bern")); | 3005 Function& function = Function::Handle(GetDummyTarget("Bern")); |
3043 const intptr_t id = 12; | 3006 const intptr_t id = 12; |
3044 const intptr_t num_args_tested = 1; | 3007 const intptr_t num_args_tested = 1; |
3045 const String& target_name = String::Handle(Symbols::New(thread, "Thun")); | 3008 const String& target_name = String::Handle(Symbols::New(thread, "Thun")); |
3046 const Array& args_descriptor = | 3009 const Array& args_descriptor = |
3047 Array::Handle(ArgumentsDescriptor::New(1, Object::null_array())); | 3010 Array::Handle(ArgumentsDescriptor::New(1, Object::null_array())); |
3048 ICData& o1 = ICData::Handle(); | 3011 ICData& o1 = ICData::Handle(); |
3049 o1 = ICData::New(function, target_name, args_descriptor, id, | 3012 o1 = ICData::New(function, target_name, args_descriptor, id, num_args_tested, |
3050 num_args_tested, false); | 3013 false); |
3051 EXPECT_EQ(1, o1.NumArgsTested()); | 3014 EXPECT_EQ(1, o1.NumArgsTested()); |
3052 EXPECT_EQ(id, o1.deopt_id()); | 3015 EXPECT_EQ(id, o1.deopt_id()); |
3053 EXPECT_EQ(function.raw(), o1.Owner()); | 3016 EXPECT_EQ(function.raw(), o1.Owner()); |
3054 EXPECT_EQ(0, o1.NumberOfChecks()); | 3017 EXPECT_EQ(0, o1.NumberOfChecks()); |
3055 EXPECT_EQ(target_name.raw(), o1.target_name()); | 3018 EXPECT_EQ(target_name.raw(), o1.target_name()); |
3056 EXPECT_EQ(args_descriptor.raw(), o1.arguments_descriptor()); | 3019 EXPECT_EQ(args_descriptor.raw(), o1.arguments_descriptor()); |
3057 | 3020 |
3058 const Function& target1 = Function::Handle(GetDummyTarget("Thun")); | 3021 const Function& target1 = Function::Handle(GetDummyTarget("Thun")); |
3059 o1.AddReceiverCheck(kSmiCid, target1); | 3022 o1.AddReceiverCheck(kSmiCid, target1); |
3060 EXPECT_EQ(1, o1.NumberOfChecks()); | 3023 EXPECT_EQ(1, o1.NumberOfChecks()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3097 o2.AddCheck(classes, target1); | 3060 o2.AddCheck(classes, target1); |
3098 EXPECT_EQ(1, o2.NumberOfChecks()); | 3061 EXPECT_EQ(1, o2.NumberOfChecks()); |
3099 o2.GetCheckAt(0, &test_class_ids, &test_target); | 3062 o2.GetCheckAt(0, &test_class_ids, &test_target); |
3100 EXPECT_EQ(2, test_class_ids.length()); | 3063 EXPECT_EQ(2, test_class_ids.length()); |
3101 EXPECT_EQ(kSmiCid, test_class_ids[0]); | 3064 EXPECT_EQ(kSmiCid, test_class_ids[0]); |
3102 EXPECT_EQ(kSmiCid, test_class_ids[1]); | 3065 EXPECT_EQ(kSmiCid, test_class_ids[1]); |
3103 EXPECT_EQ(target1.raw(), test_target.raw()); | 3066 EXPECT_EQ(target1.raw(), test_target.raw()); |
3104 | 3067 |
3105 // Check ICData for unoptimized static calls. | 3068 // Check ICData for unoptimized static calls. |
3106 const intptr_t kNumArgsChecked = 0; | 3069 const intptr_t kNumArgsChecked = 0; |
3107 const ICData& scall_icdata = ICData::Handle( | 3070 const ICData& scall_icdata = ICData::Handle(ICData::New( |
3108 ICData::New(function, target_name, args_descriptor, 57, | 3071 function, target_name, args_descriptor, 57, kNumArgsChecked, false)); |
3109 kNumArgsChecked, false)); | |
3110 scall_icdata.AddTarget(target1); | 3072 scall_icdata.AddTarget(target1); |
3111 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); | 3073 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); |
3112 } | 3074 } |
3113 | 3075 |
3114 | 3076 |
3115 VM_TEST_CASE(SubtypeTestCache) { | 3077 VM_TEST_CASE(SubtypeTestCache) { |
3116 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); | 3078 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); |
3117 Script& script = Script::Handle(); | 3079 Script& script = Script::Handle(); |
3118 const Class& empty_class = | 3080 const Class& empty_class = |
3119 Class::Handle(CreateDummyClass(class_name, script)); | 3081 Class::Handle(CreateDummyClass(class_name, script)); |
3120 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); | 3082 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); |
3121 EXPECT(!cache.IsNull()); | 3083 EXPECT(!cache.IsNull()); |
3122 EXPECT_EQ(0, cache.NumberOfChecks()); | 3084 EXPECT_EQ(0, cache.NumberOfChecks()); |
3123 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); | 3085 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); |
3124 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); | 3086 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); |
3125 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); | 3087 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); |
3126 cache.AddCheck(class_id_or_fun, targ_0, targ_1, Bool::True()); | 3088 cache.AddCheck(class_id_or_fun, targ_0, targ_1, Bool::True()); |
3127 EXPECT_EQ(1, cache.NumberOfChecks()); | 3089 EXPECT_EQ(1, cache.NumberOfChecks()); |
3128 Object& test_class_id_or_fun = Object::Handle(); | 3090 Object& test_class_id_or_fun = Object::Handle(); |
3129 TypeArguments& test_targ_0 = TypeArguments::Handle(); | 3091 TypeArguments& test_targ_0 = TypeArguments::Handle(); |
3130 TypeArguments& test_targ_1 = TypeArguments::Handle(); | 3092 TypeArguments& test_targ_1 = TypeArguments::Handle(); |
3131 Bool& test_result = Bool::Handle(); | 3093 Bool& test_result = Bool::Handle(); |
3132 cache.GetCheck( | 3094 cache.GetCheck(0, &test_class_id_or_fun, &test_targ_0, &test_targ_1, |
3133 0, &test_class_id_or_fun, &test_targ_0, &test_targ_1, &test_result); | 3095 &test_result); |
3134 EXPECT_EQ(class_id_or_fun.raw(), test_class_id_or_fun.raw()); | 3096 EXPECT_EQ(class_id_or_fun.raw(), test_class_id_or_fun.raw()); |
3135 EXPECT_EQ(targ_0.raw(), test_targ_0.raw()); | 3097 EXPECT_EQ(targ_0.raw(), test_targ_0.raw()); |
3136 EXPECT_EQ(targ_1.raw(), test_targ_1.raw()); | 3098 EXPECT_EQ(targ_1.raw(), test_targ_1.raw()); |
3137 EXPECT_EQ(Bool::True().raw(), test_result.raw()); | 3099 EXPECT_EQ(Bool::True().raw(), test_result.raw()); |
3138 } | 3100 } |
3139 | 3101 |
3140 | 3102 |
3141 VM_TEST_CASE(FieldTests) { | 3103 VM_TEST_CASE(FieldTests) { |
3142 const String& f = String::Handle(String::New("oneField")); | 3104 const String& f = String::Handle(String::New("oneField")); |
3143 const String& getter_f = String::Handle(Field::GetterName(f)); | 3105 const String& getter_f = String::Handle(Field::GetterName(f)); |
3144 const String& setter_f = String::Handle(Field::SetterName(f)); | 3106 const String& setter_f = String::Handle(Field::SetterName(f)); |
3145 EXPECT(!Field::IsGetterName(f)); | 3107 EXPECT(!Field::IsGetterName(f)); |
3146 EXPECT(!Field::IsSetterName(f)); | 3108 EXPECT(!Field::IsSetterName(f)); |
3147 EXPECT(Field::IsGetterName(getter_f)); | 3109 EXPECT(Field::IsGetterName(getter_f)); |
3148 EXPECT(!Field::IsSetterName(getter_f)); | 3110 EXPECT(!Field::IsSetterName(getter_f)); |
3149 EXPECT(!Field::IsGetterName(setter_f)); | 3111 EXPECT(!Field::IsGetterName(setter_f)); |
3150 EXPECT(Field::IsSetterName(setter_f)); | 3112 EXPECT(Field::IsSetterName(setter_f)); |
3151 EXPECT_STREQ(f.ToCString(), | 3113 EXPECT_STREQ(f.ToCString(), |
3152 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); | 3114 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); |
3153 EXPECT_STREQ(f.ToCString(), | 3115 EXPECT_STREQ(f.ToCString(), |
3154 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); | 3116 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); |
3155 } | 3117 } |
3156 | 3118 |
3157 | 3119 |
3158 | |
3159 | |
3160 // Expose helper function from object.cc for testing. | 3120 // Expose helper function from object.cc for testing. |
3161 bool EqualsIgnoringPrivate(const String& name, const String& private_name); | 3121 bool EqualsIgnoringPrivate(const String& name, const String& private_name); |
3162 | 3122 |
3163 | 3123 |
3164 VM_TEST_CASE(EqualsIgnoringPrivate) { | 3124 VM_TEST_CASE(EqualsIgnoringPrivate) { |
3165 String& mangled_name = String::Handle(); | 3125 String& mangled_name = String::Handle(); |
3166 String& bare_name = String::Handle(); | 3126 String& bare_name = String::Handle(); |
3167 | 3127 |
3168 // Simple matches. | 3128 // Simple matches. |
3169 mangled_name = OneByteString::New("foo"); | 3129 mangled_name = OneByteString::New("foo"); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3264 const char* ext_bad_bare_str = "foo.named"; | 3224 const char* ext_bad_bare_str = "foo.named"; |
3265 String& ext_mangled_name = String::Handle(); | 3225 String& ext_mangled_name = String::Handle(); |
3266 String& ext_bare_name = String::Handle(); | 3226 String& ext_bare_name = String::Handle(); |
3267 String& ext_bad_bare_name = String::Handle(); | 3227 String& ext_bad_bare_name = String::Handle(); |
3268 | 3228 |
3269 mangled_name = OneByteString::New("foo@12345.name@12345"); | 3229 mangled_name = OneByteString::New("foo@12345.name@12345"); |
3270 ext_mangled_name = ExternalOneByteString::New( | 3230 ext_mangled_name = ExternalOneByteString::New( |
3271 reinterpret_cast<const uint8_t*>(ext_mangled_str), | 3231 reinterpret_cast<const uint8_t*>(ext_mangled_str), |
3272 strlen(ext_mangled_str), NULL, NULL, Heap::kNew); | 3232 strlen(ext_mangled_str), NULL, NULL, Heap::kNew); |
3273 EXPECT(ext_mangled_name.IsExternalOneByteString()); | 3233 EXPECT(ext_mangled_name.IsExternalOneByteString()); |
3274 ext_bare_name = ExternalOneByteString::New( | 3234 ext_bare_name = |
3275 reinterpret_cast<const uint8_t*>(ext_bare_str), | 3235 ExternalOneByteString::New(reinterpret_cast<const uint8_t*>(ext_bare_str), |
3276 strlen(ext_bare_str), NULL, NULL, Heap::kNew); | 3236 strlen(ext_bare_str), NULL, NULL, Heap::kNew); |
3277 EXPECT(ext_bare_name.IsExternalOneByteString()); | 3237 EXPECT(ext_bare_name.IsExternalOneByteString()); |
3278 ext_bad_bare_name = ExternalOneByteString::New( | 3238 ext_bad_bare_name = ExternalOneByteString::New( |
3279 reinterpret_cast<const uint8_t*>(ext_bad_bare_str), | 3239 reinterpret_cast<const uint8_t*>(ext_bad_bare_str), |
3280 strlen(ext_bad_bare_str), NULL, NULL, Heap::kNew); | 3240 strlen(ext_bad_bare_str), NULL, NULL, Heap::kNew); |
3281 EXPECT(ext_bad_bare_name.IsExternalOneByteString()); | 3241 EXPECT(ext_bad_bare_name.IsExternalOneByteString()); |
3282 | 3242 |
3283 // str1 - OneByteString, str2 - ExternalOneByteString. | 3243 // str1 - OneByteString, str2 - ExternalOneByteString. |
3284 EXPECT(String::EqualsIgnoringPrivateKey(mangled_name, ext_bare_name)); | 3244 EXPECT(String::EqualsIgnoringPrivateKey(mangled_name, ext_bare_name)); |
3285 EXPECT(!String::EqualsIgnoringPrivateKey(mangled_name, ext_bad_bare_name)); | 3245 EXPECT(!String::EqualsIgnoringPrivateKey(mangled_name, ext_bad_bare_name)); |
3286 | 3246 |
3287 // str1 - ExternalOneByteString, str2 - OneByteString. | 3247 // str1 - ExternalOneByteString, str2 - OneByteString. |
3288 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, bare_name)); | 3248 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, bare_name)); |
3289 | 3249 |
3290 // str1 - ExternalOneByteString, str2 - ExternalOneByteString. | 3250 // str1 - ExternalOneByteString, str2 - ExternalOneByteString. |
3291 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bare_name)); | 3251 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bare_name)); |
3292 EXPECT(!String::EqualsIgnoringPrivateKey(ext_mangled_name, | 3252 EXPECT( |
3293 ext_bad_bare_name)); | 3253 !String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bad_bare_name)); |
3294 } | 3254 } |
3295 | 3255 |
3296 | 3256 |
3297 VM_TEST_CASE(ArrayNew_Overflow_Crash) { | 3257 VM_TEST_CASE(ArrayNew_Overflow_Crash) { |
3298 Array::Handle(Array::New(Array::kMaxElements + 1)); | 3258 Array::Handle(Array::New(Array::kMaxElements + 1)); |
3299 } | 3259 } |
3300 | 3260 |
3301 | 3261 |
3302 TEST_CASE(StackTraceFormat) { | 3262 TEST_CASE(StackTraceFormat) { |
3303 const char* kScriptChars = | 3263 const char* kScriptChars = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3335 " fooHelper();\n" | 3295 " fooHelper();\n" |
3336 " }\n" | 3296 " }\n" |
3337 "}\n" | 3297 "}\n" |
3338 "\n" | 3298 "\n" |
3339 "main() {\n" | 3299 "main() {\n" |
3340 " (() => new MyClass())();\n" | 3300 " (() => new MyClass())();\n" |
3341 "}\n"; | 3301 "}\n"; |
3342 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3302 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3343 EXPECT_VALID(lib); | 3303 EXPECT_VALID(lib); |
3344 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 3304 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
3345 EXPECT_ERROR( | 3305 EXPECT_ERROR(result, |
3346 result, | 3306 "Unhandled exception:\n" |
3347 "Unhandled exception:\n" | 3307 "MyException\n" |
3348 "MyException\n" | 3308 "#0 baz (test-lib:2:3)\n" |
3349 "#0 baz (test-lib:2:3)\n" | 3309 "#1 _OtherClass._OtherClass._named (test-lib:7:5)\n" |
3350 "#1 _OtherClass._OtherClass._named (test-lib:7:5)\n" | 3310 "#2 globalVar= (test-lib:12:7)\n" |
3351 "#2 globalVar= (test-lib:12:7)\n" | 3311 "#3 _bar (test-lib:16:3)\n" |
3352 "#3 _bar (test-lib:16:3)\n" | 3312 "#4 MyClass.field (test-lib:25:5)\n" |
3353 "#4 MyClass.field (test-lib:25:5)\n" | 3313 "#5 MyClass.foo.fooHelper (test-lib:30:7)\n" |
3354 "#5 MyClass.foo.fooHelper (test-lib:30:7)\n" | 3314 "#6 MyClass.foo (test-lib:32:14)\n" |
3355 "#6 MyClass.foo (test-lib:32:14)\n" | 3315 "#7 MyClass.MyClass.<anonymous closure> (test-lib:21:12)\n" |
3356 "#7 MyClass.MyClass.<anonymous closure> (test-lib:21:12)\n" | 3316 "#8 MyClass.MyClass (test-lib:21:18)\n" |
3357 "#8 MyClass.MyClass (test-lib:21:18)\n" | 3317 "#9 main.<anonymous closure> (test-lib:37:14)\n" |
3358 "#9 main.<anonymous closure> (test-lib:37:14)\n" | 3318 "#10 main (test-lib:37:24)"); |
3359 "#10 main (test-lib:37:24)"); | |
3360 } | 3319 } |
3361 | 3320 |
3362 | 3321 |
3363 VM_TEST_CASE(WeakProperty_PreserveCrossGen) { | 3322 VM_TEST_CASE(WeakProperty_PreserveCrossGen) { |
3364 Isolate* isolate = Isolate::Current(); | 3323 Isolate* isolate = Isolate::Current(); |
3365 WeakProperty& weak = WeakProperty::Handle(); | 3324 WeakProperty& weak = WeakProperty::Handle(); |
3366 { | 3325 { |
3367 // Weak property and value in new. Key in old. | 3326 // Weak property and value in new. Key in old. |
3368 HANDLESCOPE(thread); | 3327 HANDLESCOPE(thread); |
3369 String& key = String::Handle(); | 3328 String& key = String::Handle(); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3761 other_reference.set_referent(library); | 3720 other_reference.set_referent(library); |
3762 EXPECT_NE(reference.raw(), other_reference.raw()); | 3721 EXPECT_NE(reference.raw(), other_reference.raw()); |
3763 EXPECT_EQ(reference.referent(), other_reference.referent()); | 3722 EXPECT_EQ(reference.referent(), other_reference.referent()); |
3764 | 3723 |
3765 Object& obj = Object::Handle(reference.raw()); | 3724 Object& obj = Object::Handle(reference.raw()); |
3766 EXPECT(obj.IsMirrorReference()); | 3725 EXPECT(obj.IsMirrorReference()); |
3767 } | 3726 } |
3768 | 3727 |
3769 | 3728 |
3770 static RawFunction* GetFunction(const Class& cls, const char* name) { | 3729 static RawFunction* GetFunction(const Class& cls, const char* name) { |
3771 const Function& result = Function::Handle(cls.LookupDynamicFunction( | 3730 const Function& result = Function::Handle( |
3772 String::Handle(String::New(name)))); | 3731 cls.LookupDynamicFunction(String::Handle(String::New(name)))); |
3773 EXPECT(!result.IsNull()); | 3732 EXPECT(!result.IsNull()); |
3774 return result.raw(); | 3733 return result.raw(); |
3775 } | 3734 } |
3776 | 3735 |
3777 | 3736 |
3778 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { | 3737 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { |
3779 const Function& result = Function::Handle(cls.LookupStaticFunction( | 3738 const Function& result = Function::Handle( |
3780 String::Handle(String::New(name)))); | 3739 cls.LookupStaticFunction(String::Handle(String::New(name)))); |
3781 EXPECT(!result.IsNull()); | 3740 EXPECT(!result.IsNull()); |
3782 return result.raw(); | 3741 return result.raw(); |
3783 } | 3742 } |
3784 | 3743 |
3785 | 3744 |
3786 static RawField* GetField(const Class& cls, const char* name) { | 3745 static RawField* GetField(const Class& cls, const char* name) { |
3787 const Field& field = | 3746 const Field& field = |
3788 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); | 3747 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); |
3789 EXPECT(!field.IsNull()); | 3748 EXPECT(!field.IsNull()); |
3790 return field.raw(); | 3749 return field.raw(); |
(...skipping 11 matching lines...) Expand all Loading... |
3802 VM_TEST_CASE(FindClosureIndex) { | 3761 VM_TEST_CASE(FindClosureIndex) { |
3803 // Allocate the class first. | 3762 // Allocate the class first. |
3804 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 3763 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
3805 const Script& script = Script::Handle(); | 3764 const Script& script = Script::Handle(); |
3806 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3765 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
3807 const Array& functions = Array::Handle(Array::New(1)); | 3766 const Array& functions = Array::Handle(Array::New(1)); |
3808 const Isolate* iso = Isolate::Current(); | 3767 const Isolate* iso = Isolate::Current(); |
3809 | 3768 |
3810 Function& parent = Function::Handle(); | 3769 Function& parent = Function::Handle(); |
3811 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); | 3770 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
3812 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 3771 parent = |
3813 false, false, false, false, false, cls, | 3772 Function::New(parent_name, RawFunction::kRegularFunction, false, false, |
3814 TokenPosition::kMinSource); | 3773 false, false, false, cls, TokenPosition::kMinSource); |
3815 functions.SetAt(0, parent); | 3774 functions.SetAt(0, parent); |
3816 cls.SetFunctions(functions); | 3775 cls.SetFunctions(functions); |
3817 | 3776 |
3818 Function& function = Function::Handle(); | 3777 Function& function = Function::Handle(); |
3819 const String& function_name = String::Handle(Symbols::New(thread, "foo")); | 3778 const String& function_name = String::Handle(Symbols::New(thread, "foo")); |
3820 function = Function::NewClosureFunction(function_name, parent, | 3779 function = Function::NewClosureFunction(function_name, parent, |
3821 TokenPosition::kMinSource); | 3780 TokenPosition::kMinSource); |
3822 // Add closure function to class. | 3781 // Add closure function to class. |
3823 iso->AddClosureFunction(function); | 3782 iso->AddClosureFunction(function); |
3824 | 3783 |
(...skipping 14 matching lines...) Expand all Loading... |
3839 | 3798 |
3840 VM_TEST_CASE(FindInvocationDispatcherFunctionIndex) { | 3799 VM_TEST_CASE(FindInvocationDispatcherFunctionIndex) { |
3841 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 3800 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
3842 const Script& script = Script::Handle(); | 3801 const Script& script = Script::Handle(); |
3843 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3802 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
3844 ClassFinalizer::FinalizeTypesInClass(cls); | 3803 ClassFinalizer::FinalizeTypesInClass(cls); |
3845 | 3804 |
3846 const Array& functions = Array::Handle(Array::New(1)); | 3805 const Array& functions = Array::Handle(Array::New(1)); |
3847 Function& parent = Function::Handle(); | 3806 Function& parent = Function::Handle(); |
3848 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); | 3807 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
3849 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 3808 parent = |
3850 false, false, false, false, false, cls, | 3809 Function::New(parent_name, RawFunction::kRegularFunction, false, false, |
3851 TokenPosition::kMinSource); | 3810 false, false, false, cls, TokenPosition::kMinSource); |
3852 functions.SetAt(0, parent); | 3811 functions.SetAt(0, parent); |
3853 cls.SetFunctions(functions); | 3812 cls.SetFunctions(functions); |
3854 cls.Finalize(); | 3813 cls.Finalize(); |
3855 | 3814 |
3856 // Add invocation dispatcher. | 3815 // Add invocation dispatcher. |
3857 const String& invocation_dispatcher_name = | 3816 const String& invocation_dispatcher_name = |
3858 String::Handle(Symbols::New(thread, "myMethod")); | 3817 String::Handle(Symbols::New(thread, "myMethod")); |
3859 const Array& args_desc = Array::Handle(ArgumentsDescriptor::New(1)); | 3818 const Array& args_desc = Array::Handle(ArgumentsDescriptor::New(1)); |
3860 Function& invocation_dispatcher = Function::Handle(); | 3819 Function& invocation_dispatcher = Function::Handle(); |
3861 invocation_dispatcher ^= | 3820 invocation_dispatcher ^= cls.GetInvocationDispatcher( |
3862 cls.GetInvocationDispatcher(invocation_dispatcher_name, args_desc, | 3821 invocation_dispatcher_name, args_desc, |
3863 RawFunction::kNoSuchMethodDispatcher, | 3822 RawFunction::kNoSuchMethodDispatcher, true /* create_if_absent */); |
3864 true /* create_if_absent */); | |
3865 EXPECT(!invocation_dispatcher.IsNull()); | 3823 EXPECT(!invocation_dispatcher.IsNull()); |
3866 // Get index to function. | 3824 // Get index to function. |
3867 intptr_t invocation_dispatcher_index = | 3825 intptr_t invocation_dispatcher_index = |
3868 cls.FindInvocationDispatcherFunctionIndex(invocation_dispatcher); | 3826 cls.FindInvocationDispatcherFunctionIndex(invocation_dispatcher); |
3869 // Expect a valid index. | 3827 // Expect a valid index. |
3870 EXPECT_GE(invocation_dispatcher_index, 0); | 3828 EXPECT_GE(invocation_dispatcher_index, 0); |
3871 // Retrieve function through index. | 3829 // Retrieve function through index. |
3872 Function& invocation_dispatcher_from_index = Function::Handle(); | 3830 Function& invocation_dispatcher_from_index = Function::Handle(); |
3873 invocation_dispatcher_from_index ^= | 3831 invocation_dispatcher_from_index ^= |
3874 cls.InvocationDispatcherFunctionFromIndex(invocation_dispatcher_index); | 3832 cls.InvocationDispatcherFunctionFromIndex(invocation_dispatcher_index); |
3875 // Same function. | 3833 // Same function. |
3876 EXPECT_EQ(invocation_dispatcher.raw(), | 3834 EXPECT_EQ(invocation_dispatcher.raw(), |
3877 invocation_dispatcher_from_index.raw()); | 3835 invocation_dispatcher_from_index.raw()); |
3878 // Test function not found case. | 3836 // Test function not found case. |
3879 const Function& bad_function = Function::Handle(Function::null()); | 3837 const Function& bad_function = Function::Handle(Function::null()); |
3880 intptr_t bad_invocation_dispatcher_index = | 3838 intptr_t bad_invocation_dispatcher_index = |
3881 cls.FindInvocationDispatcherFunctionIndex(bad_function); | 3839 cls.FindInvocationDispatcherFunctionIndex(bad_function); |
3882 EXPECT_EQ(bad_invocation_dispatcher_index, -1); | 3840 EXPECT_EQ(bad_invocation_dispatcher_index, -1); |
3883 } | 3841 } |
3884 | 3842 |
3885 | 3843 |
3886 static void PrintMetadata(const char* name, const Object& data) { | 3844 static void PrintMetadata(const char* name, const Object& data) { |
3887 if (data.IsError()) { | 3845 if (data.IsError()) { |
3888 OS::Print("Error in metadata evaluation for %s: '%s'\n", | 3846 OS::Print("Error in metadata evaluation for %s: '%s'\n", name, |
3889 name, | |
3890 Error::Cast(data).ToErrorCString()); | 3847 Error::Cast(data).ToErrorCString()); |
3891 } | 3848 } |
3892 EXPECT(data.IsArray()); | 3849 EXPECT(data.IsArray()); |
3893 const Array& metadata = Array::Cast(data); | 3850 const Array& metadata = Array::Cast(data); |
3894 OS::Print("Metadata for %s has %" Pd " values:\n", name, metadata.Length()); | 3851 OS::Print("Metadata for %s has %" Pd " values:\n", name, metadata.Length()); |
3895 Object& elem = Object::Handle(); | 3852 Object& elem = Object::Handle(); |
3896 for (int i = 0; i < metadata.Length(); i++) { | 3853 for (int i = 0; i < metadata.Length(); i++) { |
3897 elem = metadata.At(i); | 3854 elem = metadata.At(i); |
3898 OS::Print(" %d: %s\n", i, elem.ToCString()); | 3855 OS::Print(" %d: %s\n", i, elem.ToCString()); |
3899 } | 3856 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3954 | 3911 |
3955 Function& func = Function::Handle(GetFunction(class_a, "aFunc")); | 3912 Function& func = Function::Handle(GetFunction(class_a, "aFunc")); |
3956 res = lib.GetMetadata(func); | 3913 res = lib.GetMetadata(func); |
3957 PrintMetadata("A.aFunc", res); | 3914 PrintMetadata("A.aFunc", res); |
3958 | 3915 |
3959 func = lib.LookupLocalFunction(String::Handle(Symbols::New(thread, "main"))); | 3916 func = lib.LookupLocalFunction(String::Handle(Symbols::New(thread, "main"))); |
3960 EXPECT(!func.IsNull()); | 3917 EXPECT(!func.IsNull()); |
3961 res = lib.GetMetadata(func); | 3918 res = lib.GetMetadata(func); |
3962 PrintMetadata("main", res); | 3919 PrintMetadata("main", res); |
3963 | 3920 |
3964 func = lib.LookupLocalFunction(String::Handle(Symbols::New(thread, | 3921 func = lib.LookupLocalFunction( |
3965 "get:tlGetter"))); | 3922 String::Handle(Symbols::New(thread, "get:tlGetter"))); |
3966 EXPECT(!func.IsNull()); | 3923 EXPECT(!func.IsNull()); |
3967 res = lib.GetMetadata(func); | 3924 res = lib.GetMetadata(func); |
3968 PrintMetadata("tlGetter", res); | 3925 PrintMetadata("tlGetter", res); |
3969 | 3926 |
3970 field = lib.LookupLocalField(String::Handle(Symbols::New(thread, "gVar"))); | 3927 field = lib.LookupLocalField(String::Handle(Symbols::New(thread, "gVar"))); |
3971 EXPECT(!field.IsNull()); | 3928 EXPECT(!field.IsNull()); |
3972 res = lib.GetMetadata(field); | 3929 res = lib.GetMetadata(field); |
3973 PrintMetadata("gVar", res); | 3930 PrintMetadata("gVar", res); |
3974 } | 3931 } |
3975 | 3932 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4011 " void test6(int a) {\n" | 3968 " void test6(int a) {\n" |
4012 " return a > 1 ? a + 1 : a;\n" | 3969 " return a > 1 ? a + 1 : a;\n" |
4013 " }\n" | 3970 " }\n" |
4014 "}"; | 3971 "}"; |
4015 TestCase::LoadTestScript(kScriptChars, NULL); | 3972 TestCase::LoadTestScript(kScriptChars, NULL); |
4016 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 3973 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
4017 const String& name = String::Handle(String::New(TestCase::url())); | 3974 const String& name = String::Handle(String::New(TestCase::url())); |
4018 const Library& lib = Library::Handle(Library::LookupLibrary(thread, name)); | 3975 const Library& lib = Library::Handle(Library::LookupLibrary(thread, name)); |
4019 EXPECT(!lib.IsNull()); | 3976 EXPECT(!lib.IsNull()); |
4020 | 3977 |
4021 const Class& class_a = Class::Handle( | 3978 const Class& class_a = |
4022 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); | 3979 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
4023 const Class& class_b = Class::Handle( | 3980 const Class& class_b = |
4024 lib.LookupClass(String::Handle(Symbols::New(thread, "B")))); | 3981 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "B")))); |
4025 const Function& a_test1 = | 3982 const Function& a_test1 = |
4026 Function::Handle(GetStaticFunction(class_a, "test1")); | 3983 Function::Handle(GetStaticFunction(class_a, "test1")); |
4027 const Function& b_test1 = | 3984 const Function& b_test1 = |
4028 Function::Handle(GetStaticFunction(class_b, "test1")); | 3985 Function::Handle(GetStaticFunction(class_b, "test1")); |
4029 const Function& a_test2 = | 3986 const Function& a_test2 = |
4030 Function::Handle(GetStaticFunction(class_a, "test2")); | 3987 Function::Handle(GetStaticFunction(class_a, "test2")); |
4031 const Function& a_test3 = | 3988 const Function& a_test3 = |
4032 Function::Handle(GetStaticFunction(class_a, "test3")); | 3989 Function::Handle(GetStaticFunction(class_a, "test3")); |
4033 const Function& a_test4 = | 3990 const Function& a_test4 = |
4034 Function::Handle(GetStaticFunction(class_a, "test4")); | 3991 Function::Handle(GetStaticFunction(class_a, "test4")); |
4035 const Function& a_test5 = | 3992 const Function& a_test5 = |
4036 Function::Handle(GetStaticFunction(class_a, "test5")); | 3993 Function::Handle(GetStaticFunction(class_a, "test5")); |
4037 const Function& b_test5 = | 3994 const Function& b_test5 = |
4038 Function::Handle(GetStaticFunction(class_b, "test5")); | 3995 Function::Handle(GetStaticFunction(class_b, "test5")); |
4039 const Function& a_test6 = | 3996 const Function& a_test6 = Function::Handle(GetFunction(class_a, "test6")); |
4040 Function::Handle(GetFunction(class_a, "test6")); | 3997 const Function& b_test6 = Function::Handle(GetFunction(class_b, "test6")); |
4041 const Function& b_test6 = | |
4042 Function::Handle(GetFunction(class_b, "test6")); | |
4043 | 3998 |
4044 EXPECT_EQ(a_test1.SourceFingerprint(), b_test1.SourceFingerprint()); | 3999 EXPECT_EQ(a_test1.SourceFingerprint(), b_test1.SourceFingerprint()); |
4045 EXPECT_NE(a_test1.SourceFingerprint(), a_test2.SourceFingerprint()); | 4000 EXPECT_NE(a_test1.SourceFingerprint(), a_test2.SourceFingerprint()); |
4046 EXPECT_NE(a_test2.SourceFingerprint(), a_test3.SourceFingerprint()); | 4001 EXPECT_NE(a_test2.SourceFingerprint(), a_test3.SourceFingerprint()); |
4047 EXPECT_NE(a_test3.SourceFingerprint(), a_test4.SourceFingerprint()); | 4002 EXPECT_NE(a_test3.SourceFingerprint(), a_test4.SourceFingerprint()); |
4048 EXPECT_NE(a_test4.SourceFingerprint(), a_test5.SourceFingerprint()); | 4003 EXPECT_NE(a_test4.SourceFingerprint(), a_test5.SourceFingerprint()); |
4049 EXPECT_EQ(a_test5.SourceFingerprint(), b_test5.SourceFingerprint()); | 4004 EXPECT_EQ(a_test5.SourceFingerprint(), b_test5.SourceFingerprint()); |
4050 // Although a_test6's receiver type is different than b_test6's receiver type, | 4005 // Although a_test6's receiver type is different than b_test6's receiver type, |
4051 // the fingerprints are identical. The token stream does not reflect the | 4006 // the fingerprints are identical. The token stream does not reflect the |
4052 // receiver's type. This is not a problem, since we recognize functions | 4007 // receiver's type. This is not a problem, since we recognize functions |
(...skipping 24 matching lines...) Expand all Loading... |
4077 // Run function A.b one time. | 4032 // Run function A.b one time. |
4078 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 0, NULL); | 4033 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 0, NULL); |
4079 EXPECT_VALID(result); | 4034 EXPECT_VALID(result); |
4080 | 4035 |
4081 // With no breakpoint, function A.b is inlineable. | 4036 // With no breakpoint, function A.b is inlineable. |
4082 const String& name = String::Handle(String::New(TestCase::url())); | 4037 const String& name = String::Handle(String::New(TestCase::url())); |
4083 const Library& vmlib = Library::Handle(Library::LookupLibrary(thread, name)); | 4038 const Library& vmlib = Library::Handle(Library::LookupLibrary(thread, name)); |
4084 EXPECT(!vmlib.IsNull()); | 4039 EXPECT(!vmlib.IsNull()); |
4085 const Class& class_a = Class::Handle( | 4040 const Class& class_a = Class::Handle( |
4086 vmlib.LookupClass(String::Handle(Symbols::New(thread, "A")))); | 4041 vmlib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
4087 const Function& func_b = | 4042 const Function& func_b = Function::Handle(GetFunction(class_a, "b")); |
4088 Function::Handle(GetFunction(class_a, "b")); | |
4089 EXPECT(func_b.CanBeInlined()); | 4043 EXPECT(func_b.CanBeInlined()); |
4090 | 4044 |
4091 // After setting a breakpoint in a function A.b, it is no longer inlineable. | 4045 // After setting a breakpoint in a function A.b, it is no longer inlineable. |
4092 result = Dart_SetBreakpoint(NewString(TestCase::url()), kBreakpointLine); | 4046 result = Dart_SetBreakpoint(NewString(TestCase::url()), kBreakpointLine); |
4093 EXPECT_VALID(result); | 4047 EXPECT_VALID(result); |
4094 EXPECT(!func_b.CanBeInlined()); | 4048 EXPECT(!func_b.CanBeInlined()); |
4095 } | 4049 } |
4096 | 4050 |
4097 | 4051 |
4098 VM_TEST_CASE(SpecialClassesHaveEmptyArrays) { | 4052 VM_TEST_CASE(SpecialClassesHaveEmptyArrays) { |
(...skipping 26 matching lines...) Expand all Loading... |
4125 EXPECT(array.IsArray()); | 4079 EXPECT(array.IsArray()); |
4126 } | 4080 } |
4127 | 4081 |
4128 | 4082 |
4129 #ifndef PRODUCT | 4083 #ifndef PRODUCT |
4130 | 4084 |
4131 | 4085 |
4132 class ObjectAccumulator : public ObjectVisitor { | 4086 class ObjectAccumulator : public ObjectVisitor { |
4133 public: | 4087 public: |
4134 explicit ObjectAccumulator(GrowableArray<Object*>* objects) | 4088 explicit ObjectAccumulator(GrowableArray<Object*>* objects) |
4135 : objects_(objects) { } | 4089 : objects_(objects) {} |
4136 virtual ~ObjectAccumulator() { } | 4090 virtual ~ObjectAccumulator() {} |
4137 virtual void VisitObject(RawObject* obj) { | 4091 virtual void VisitObject(RawObject* obj) { |
4138 if (obj->IsPseudoObject()) { | 4092 if (obj->IsPseudoObject()) { |
4139 return; // Cannot be wrapped in handles. | 4093 return; // Cannot be wrapped in handles. |
4140 } | 4094 } |
4141 Object& handle = Object::Handle(obj); | 4095 Object& handle = Object::Handle(obj); |
4142 // Skip some common simple objects to run in reasonable time. | 4096 // Skip some common simple objects to run in reasonable time. |
4143 if (handle.IsString() || | 4097 if (handle.IsString() || handle.IsArray() || handle.IsLiteralToken()) { |
4144 handle.IsArray() || | |
4145 handle.IsLiteralToken()) { | |
4146 return; | 4098 return; |
4147 } | 4099 } |
4148 objects_->Add(&handle); | 4100 objects_->Add(&handle); |
4149 } | 4101 } |
| 4102 |
4150 private: | 4103 private: |
4151 GrowableArray<Object*>* objects_; | 4104 GrowableArray<Object*>* objects_; |
4152 }; | 4105 }; |
4153 | 4106 |
4154 | 4107 |
4155 VM_TEST_CASE(PrintJSON) { | 4108 VM_TEST_CASE(PrintJSON) { |
4156 Heap* heap = Isolate::Current()->heap(); | 4109 Heap* heap = Isolate::Current()->heap(); |
4157 heap->CollectAllGarbage(); | 4110 heap->CollectAllGarbage(); |
4158 GrowableArray<Object*> objects; | 4111 GrowableArray<Object*> objects; |
4159 ObjectAccumulator acc(&objects); | 4112 ObjectAccumulator acc(&objects); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4622 | 4575 |
4623 static void CheckConcatAll(const String* data[], intptr_t n) { | 4576 static void CheckConcatAll(const String* data[], intptr_t n) { |
4624 Thread* thread = Thread::Current(); | 4577 Thread* thread = Thread::Current(); |
4625 Zone* zone = thread->zone(); | 4578 Zone* zone = thread->zone(); |
4626 GrowableHandlePtrArray<const String> pieces(zone, n); | 4579 GrowableHandlePtrArray<const String> pieces(zone, n); |
4627 const Array& array = Array::Handle(zone, Array::New(n)); | 4580 const Array& array = Array::Handle(zone, Array::New(n)); |
4628 for (int i = 0; i < n; i++) { | 4581 for (int i = 0; i < n; i++) { |
4629 pieces.Add(*data[i]); | 4582 pieces.Add(*data[i]); |
4630 array.SetAt(i, *data[i]); | 4583 array.SetAt(i, *data[i]); |
4631 } | 4584 } |
4632 const String& res1 = String::Handle(zone, Symbols::FromConcatAll(thread, | 4585 const String& res1 = |
4633 pieces)); | 4586 String::Handle(zone, Symbols::FromConcatAll(thread, pieces)); |
4634 const String& res2 = String::Handle(zone, String::ConcatAll(array)); | 4587 const String& res2 = String::Handle(zone, String::ConcatAll(array)); |
4635 EXPECT(res1.Equals(res2)); | 4588 EXPECT(res1.Equals(res2)); |
4636 } | 4589 } |
4637 | 4590 |
4638 | 4591 |
4639 VM_TEST_CASE(Symbols_FromConcatAll) { | 4592 VM_TEST_CASE(Symbols_FromConcatAll) { |
4640 { | 4593 { |
4641 const String* data[3] = { &Symbols::FallThroughError(), | 4594 const String* data[3] = {&Symbols::FallThroughError(), &Symbols::Dot(), |
4642 &Symbols::Dot(), | 4595 &Symbols::isPaused()}; |
4643 &Symbols::isPaused() }; | |
4644 CheckConcatAll(data, 3); | 4596 CheckConcatAll(data, 3); |
4645 } | 4597 } |
4646 | 4598 |
4647 { | 4599 { |
4648 const intptr_t kWideCharsLen = 7; | 4600 const intptr_t kWideCharsLen = 7; |
4649 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; | 4601 uint16_t wide_chars[kWideCharsLen] = {'H', 'e', 'l', 'l', 'o', 256, '!'}; |
4650 const String& two_str = String::Handle(String::FromUTF16(wide_chars, | 4602 const String& two_str = |
4651 kWideCharsLen)); | 4603 String::Handle(String::FromUTF16(wide_chars, kWideCharsLen)); |
4652 | 4604 |
4653 const String* data[3] = { &two_str, &Symbols::Dot(), &two_str }; | 4605 const String* data[3] = {&two_str, &Symbols::Dot(), &two_str}; |
4654 CheckConcatAll(data, 3); | 4606 CheckConcatAll(data, 3); |
4655 } | 4607 } |
4656 | 4608 |
4657 { | 4609 { |
4658 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 }; | 4610 uint8_t characters[] = {0xF6, 0xF1, 0xE9}; |
4659 intptr_t len = ARRAY_SIZE(characters); | 4611 intptr_t len = ARRAY_SIZE(characters); |
4660 | 4612 |
4661 const String& str = String::Handle( | 4613 const String& str = String::Handle( |
4662 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); | 4614 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
4663 const String* data[3] = { &str, &Symbols::Dot(), &str }; | 4615 const String* data[3] = {&str, &Symbols::Dot(), &str}; |
4664 CheckConcatAll(data, 3); | 4616 CheckConcatAll(data, 3); |
4665 } | 4617 } |
4666 | 4618 |
4667 { | 4619 { |
4668 uint16_t characters[] = | 4620 uint16_t characters[] = {'a', '\n', '\f', '\b', '\t', |
4669 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; | 4621 '\v', '\r', '\\', '$', 'z'}; |
4670 intptr_t len = ARRAY_SIZE(characters); | 4622 intptr_t len = ARRAY_SIZE(characters); |
4671 | 4623 |
4672 const String& str = String::Handle( | 4624 const String& str = String::Handle( |
4673 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); | 4625 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
4674 const String* data[3] = { &str, &Symbols::Dot(), &str }; | 4626 const String* data[3] = {&str, &Symbols::Dot(), &str}; |
4675 CheckConcatAll(data, 3); | 4627 CheckConcatAll(data, 3); |
4676 } | 4628 } |
4677 | 4629 |
4678 { | 4630 { |
4679 uint8_t characters1[] = { 0xF6, 0xF1, 0xE9 }; | 4631 uint8_t characters1[] = {0xF6, 0xF1, 0xE9}; |
4680 intptr_t len1 = ARRAY_SIZE(characters1); | 4632 intptr_t len1 = ARRAY_SIZE(characters1); |
4681 | 4633 |
4682 const String& str1 = String::Handle( | 4634 const String& str1 = String::Handle( |
4683 ExternalOneByteString::New(characters1, len1, NULL, NULL, Heap::kNew)); | 4635 ExternalOneByteString::New(characters1, len1, NULL, NULL, Heap::kNew)); |
4684 | 4636 |
4685 uint16_t characters2[] = | 4637 uint16_t characters2[] = {'a', '\n', '\f', '\b', '\t', |
4686 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; | 4638 '\v', '\r', '\\', '$', 'z'}; |
4687 intptr_t len2 = ARRAY_SIZE(characters2); | 4639 intptr_t len2 = ARRAY_SIZE(characters2); |
4688 | 4640 |
4689 const String& str2 = String::Handle( | 4641 const String& str2 = String::Handle( |
4690 ExternalTwoByteString::New(characters2, len2, NULL, NULL, Heap::kNew)); | 4642 ExternalTwoByteString::New(characters2, len2, NULL, NULL, Heap::kNew)); |
4691 const String* data[3] = { &str1, &Symbols::Dot(), &str2 }; | 4643 const String* data[3] = {&str1, &Symbols::Dot(), &str2}; |
4692 CheckConcatAll(data, 3); | 4644 CheckConcatAll(data, 3); |
4693 } | 4645 } |
4694 | 4646 |
4695 { | 4647 { |
4696 const String& empty = String::Handle(String::New("")); | 4648 const String& empty = String::Handle(String::New("")); |
4697 const String* data[3] = { &Symbols::FallThroughError(), | 4649 const String* data[3] = {&Symbols::FallThroughError(), &empty, |
4698 &empty, | 4650 &Symbols::isPaused()}; |
4699 &Symbols::isPaused() }; | |
4700 CheckConcatAll(data, 3); | 4651 CheckConcatAll(data, 3); |
4701 } | 4652 } |
4702 } | 4653 } |
4703 | 4654 |
4704 | 4655 |
4705 struct TestResult { | 4656 struct TestResult { |
4706 const char* in; | 4657 const char* in; |
4707 const char* out; | 4658 const char* out; |
4708 }; | 4659 }; |
4709 | 4660 |
4710 | 4661 |
4711 VM_TEST_CASE(String_ScrubName) { | 4662 VM_TEST_CASE(String_ScrubName) { |
4712 TestResult tests[] = { | 4663 TestResult tests[] = { |
4713 {"(dynamic, dynamic) => void", "(dynamic, dynamic) => void"}, | 4664 {"(dynamic, dynamic) => void", "(dynamic, dynamic) => void"}, |
4714 {"_List@915557746", "_List"}, | 4665 {"_List@915557746", "_List"}, |
4715 {"_HashMap@600006304<K, V>(dynamic) => V", "_HashMap<K, V>(dynamic) => V"}, | 4666 {"_HashMap@600006304<K, V>(dynamic) => V", |
4716 {"set:foo", "foo="}, | 4667 "_HashMap<K, V>(dynamic) => V"}, |
4717 {"get:foo", "foo"}, | 4668 {"set:foo", "foo="}, |
4718 {"_ReceivePortImpl@709387912", "_ReceivePortImpl"}, | 4669 {"get:foo", "foo"}, |
4719 {"_ReceivePortImpl@709387912._internal@709387912", | 4670 {"_ReceivePortImpl@709387912", "_ReceivePortImpl"}, |
4720 "_ReceivePortImpl._internal"}, | 4671 {"_ReceivePortImpl@709387912._internal@709387912", |
4721 {"_C@6328321&_E@6328321&_F@6328321", "_C&_E&_F"}, | 4672 "_ReceivePortImpl._internal"}, |
4722 {"List.", "List"}, | 4673 {"_C@6328321&_E@6328321&_F@6328321", "_C&_E&_F"}, |
4723 {"get:foo@6328321", "foo"}, | 4674 {"List.", "List"}, |
4724 {"_MyClass@6328321.", "_MyClass"}, | 4675 {"get:foo@6328321", "foo"}, |
4725 {"_MyClass@6328321.named", "_MyClass.named"}, | 4676 {"_MyClass@6328321.", "_MyClass"}, |
| 4677 {"_MyClass@6328321.named", "_MyClass.named"}, |
4726 }; | 4678 }; |
4727 String& test = String::Handle(); | 4679 String& test = String::Handle(); |
4728 String& result = String::Handle(); | 4680 String& result = String::Handle(); |
4729 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { | 4681 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { |
4730 test = String::New(tests[i].in); | 4682 test = String::New(tests[i].in); |
4731 result = String::ScrubName(test); | 4683 result = String::ScrubName(test); |
4732 EXPECT_STREQ(tests[i].out, result.ToCString()); | 4684 EXPECT_STREQ(tests[i].out, result.ToCString()); |
4733 } | 4685 } |
4734 } | 4686 } |
4735 | 4687 |
4736 | 4688 |
4737 VM_TEST_CASE(String_EqualsUTF32) { | 4689 VM_TEST_CASE(String_EqualsUTF32) { |
4738 // Regression test for Issue 27433. Checks that comparisons between Strings | 4690 // Regression test for Issue 27433. Checks that comparisons between Strings |
4739 // and utf32 arrays happens after conversion to utf16 instead of utf32, as | 4691 // and utf32 arrays happens after conversion to utf16 instead of utf32, as |
4740 // required for proper canonicalization of string literals with a lossy | 4692 // required for proper canonicalization of string literals with a lossy |
4741 // utf32->utf16 conversion. | 4693 // utf32->utf16 conversion. |
4742 int32_t char_codes[] = { | 4694 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, |
4743 0, 0x0a, 0x0d, 0x7f, 0xff, 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff | 4695 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; |
4744 }; | |
4745 | 4696 |
4746 const String& str = | 4697 const String& str = |
4747 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); | 4698 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); |
4748 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); | 4699 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); |
4749 } | 4700 } |
4750 | 4701 |
4751 } // namespace dart | 4702 } // namespace dart |
OLD | NEW |