OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Tests v8::internal::Scanner. Note that presently most unit tests for the | |
6 // Scanner are in cctest/test-parsing.cc, rather than here. | |
7 | |
8 #include "src/handles-inl.h" | |
9 #include "src/parsing/scanner-character-streams.h" | |
10 #include "src/parsing/scanner.h" | |
11 #include "src/unicode-cache.h" | |
12 #include "test/cctest/cctest.h" | |
13 | |
14 using namespace v8::internal; | |
15 | |
16 namespace { | |
17 | |
18 const char src_simple[] = "function foo() { var x = 2 * a() + b; }"; | |
19 | |
20 static UnicodeCache* unicode_cache = new UnicodeCache(); | |
21 | |
22 std::unique_ptr<Scanner> make_scanner(const char* src) { | |
23 std::unique_ptr<Scanner> scanner(new Scanner(new UnicodeCache())); | |
24 scanner->Initialize(ScannerStream::ForTesting(src).release()); | |
25 return scanner; | |
26 } | |
27 | |
28 } // anonymous namespace | |
29 | |
30 TEST(Bookmarks) { | |
31 // Scan through the given source and record the tokens for use as reference | |
32 // below. | |
33 std::vector<Token::Value> tokens; | |
34 { | |
35 auto scanner = make_scanner(src_simple); | |
36 do { | |
37 tokens.push_back(scanner->Next()); | |
38 } while (scanner->current_token() != Token::EOS); | |
39 } | |
40 | |
41 // For each position (between tokens, i.e. not first or last): | |
42 // - Scan through file, | |
43 // - set a bookmark once the position is reached, | |
44 // - scan a bit more, | |
45 // - reset to the bookmark, and | |
46 // - scan until the end. | |
47 // At each step, compare to the reference token sequence generated above. | |
48 for (size_t bookmark_pos = 1; bookmark_pos < tokens.size() - 1; | |
marja
2016/09/19 11:50:39
You could also set the bookmark to pos 0 without s
marja
2016/09/19 11:50:39
Can you also set it to the end? Or does that not m
vogelheim
2016/09/19 16:04:45
Done.
[My thinking was that this doesn't test any
vogelheim
2016/09/19 16:04:45
Done.
| |
49 bookmark_pos++) { | |
50 auto scanner = make_scanner(src_simple); | |
51 Scanner::BookmarkScope bookmark(scanner.get()); | |
52 | |
53 for (size_t i = 0; i < std::min(bookmark_pos + 10, tokens.size()); i++) { | |
54 if (i == bookmark_pos) { | |
55 bookmark.Set(); | |
56 } | |
57 DCHECK_EQ(tokens[i], scanner->Next()); | |
58 } | |
59 | |
60 bookmark.Reset(); | |
61 for (size_t i = bookmark_pos; i < tokens.size(); i++) { | |
62 DCHECK_EQ(tokens[i], scanner->Next()); | |
63 } | |
64 } | |
65 } | |
OLD | NEW |