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

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

Issue 24359005: Make Script::GetTokenLocation() and Script::TokenRangeAtLine() use token streams where possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
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 "vm/assembler.h" 5 #include "vm/assembler.h"
6 #include "vm/bigint_operations.h" 6 #include "vm/bigint_operations.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 const Script& script = Script::Handle( 2057 const Script& script = Script::Handle(
2058 Script::New(url, source, RawScript::kScriptTag)); 2058 Script::New(url, source, RawScript::kScriptTag));
2059 script.SetLocationOffset(line_offset, col_offset); 2059 script.SetLocationOffset(line_offset, col_offset);
2060 2060
2061 String& str = String::Handle(); 2061 String& str = String::Handle();
2062 str = script.GetLine(first_dart_line); 2062 str = script.GetLine(first_dart_line);
2063 EXPECT_STREQ("main() {", str.ToCString()); 2063 EXPECT_STREQ("main() {", str.ToCString());
2064 str = script.GetLine(last_dart_line); 2064 str = script.GetLine(last_dart_line);
2065 EXPECT_STREQ(" }", str.ToCString()); 2065 EXPECT_STREQ(" }", str.ToCString());
2066 2066
2067 script.Tokenize(String::Handle(String::New("ABC")));
2068 // Tokens: 0: kIDENT, 1: kLPAREN, 2: kRPAREN, 3: kLBRACE, 4: kNEWLINE,
2069 // 5: kRETURN, 6: kSTRING, 7: kSEMICOLON, 8: kNEWLINE,
2070 // 9: kRBRACE, 10: kNEWLINE
2067 2071
2068 script.Tokenize(String::Handle(String::New("ABC")));
2069 intptr_t line, col; 2072 intptr_t line, col;
2073 intptr_t fast_line;
2070 script.GetTokenLocation(0, &line, &col); 2074 script.GetTokenLocation(0, &line, &col);
2071 EXPECT_EQ(first_dart_line, line); 2075 EXPECT_EQ(first_dart_line, line);
2072 EXPECT_EQ(col, col_offset + 1); 2076 EXPECT_EQ(col, col_offset + 1);
2077 script.GetTokenLocation(0, &fast_line, NULL);
hausner 2013/09/23 18:54:49 Can you add a comment here why you call GetTokenLo
Michael Lippautz (Google) 2013/09/23 21:15:03 Done.
2078 EXPECT_EQ(line, fast_line);
2073 2079
2074 script.GetTokenLocation(4, &line, &col); // Token 'return' 2080 script.GetTokenLocation(5, &line, &col); // Token 'return'
2075 EXPECT_EQ(4, line); // 'return' is in line 4. 2081 EXPECT_EQ(4, line); // 'return' is in line 4.
2076 EXPECT_EQ(5, col); // Four spaces before 'return'. 2082 EXPECT_EQ(5, col); // Four spaces before 'return'.
2083 script.GetTokenLocation(5, &fast_line, NULL);
2084 EXPECT_EQ(line, fast_line);
2077 2085
2078 intptr_t first_idx, last_idx; 2086 intptr_t first_idx, last_idx;
2079 script.TokenRangeAtLine(3, &first_idx, &last_idx); 2087 script.TokenRangeAtLine(3, &first_idx, &last_idx);
2080 EXPECT_EQ(0, first_idx); // Token 'main' is first token. 2088 EXPECT_EQ(0, first_idx); // Token 'main' is first token.
2081 EXPECT_EQ(3, last_idx); // Token { is last token. 2089 EXPECT_EQ(3, last_idx); // Token { is last token.
2090 script.TokenRangeAtLine(4, &first_idx, &last_idx);
2091 EXPECT_EQ(5, first_idx); // Token 'return' is first token.
2092 EXPECT_EQ(7, last_idx); // Token ; is last token.
2082 script.TokenRangeAtLine(5, &first_idx, &last_idx); 2093 script.TokenRangeAtLine(5, &first_idx, &last_idx);
2083 EXPECT_EQ(9, first_idx); // Token } is first and only token. 2094 EXPECT_EQ(9, first_idx); // Token } is first and only token.
2084 EXPECT_EQ(9, last_idx); 2095 EXPECT_EQ(9, last_idx);
2085 } 2096 }
2086 2097
2087 2098
2088 TEST_CASE(Context) { 2099 TEST_CASE(Context) {
2089 const int kNumVariables = 5; 2100 const int kNumVariables = 5;
2090 const Context& parent_context = Context::Handle(Context::New(0)); 2101 const Context& parent_context = Context::Handle(Context::New(0));
2091 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); 2102 EXPECT_EQ(parent_context.isolate(), Isolate::Current());
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
3450 cls = Object::dynamic_class(); 3461 cls = Object::dynamic_class();
3451 array = cls.fields(); 3462 array = cls.fields();
3452 EXPECT(!array.IsNull()); 3463 EXPECT(!array.IsNull());
3453 EXPECT(array.IsArray()); 3464 EXPECT(array.IsArray());
3454 array = cls.functions(); 3465 array = cls.functions();
3455 EXPECT(!array.IsNull()); 3466 EXPECT(!array.IsNull());
3456 EXPECT(array.IsArray()); 3467 EXPECT(array.IsArray());
3457 } 3468 }
3458 3469
3459 } // namespace dart 3470 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | runtime/vm/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698