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

Side by Side Diff: tests/compiler/dart2js/scanner_test.dart

Issue 992333003: dart2js: Handle zero-terminated content explicitly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment and close server in finally. Created 5 years, 9 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'package:compiler/src/scanner/scannerlib.dart'; 6 import 'package:compiler/src/scanner/scannerlib.dart';
7 import 'package:compiler/src/util/characters.dart'; 7 import 'package:compiler/src/util/characters.dart';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 Token scan(List<int> bytes) => new Utf8BytesScanner.fromBytes(bytes).tokenize(); 10 Token scan(List<int> bytes) {
11 List<int> zeroTerminated = new Uint8List(bytes.length + 1);
12 zeroTerminated.setRange(0, bytes.length, bytes);
13 zeroTerminated[bytes.length] = 0;
14 return new Utf8BytesScanner.fromBytes(zeroTerminated).tokenize();
15 }
11 16
12 Token scanUTF8(List<int> bytes) { 17 Token scanUTF8(List<int> bytes) {
13 int l = bytes.length; 18 int l = bytes.length;
14 List<int> stringLiteral = new Uint8List(l + 3); 19 List<int> stringLiteral = new Uint8List(l + 3);
15 stringLiteral[0] = 0x27; // single quote 20 stringLiteral[0] = 0x27; // single quote
16 stringLiteral[l+1] = 0x27; // single quote 21 stringLiteral[l+1] = 0x27; // single quote
22 // The bytes given to the scanner must be 0-terminated.
17 stringLiteral[l+2] = $EOF; 23 stringLiteral[l+2] = $EOF;
18 for (int i = 0; i < l; i++) { 24 for (int i = 0; i < l; i++) {
19 stringLiteral[i+1] = bytes[i]; 25 stringLiteral[i+1] = bytes[i];
20 } 26 }
21 return new Utf8BytesScanner.fromBytes(stringLiteral).tokenize(); 27 return new Utf8BytesScanner.fromBytes(stringLiteral).tokenize();
22 } 28 }
23 29
24 bool isRunningOnJavaScript() => identical(1, 1.0); 30 bool isRunningOnJavaScript() => identical(1, 1.0);
25 31
26 main() { 32 main() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // "#!" 70 // "#!"
65 token = scan([0x23, 0x21]); 71 token = scan([0x23, 0x21]);
66 Expect.equals(token.info, EOF_INFO); // Treated as a comment. 72 Expect.equals(token.info, EOF_INFO); // Treated as a comment.
67 73
68 // Regression test for issue 1761. 74 // Regression test for issue 1761.
69 // "#! Hello, World!" 75 // "#! Hello, World!"
70 token = scan([0x23, 0x21, 0x20, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 76 token = scan([0x23, 0x21, 0x20, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20,
71 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21]); 77 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21]);
72 Expect.equals(token.info, EOF_INFO); // Treated as a comment. 78 Expect.equals(token.info, EOF_INFO); // Treated as a comment.
73 } 79 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/one_line_dart_program.dart ('k') | tests/compiler/dart2js/zero_termination_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698