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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object_test.cc
diff --git a/runtime/vm/object_test.cc b/runtime/vm/object_test.cc
index dcb3bbe5fdefe14c46218140ec75143f9cc48cc5..ca79138ef7de0eddbe26c366c431a508e135844b 100644
--- a/runtime/vm/object_test.cc
+++ b/runtime/vm/object_test.cc
@@ -2064,24 +2064,47 @@ TEST_CASE(EmbeddedScript) {
str = script.GetLine(last_dart_line);
EXPECT_STREQ(" }", str.ToCString());
-
script.Tokenize(String::Handle(String::New("ABC")));
+ // Tokens: 0: kIDENT, 1: kLPAREN, 2: kRPAREN, 3: kLBRACE, 4: kNEWLINE,
+ // 5: kRETURN, 6: kSTRING, 7: kSEMICOLON, 8: kNEWLINE,
+ // 9: kRBRACE, 10: kNEWLINE
+
intptr_t line, col;
+ intptr_t fast_line;
script.GetTokenLocation(0, &line, &col);
EXPECT_EQ(first_dart_line, line);
EXPECT_EQ(col, col_offset + 1);
- script.GetTokenLocation(4, &line, &col); // Token 'return'
+ // We allow asking for only the line number, which only scans the token stream
+ // instead of rescanning the script.
+ script.GetTokenLocation(0, &fast_line, NULL);
+ EXPECT_EQ(line, fast_line);
+
+ script.GetTokenLocation(5, &line, &col); // Token 'return'
EXPECT_EQ(4, line); // 'return' is in line 4.
EXPECT_EQ(5, col); // Four spaces before 'return'.
+ // We allow asking for only the line number, which only scans the token stream
+ // instead of rescanning the script.
+ script.GetTokenLocation(5, &fast_line, NULL);
+ EXPECT_EQ(line, fast_line);
+
intptr_t first_idx, last_idx;
script.TokenRangeAtLine(3, &first_idx, &last_idx);
EXPECT_EQ(0, first_idx); // Token 'main' is first token.
EXPECT_EQ(3, last_idx); // Token { is last token.
+ script.TokenRangeAtLine(4, &first_idx, &last_idx);
+ EXPECT_EQ(5, first_idx); // Token 'return' is first token.
+ EXPECT_EQ(7, last_idx); // Token ; is last token.
script.TokenRangeAtLine(5, &first_idx, &last_idx);
EXPECT_EQ(9, first_idx); // Token } is first and only token.
EXPECT_EQ(9, last_idx);
+ script.TokenRangeAtLine(1, &first_idx, &last_idx);
+ EXPECT_EQ(0, first_idx);
+ EXPECT_EQ(3, last_idx);
+ script.TokenRangeAtLine(1000, &first_idx, &last_idx);
+ EXPECT_EQ(-1, first_idx);
+ EXPECT_EQ(-1, last_idx);
}
« 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