OLD | NEW |
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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Test inlining of assignments in parameter passing. If [StringScanner.charAt] | 7 // Test inlining of assignments in parameter passing. If [StringScanner.charAt] |
8 // is inlined, the argument expresion [: ++byteOffset :] should not be | 8 // is inlined, the argument expression [: ++byteOffset :] should not be |
9 // duplicated. | 9 // duplicated. |
10 | 10 |
11 class StringScanner { | 11 class StringScanner { |
12 final String string; | 12 final String string; |
13 int byteOffset = -1; | 13 int byteOffset = -1; |
14 | 14 |
15 StringScanner(this.string); | 15 StringScanner(this.string); |
16 | 16 |
17 int nextByte() => charAt(++byteOffset); | 17 int nextByte() => charAt(++byteOffset); |
18 | 18 |
19 int charAt(index) => (string.length > index) ? string.codeUnitAt(index) : -1; | 19 int charAt(index) => (string.length > index) ? string.codeUnitAt(index) : -1; |
20 } | 20 } |
21 | 21 |
22 void main() { | 22 void main() { |
23 var scanner = new StringScanner('az9'); | 23 var scanner = new StringScanner('az9'); |
24 Expect.equals(0x61, scanner.nextByte()); // Expect a. | 24 Expect.equals(0x61, scanner.nextByte()); // Expect a. |
25 Expect.equals(0x7A, scanner.nextByte()); // Expect z. | 25 Expect.equals(0x7A, scanner.nextByte()); // Expect z. |
26 Expect.equals(0x39, scanner.nextByte()); // Expect 9. | 26 Expect.equals(0x39, scanner.nextByte()); // Expect 9. |
27 Expect.equals(-1, scanner.nextByte()); | 27 Expect.equals(-1, scanner.nextByte()); |
28 } | 28 } |
OLD | NEW |