OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:front_end/src/fasta/parser/token_stream_rewriter.dart'; | 5 import 'package:front_end/src/fasta/parser/token_stream_rewriter.dart'; |
6 import 'package:front_end/src/fasta/scanner/token.dart'; | 6 import 'package:front_end/src/fasta/scanner/token.dart'; |
7 import 'package:front_end/src/scanner/token.dart' | 7 import 'package:front_end/src/scanner/token.dart' |
8 show BeginToken, Token, TokenType; | 8 show BeginToken, Token, TokenType; |
9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
11 | 11 |
12 main() { | 12 main() { |
13 defineReflectiveSuite(() { | 13 defineReflectiveSuite(() { |
14 defineReflectiveTests(TokenStreamRewriterTest_NoPrevious); | 14 defineReflectiveTests(TokenStreamRewriterTest_NoPrevious); |
15 defineReflectiveTests(TokenStreamRewriterTest_UsingPrevious); | 15 defineReflectiveTests(TokenStreamRewriterTest_UsingPrevious); |
16 }); | 16 }); |
17 } | 17 } |
18 | 18 |
19 /// Abstract base class for tests of [TokenStreamRewriter]. | 19 /// Abstract base class for tests of [TokenStreamRewriter]. |
20 abstract class TokenStreamRewriterTest { | 20 abstract class TokenStreamRewriterTest { |
21 /// Indicates whether the tests should set up [Token.previous]. | 21 /// Indicates whether the tests should set up [Token.previous]. |
22 bool get setPrevious; | 22 bool get setPrevious; |
23 | 23 |
24 void test_insert_at_end() { | 24 void test_insert_at_end() { |
25 var a = _makeToken(0, 'a'); | 25 var a = _makeToken(0, 'a'); |
26 var b = _makeToken(1, 'b'); | 26 var b = _makeToken(1, 'b'); |
27 var eof = _link([a]); | 27 var eof = _link([a]); |
28 var rewriter = new TokenStreamRewriter(a); | 28 var rewriter = new TokenStreamRewriter(a); |
29 rewriter.insertTokenBefore(b, eof); | 29 expect(rewriter.insertTokenBefore(b, eof), same(b)); |
30 expect(rewriter.firstToken, same(a)); | 30 expect(rewriter.firstToken, same(a)); |
31 expect(a.next, same(b)); | 31 expect(a.next, same(b)); |
32 expect(b.next, same(eof)); | 32 expect(b.next, same(eof)); |
33 expect(eof.previous, same(b)); | 33 expect(eof.previous, same(b)); |
34 expect(b.previous, same(a)); | 34 expect(b.previous, same(a)); |
35 } | 35 } |
36 | 36 |
37 void test_insert_at_start() { | 37 void test_insert_at_start() { |
38 var a = _makeToken(0, 'a'); | 38 var a = _makeToken(0, 'a'); |
39 var b = _makeToken(1, 'b'); | 39 var b = _makeToken(1, 'b'); |
40 _link([b]); | 40 _link([b]); |
41 var rewriter = new TokenStreamRewriter(b); | 41 var rewriter = new TokenStreamRewriter(b); |
42 rewriter.insertTokenBefore(a, b); | 42 expect(rewriter.insertTokenBefore(a, b), same(a)); |
43 expect(rewriter.firstToken, same(a)); | 43 expect(rewriter.firstToken, same(a)); |
44 expect(a.next, same(b)); | 44 expect(a.next, same(b)); |
45 expect(a.previous.next, same(a)); | 45 expect(a.previous.next, same(a)); |
46 expect(b.previous, same(a)); | 46 expect(b.previous, same(a)); |
47 } | 47 } |
48 | 48 |
49 void test_resume_at_previous_insertion_point() { | 49 void test_resume_at_previous_insertion_point() { |
50 var a = _makeToken(0, 'a'); | 50 var a = _makeToken(0, 'a'); |
51 var b = _makeToken(1, 'b'); | 51 var b = _makeToken(1, 'b'); |
52 var c = _makeToken(2, 'c'); | 52 var c = _makeToken(2, 'c'); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 /// Concrete implementation of [TokenStreamRewriterTest] in which | 143 /// Concrete implementation of [TokenStreamRewriterTest] in which |
144 /// [Token.previous] values are set to non-null. | 144 /// [Token.previous] values are set to non-null. |
145 /// | 145 /// |
146 /// Since [TokenStreamRewriter] makes use of [Token.previous] when it can, | 146 /// Since [TokenStreamRewriter] makes use of [Token.previous] when it can, |
147 /// these tests do not exercise the more complex heuristics for finding previous | 147 /// these tests do not exercise the more complex heuristics for finding previous |
148 /// tokens. | 148 /// tokens. |
149 @reflectiveTest | 149 @reflectiveTest |
150 class TokenStreamRewriterTest_UsingPrevious extends TokenStreamRewriterTest { | 150 class TokenStreamRewriterTest_UsingPrevious extends TokenStreamRewriterTest { |
151 bool get setPrevious => true; | 151 bool get setPrevious => true; |
152 } | 152 } |
OLD | NEW |