Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: runtime/vm/object_test.cc

Issue 11824067: Support for embedded Dart scripts (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
2401 const int first_dart_line = 3;
2402 ASSERT(strstr(line3, "main") != NULL);
2403 const int last_dart_line = 5;
2404 ASSERT(strstr(line5, "}") != NULL);
2405
2406 const char* script_begin = strstr(text, "main");
2407 ASSERT(script_begin != NULL);
2408 const char* script_end = strstr(text, "</script>");
2409 ASSERT(script_end != NULL);
2410 int script_length = script_end - script_begin;
2411 ASSERT(script_length > 0);
2412
2413 // The Dart script starts on line 3 instead of 1, offset is 3 - 1 = 2.
2414 int line_offset = 2;
2415 // Dart script starts with "main" on line 3.
2416 intptr_t col_offset = script_begin - line3;
2417 ASSERT(col_offset > 0);
2418
2419 char* src_chars = strdup(script_begin);
2420 src_chars[script_length] = '\0';
2421
2422 const String& url = String::Handle(String::New(url_chars));
2423 const String& source = String::Handle(String::New(src_chars));
2424 const Script& script = Script::Handle(
2425 Script::New(url, source, RawScript::kSourceTag));
2426 script.SetLocationOffset(line_offset, col_offset);
2427
2428 String& str = String::Handle();
2429 str = script.GetLine(first_dart_line);
2430 EXPECT_STREQ("main() {", str.ToCString());
2431 str = script.GetLine(last_dart_line);
2432 EXPECT_STREQ(" }", str.ToCString());
2433
2434
2435 script.Tokenize(String::Handle(String::New("ABC")));
2436 intptr_t line, col;
2437 script.GetTokenLocation(0, &line, &col);
2438 EXPECT_EQ(first_dart_line, line);
2439 EXPECT_EQ(col, col_offset + 1);
2440
2441 script.GetTokenLocation(4, &line, &col); // Token 'return'
2442 EXPECT_EQ(4, line); // 'return' is in line 4.
2443 EXPECT_EQ(5, col); // Four spaces before 'return'.
2444
2445 intptr_t first_idx, last_idx;
2446 script.TokenRangeAtLine(3, &first_idx, &last_idx);
2447 EXPECT_EQ(0, first_idx); // Token 'main' is first token.
2448 EXPECT_EQ(3, last_idx); // Token { is last token.
2449 script.TokenRangeAtLine(5, &first_idx, &last_idx);
2450 EXPECT_EQ(7, first_idx); // Token } is first and only token.
2451 EXPECT_EQ(7, last_idx);
2452 }
2453
2454
2386 TEST_CASE(Context) { 2455 TEST_CASE(Context) {
2387 const int kNumVariables = 5; 2456 const int kNumVariables = 5;
2388 const Context& parent_context = Context::Handle(Context::New(0)); 2457 const Context& parent_context = Context::Handle(Context::New(0));
2389 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); 2458 EXPECT_EQ(parent_context.isolate(), Isolate::Current());
2390 const Context& context = Context::Handle(Context::New(kNumVariables)); 2459 const Context& context = Context::Handle(Context::New(kNumVariables));
2391 context.set_parent(parent_context); 2460 context.set_parent(parent_context);
2392 const Context& check_parent_context = Context::Handle(context.parent()); 2461 const Context& check_parent_context = Context::Handle(context.parent());
2393 EXPECT_EQ(context.isolate(), check_parent_context.isolate()); 2462 EXPECT_EQ(context.isolate(), check_parent_context.isolate());
2394 EXPECT_EQ(kNumVariables, context.num_variables()); 2463 EXPECT_EQ(kNumVariables, context.num_variables());
2395 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw()); 2464 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw());
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); 3548 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint());
3480 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); 3549 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint());
3481 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); 3550 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint());
3482 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); 3551 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint());
3483 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); 3552 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint());
3484 } 3553 }
3485 3554
3486 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3555 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3487 3556
3488 } // namespace dart 3557 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698