Migrate tests to use expected_output (dart-lang/markdown#163)

Migrate tests to use expected_output
diff --git a/pkgs/markdown/pubspec.yaml b/pkgs/markdown/pubspec.yaml
index fec5e69..9322505 100644
--- a/pkgs/markdown/pubspec.yaml
+++ b/pkgs/markdown/pubspec.yaml
@@ -9,7 +9,8 @@
   args: '^0.13.3+1'
   # Only for example/app.dart.
   browser: any
-  collection: ^1.2.0
+  collection: '^1.2.0'
+  expected_output: '^1.1.0'
   html: '>=0.12.2 <0.14.0'
   js: '^0.6.1'
   path: '^1.3.1'
diff --git a/pkgs/markdown/test/markdown_test.dart b/pkgs/markdown/test/markdown_test.dart
index 701ae63..8ea7be7 100644
--- a/pkgs/markdown/test/markdown_test.dart
+++ b/pkgs/markdown/test/markdown_test.dart
@@ -2,12 +2,8 @@
 // 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.
 
-/// Unit tests for markdown.
-library markdown.test.markdown_test;
-
-import 'package:test/test.dart';
-
 import 'package:markdown/markdown.dart';
+import 'package:test/test.dart';
 
 import 'util.dart';
 
@@ -16,6 +12,16 @@
 void main() {
   testDirectory('original');
 
+  testFile('extensions/fenced_code_blocks.unit',
+      blockSyntaxes: [const FencedCodeBlockSyntax()]);
+  testFile('extensions/inline_html.unit',
+      inlineSyntaxes: [new InlineHtmlSyntax()]);
+  testFile('extensions/headers_with_ids.unit',
+      blockSyntaxes: [const HeaderWithIdSyntax()]);
+  testFile('extensions/setext_headers_with_ids.unit',
+      blockSyntaxes: [const SetextHeaderWithIdSyntax()]);
+  testFile('extensions/tables.unit', blockSyntaxes: [const TableSyntax()]);
+
   group('Resolver', () {
     Node nyanResolver(String text) => new Text('~=[,,_${text}_,,]:3');
     validateCore(
@@ -136,18 +142,4 @@
         ''',
         inlineOnly: true);
   });
-
-  testFile('extensions/fenced_code_blocks.unit',
-      blockSyntaxes: [const FencedCodeBlockSyntax()]);
-
-  testFile('extensions/inline_html.unit',
-      inlineSyntaxes: [new InlineHtmlSyntax()]);
-
-  testFile('extensions/headers_with_ids.unit',
-      blockSyntaxes: [const HeaderWithIdSyntax()]);
-
-  testFile('extensions/setext_headers_with_ids.unit',
-      blockSyntaxes: [const SetextHeaderWithIdSyntax()]);
-
-  testFile('extensions/tables.unit', blockSyntaxes: [const TableSyntax()]);
 }
diff --git a/pkgs/markdown/test/util.dart b/pkgs/markdown/test/util.dart
index dfec203..123bf9c 100644
--- a/pkgs/markdown/test/util.dart
+++ b/pkgs/markdown/test/util.dart
@@ -7,6 +7,7 @@
 import 'dart:io';
 import 'dart:mirrors';
 
+import 'package:expected_output/expected_output.dart';
 import 'package:markdown/markdown.dart';
 import 'package:path/path.dart' as p;
 import 'package:test/test.dart';
@@ -15,12 +16,9 @@
 
 /// Run tests defined in "*.unit" files inside directory [name].
 void testDirectory(String name) {
-  var dir = p.join(_testDir, name);
-  var entries =
-      new Directory(dir).listSync().where((e) => e.path.endsWith('.unit'));
-
-  for (var entry in entries) {
-    testUnitFile(name, entry);
+  for (var dataCase
+      in dataCasesUnder(library: #markdown.test.util, subdirectory: name)) {
+    validateCore(dataCase.description, dataCase.input, dataCase.expectedOutput);
   }
 }
 
@@ -30,49 +28,12 @@
     p.dirname(currentMirrorSystem().findLibrary(#markdown.test.util).uri.path);
 
 void testFile(String file,
-        {Iterable<BlockSyntax> blockSyntaxes,
-        Iterable<InlineSyntax> inlineSyntaxes}) =>
-    testUnitFile(file, new File(p.join(_testDir, file)),
-        blockSyntaxes: blockSyntaxes, inlineSyntaxes: inlineSyntaxes);
-
-void testUnitFile(String directory, File entry,
     {Iterable<BlockSyntax> blockSyntaxes,
     Iterable<InlineSyntax> inlineSyntaxes}) {
-  group('$directory ${p.basename(entry.path)}', () {
-    var lines = entry.readAsLinesSync();
-
-    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 indentMatch = _indentPattern.firstMatch(description);
-      if (indentMatch != null) {
-        // The test specifies it in spaces, but the formatter expects levels.
-        description = description.substring(indentMatch.end);
-      }
-
-      if (description == "") {
-        description = "line ${i + 1}";
-      } else {
-        description = "line ${i + 1}: $description";
-      }
-
-      var input = "";
-      while (!lines[i].startsWith("<<<")) {
-        input += lines[i++] + "\n";
-      }
-
-      var expectedOutput = "";
-      while (++i < lines.length && !lines[i].startsWith(">>>")) {
-        expectedOutput += lines[i] + "\n";
-      }
-
-      validateCore(description, input, expectedOutput,
-          blockSyntaxes: blockSyntaxes, inlineSyntaxes: inlineSyntaxes);
-    }
-  });
+  for (var dataCase in dataCasesInFile(path: p.join(_testDir, file))) {
+    validateCore(dataCase.description, dataCase.input, dataCase.expectedOutput,
+        blockSyntaxes: blockSyntaxes, inlineSyntaxes: inlineSyntaxes);
+  }
 }
 
 void validateCore(String description, String markdown, String html,