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

Unified Diff: test/formatter_test.dart

Issue 791113002: Regression test for #45 which is doing pretty much what we want the formatter to do already. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | test/regression/33.stmt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/formatter_test.dart
diff --git a/test/formatter_test.dart b/test/formatter_test.dart
index 971f7ecd75f8d19233990b78de59d06e7c9d838b..91b01c06fd84ae28a33691c848344a7a08d0b823 100644
--- a/test/formatter_test.dart
+++ b/test/formatter_test.dart
@@ -100,6 +100,8 @@ void main() {
/// Run tests defined in "*.unit" and "*.stmt" files inside directory [name].
void testDirectory(String name) {
+ var indentPattern = new RegExp(r"^\(indent (\d+)\)\s*");
+
var dir = p.join(p.dirname(p.fromUri(Platform.script)), name);
for (var entry in new Directory(dir).listSync()) {
if (!entry.path.endsWith(".stmt") && !entry.path.endsWith(".unit")) {
@@ -119,6 +121,17 @@ void testDirectory(String name) {
var i = 0;
while (i < lines.length) {
var description = lines[i++].replaceAll(">>>", "").trim();
+
+ // Let the test specify a leading indentation. This is handy for
+ // regression tests which often come from a chunk of nested code.
+ var leadingIndent = 0;
+ var indentMatch = indentPattern.firstMatch(description);
+ if (indentMatch != null) {
+ // The test specifies it in spaces, but the formatter expects levels.
+ leadingIndent = int.parse(indentMatch[1]) ~/ 2;
+ description = description.substring(indentMatch.end);
+ }
+
if (description == "") {
description = "line ${i + 1}";
} else {
@@ -135,13 +148,9 @@ void testDirectory(String name) {
expectedOutput += lines[i] + "\n";
}
- if (description.contains("SKIP")) {
- print("SKIP: $description");
- continue;
- }
-
test(description, () {
- var formatter = new DartFormatter(pageWidth: pageWidth);
+ var formatter = new DartFormatter(
+ pageWidth: pageWidth, indent: leadingIndent);
var result;
if (p.extension(entry.path) == ".stmt") {
« no previous file with comments | « no previous file | test/regression/33.stmt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698