Chromium Code Reviews| 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/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/assembler.h" | 6 #include "vm/assembler.h" |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2376 EXPECT_EQ(':', str.CharAt(7)); | 2376 EXPECT_EQ(':', str.CharAt(7)); |
| 2377 EXPECT_EQ('e', str.CharAt(16)); | 2377 EXPECT_EQ('e', str.CharAt(16)); |
| 2378 str = script.Source(); | 2378 str = script.Source(); |
| 2379 EXPECT_EQ(22, str.Length()); | 2379 EXPECT_EQ(22, str.Length()); |
| 2380 EXPECT_EQ('T', str.CharAt(0)); | 2380 EXPECT_EQ('T', str.CharAt(0)); |
| 2381 EXPECT_EQ('n', str.CharAt(10)); | 2381 EXPECT_EQ('n', str.CharAt(10)); |
| 2382 EXPECT_EQ('.', str.CharAt(21)); | 2382 EXPECT_EQ('.', str.CharAt(21)); |
| 2383 } | 2383 } |
| 2384 | 2384 |
| 2385 | 2385 |
| 2386 TEST_CASE(EmbeddedScript) { | |
| 2387 const char* url_chars = "builtin:test-case"; | |
| 2388 const char* text = | |
| 2389 /* 1 */ "<!DOCTYPE html>\n" | |
| 2390 /* 2 */ " ... more junk ...\n" | |
| 2391 /* 3 */ " <script type='application/dart'>main() {\n" | |
| 2392 /* 4 */ " return 'foo';\n" | |
| 2393 /* 5 */ " }\n" | |
| 2394 /* 6 */ "</script>\n"; | |
| 2395 const char* line1 = text; | |
| 2396 const char* line2 = strstr(line1, "\n") + 1; | |
| 2397 const char* line3 = strstr(line2, "\n") + 1; | |
| 2398 const char* line4 = strstr(line3, "\n") + 1; | |
| 2399 const char* line5 = strstr(line4, "\n") + 1; | |
| 2400 ASSERT(strstr(line5, "}") != NULL); | |
|
siva
2013/01/10 21:17:20
Maybe you should add a comment indicating why this
hausner
2013/01/10 21:46:03
Done.
| |
| 2401 | |
| 2402 const char* script_begin = strstr(text, "main"); | |
| 2403 ASSERT(script_begin != NULL); | |
| 2404 const char* script_end = strstr(text, "</script>"); | |
| 2405 ASSERT(script_end != NULL); | |
| 2406 int script_length = script_end - script_begin; | |
| 2407 ASSERT(script_length > 0); | |
| 2408 | |
| 2409 // The Dart script starts on line 3 instead of 1, offset is 3 - 1 = 2. | |
| 2410 ASSERT(strstr(line3, "main") != NULL); | |
| 2411 int line_offset = 2; | |
| 2412 // Dart script starts with "main" on line 3. | |
| 2413 intptr_t col_offset = script_begin - line3; | |
| 2414 ASSERT(col_offset > 0); | |
| 2415 | |
| 2416 char* src_chars = strdup(script_begin); | |
| 2417 src_chars[script_length] = '\0'; | |
| 2418 | |
| 2419 const String& url = String::Handle(String::New(url_chars)); | |
| 2420 const String& source = String::Handle(String::New(src_chars)); | |
| 2421 const Script& script = Script::Handle( | |
| 2422 Script::New(url, source, RawScript::kSourceTag)); | |
| 2423 script.SetLocationOffset(line_offset, col_offset); | |
| 2424 | |
| 2425 String& str = String::Handle(); | |
| 2426 str = script.GetLine(3); | |
| 2427 EXPECT_STREQ("main() {", str.ToCString()); | |
| 2428 str = script.GetLine(5); | |
| 2429 EXPECT_STREQ(" }", str.ToCString()); | |
| 2430 | |
| 2431 | |
| 2432 script.Tokenize(String::Handle(String::New("ABC"))); | |
| 2433 intptr_t line, col; | |
| 2434 script.GetTokenLocation(0, &line, &col); | |
| 2435 EXPECT_EQ(3, line); | |
| 2436 EXPECT_EQ(col, col_offset + 1); | |
| 2437 | |
| 2438 script.GetTokenLocation(4, &line, &col); // Token 'return' | |
| 2439 EXPECT_EQ(4, line); // 'return' is in line 4. | |
| 2440 EXPECT_EQ(5, col); // Four spaces before 'return'. | |
| 2441 | |
| 2442 intptr_t first_idx, last_idx; | |
| 2443 script.TokenRangeAtLine(3, &first_idx, &last_idx); | |
| 2444 EXPECT_EQ(0, first_idx); // Token 'main' is first token. | |
| 2445 EXPECT_EQ(3, last_idx); // Token { is last token. | |
| 2446 script.TokenRangeAtLine(5, &first_idx, &last_idx); | |
| 2447 EXPECT_EQ(7, first_idx); // Token } is first and only token. | |
| 2448 EXPECT_EQ(7, last_idx); | |
| 2449 } | |
| 2450 | |
| 2451 | |
| 2386 TEST_CASE(Context) { | 2452 TEST_CASE(Context) { |
| 2387 const int kNumVariables = 5; | 2453 const int kNumVariables = 5; |
| 2388 const Context& parent_context = Context::Handle(Context::New(0)); | 2454 const Context& parent_context = Context::Handle(Context::New(0)); |
| 2389 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); | 2455 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); |
| 2390 const Context& context = Context::Handle(Context::New(kNumVariables)); | 2456 const Context& context = Context::Handle(Context::New(kNumVariables)); |
| 2391 context.set_parent(parent_context); | 2457 context.set_parent(parent_context); |
| 2392 const Context& check_parent_context = Context::Handle(context.parent()); | 2458 const Context& check_parent_context = Context::Handle(context.parent()); |
| 2393 EXPECT_EQ(context.isolate(), check_parent_context.isolate()); | 2459 EXPECT_EQ(context.isolate(), check_parent_context.isolate()); |
| 2394 EXPECT_EQ(kNumVariables, context.num_variables()); | 2460 EXPECT_EQ(kNumVariables, context.num_variables()); |
| 2395 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw()); | 2461 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw()); |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3479 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); | 3545 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); |
| 3480 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); | 3546 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); |
| 3481 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); | 3547 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); |
| 3482 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); | 3548 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); |
| 3483 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); | 3549 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); |
| 3484 } | 3550 } |
| 3485 | 3551 |
| 3486 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3552 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3487 | 3553 |
| 3488 } // namespace dart | 3554 } // namespace dart |
| OLD | NEW |