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

Unified Diff: tests/compiler/dart2js/annotated_code_helper.dart

Issue 2656583003: Add inference test functionality based on code point id. (Closed)
Patch Set: Created 3 years, 11 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: tests/compiler/dart2js/annotated_code_helper.dart
diff --git a/tests/compiler/dart2js/annotated_code_helper.dart b/tests/compiler/dart2js/annotated_code_helper.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f75b5927a74746de4b06cdaa171e4a00f2c8a4c8
--- /dev/null
+++ b/tests/compiler/dart2js/annotated_code_helper.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+const int _LF = 0x0A;
+const int _CR = 0x0D;
+const int _LBRACE = 0x7B;
+
+class Annotation {
+ /// 1-based line number of the annotation.
+ final int lineNo;
+
+ /// 1-based column number of the annotation.
+ final int columnNo;
+
+ /// 0-based character offset with
Siggi Cherem (dart-lang) 2017/01/24 21:05:59 with => of the annotation?
Johnni Winther 2017/01/25 13:28:13 Done.
+ final int offset;
+
+ /// The text in the annotation.
+ final String text;
+
+ Annotation(this.lineNo, this.columnNo, this.offset, this.text);
+}
+
+class AnnotatedCode {
Siggi Cherem (dart-lang) 2017/01/24 21:05:59 add a short dart doc with an example of the syntax
Johnni Winther 2017/01/25 13:28:13 Done.
+ final String sourceCode;
Siggi Cherem (dart-lang) 2017/01/24 21:05:59 + dartdoc or rename to unannotatedCode?
Johnni Winther 2017/01/25 13:28:13 Done.
+ final List<Annotation> annotations;
+
+ AnnotatedCode(this.sourceCode, this.annotations);
+}
+
+AnnotatedCode processAnnotatedCode(String code) {
Siggi Cherem (dart-lang) 2017/01/24 21:05:59 optional nit: rename or move as a factory construc
Johnni Winther 2017/01/25 13:28:13 Done.
+ StringBuffer codeBuffer = new StringBuffer();
+ List<Annotation> annotations = <Annotation>[];
+ int index = 0;
+ int offset = 0;
+ int lineNo = 1;
+ int columnNo = 1;
+ while (index < code.length) {
+ int charCode = code.codeUnitAt(index);
+ switch (charCode) {
+ case _LF:
+ codeBuffer.write('\n');
+ offset++;
+ lineNo++;
+ columnNo = 1;
+ break;
+ case _CR:
+ if (index + 1 < code.length && code.codeUnitAt(index + 1) == _LF) {
+ index++;
+ }
+ codeBuffer.write('\n');
+ offset++;
+ lineNo++;
+ columnNo = 1;
+ break;
+ case 0x40:
Siggi Cherem (dart-lang) 2017/01/24 21:05:59 define 0x40 too?
+ if (index + 1 < code.length && code.codeUnitAt(index + 1) == _LBRACE) {
+ int endIndex = code.indexOf('}', index);
+ String text = code.substring(index + 2, endIndex);
+ annotations.add(new Annotation(lineNo, columnNo, offset, text));
+ index = endIndex;
+ } else {
+ codeBuffer.writeCharCode(charCode);
+ offset++;
+ columnNo++;
+ }
+ break;
+ default:
+ codeBuffer.writeCharCode(charCode);
+ offset++;
+ columnNo++;
+ }
+ index++;
+ }
+ return new AnnotatedCode(codeBuffer.toString(), annotations);
+}

Powered by Google App Engine
This is Rietveld 408576698