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

Unified Diff: pkg/mustache/test/mustache_spec_test.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files 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 | « pkg/mustache/pubspec.yaml ('k') | pkg/mustache/test/mustache_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mustache/test/mustache_spec_test.dart
diff --git a/pkg/mustache/test/mustache_spec_test.dart b/pkg/mustache/test/mustache_spec_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f6fc573099bfffd4a6130f782d57e68a3ba50ee9
--- /dev/null
+++ b/pkg/mustache/test/mustache_spec_test.dart
@@ -0,0 +1,83 @@
+import 'dart:async';
+import 'dart:io';
+import 'package:mustache/mustache.dart' as mustache;
+import 'dart:convert';
+
+var verbose = false;
+var testName = null;
+var fileName = null; //'test/spec/sections.json';
+
+main(List<String> args) {
+ if (!args.isEmpty) {
+ for (var arg in args) {
+ if (arg == '--verbose' || arg == '-v') {
+ verbose = true;
+ } else if (arg.startsWith('-')) {
+ print('Unknown argument: $arg');
+ print('Usage: dart test/mustache_spec_test.dart [--verbose] [test name]');
+ return;
+ } else {
+ testName = arg;
+ verbose = true;
+ }
+ }
+ }
+
+ var specs = new Directory('test/spec')
+ .listSync()
+ .where((f) => f is File
+ && f.path.endsWith('.json')
+ && (fileName == null || f.path == fileName));
+
+ Future.forEach(specs,
+ (file) => file
+ .readAsString()
+ .then((s) => JSON.decode(s))
+ .then((spec) {
+ print('Specification: ${file.path}');
+ spec['tests'].forEach((map) => runTest(
+ map['name'],
+ map['desc'],
+ map['data'],
+ map['template'],
+ map['expected']));
+ print('');
+ }));
+}
+
+runTest(String name, String desc, Map data, String template, String expected) {
+ if (testName != null && name != testName)
+ return;
+
+ var output;
+ var exception;
+ var trace;
+ try {
+ output = mustache.parse(template, lenient: true).renderString(data, lenient: true);
+ } catch (ex, stacktrace) {
+ exception = ex;
+ trace = stacktrace;
+ }
+
+// if (output != null)
+// output = output.replaceAll('\n', '\\n');
+
+// if (expected != null)
+// expected = expected.replaceAll('\n', '\\n');
+
+ var passed = output == expected;
+ var result = passed ? 'Pass' : 'Fail';
+ print(' $result $name');
+ if (verbose && !passed) {
+ print(desc);
+ print(' Template: $template');
+ print(' Data: ${JSON.encode(data)}');
+ print(' Expected: $expected');
+ print(' Output: $output');
+ if (exception != null) print(' Exception: $exception');
+ if (trace != null) print(trace);
+ print('');
+ print('');
+ }
+}
+
« no previous file with comments | « pkg/mustache/pubspec.yaml ('k') | pkg/mustache/test/mustache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698