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

Unified Diff: test/runner/parse_metadata_test.dart

Issue 1008483003: Add a function to parse metadata into a usable object. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/runner/loader_test.dart ('k') | test/util/parse_annotations_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/runner/parse_metadata_test.dart
diff --git a/test/runner/parse_metadata_test.dart b/test/runner/parse_metadata_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5dfa6eaf67f63af0d5623e906701fe7c7163115b
--- /dev/null
+++ b/test/runner/parse_metadata_test.dart
@@ -0,0 +1,94 @@
+// Copyright (c) 2015, 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.
+
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+import 'package:unittest/unittest.dart';
+import 'package:unittest/src/runner/parse_metadata.dart';
+
+String _sandbox;
+String _path;
+
+void main() {
+ setUp(() {
+ _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
+ _path = p.join(_sandbox, "test.dart");
+ });
+
+ tearDown(() {
+ new Directory(_sandbox).deleteSync(recursive: true);
+ });
+
+ test("returns empty metadata for an empty file", () {
+ new File(_path).writeAsStringSync("");
+ var metadata = parseMetadata(_path);
+ expect(metadata.testOn, isNull);
+ });
+
+ test("ignores irrelevant annotations", () {
+ new File(_path).writeAsStringSync("@Fblthp\n@Fblthp.foo\nlibrary foo;");
+ var metadata = parseMetadata(_path);
+ expect(metadata.testOn, isNull);
+ });
+
+ test("parses a valid annotation", () {
+ new File(_path).writeAsStringSync("@TestOn('foo')\nlibrary foo;");
+ var metadata = parseMetadata(_path);
+ expect(metadata.testOn, equals("foo"));
+ });
+
+ test("parses a prefixed annotation", () {
+ new File(_path).writeAsStringSync(
+ "@foo.TestOn('foo')\n"
+ "import 'package:unittest/unittest.dart' as foo;");
+ var metadata = parseMetadata(_path);
+ expect(metadata.testOn, equals("foo"));
+ });
+
+ test("ignores a constructor named TestOn", () {
+ new File(_path).writeAsStringSync("@foo.TestOn('foo')\nlibrary foo;");
+ var metadata = parseMetadata(_path);
+ expect(metadata.testOn, isNull);
+ });
+
+ group("throws an error for", () {
+ test("a named constructor", () {
+ new File(_path).writeAsStringSync("@TestOn.name('foo')\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+
+ test("no argument list", () {
+ new File(_path).writeAsStringSync("@TestOn\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+
+ test("an empty argument list", () {
+ new File(_path).writeAsStringSync("@TestOn()\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+
+ test("a named argument", () {
+ new File(_path).writeAsStringSync(
+ "@TestOn(expression: 'foo')\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+
+ test("multiple arguments", () {
+ new File(_path).writeAsStringSync("@TestOn('foo', 'bar')\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+
+ test("a non-string argument", () {
+ new File(_path).writeAsStringSync("@TestOn(123)\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+
+ test("multiple @TestOns", () {
+ new File(_path).writeAsStringSync(
+ "@TestOn('foo')\n@TestOn('bar')\nlibrary foo;");
+ expect(() => parseMetadata(_path), throwsFormatException);
+ });
+ });
+}
« no previous file with comments | « test/runner/loader_test.dart ('k') | test/util/parse_annotations_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698