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

Unified Diff: test/util/parse_annotations_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/parse_metadata_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/util/parse_annotations_test.dart
diff --git a/test/util/parse_annotations_test.dart b/test/util/parse_annotations_test.dart
deleted file mode 100644
index 92818eb9ee87b21b89b1d65b34fdef487d036039..0000000000000000000000000000000000000000
--- a/test/util/parse_annotations_test.dart
+++ /dev/null
@@ -1,178 +0,0 @@
-// 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/util/dart.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("with an empty file", () {
- new File(_path).writeAsStringSync("");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, isEmpty);
- });
-
- test("before a library tag", () {
- new File(_path).writeAsStringSync("@Annotation()\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("before an import", () {
- new File(_path).writeAsStringSync("@Annotation()\nimport 'foo';");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("multiple annotations", () {
- new File(_path).writeAsStringSync(
- "@Annotation1() @Annotation2()\n@Annotation3()\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(3));
- expect(annotations[0].name.name, equals('Annotation1'));
- expect(annotations[0].arguments.arguments, isEmpty);
- expect(annotations[1].name.name, equals('Annotation2'));
- expect(annotations[1].arguments.arguments, isEmpty);
- expect(annotations[2].name.name, equals('Annotation3'));
- expect(annotations[2].arguments.arguments, isEmpty);
- });
-
- test("with no arguments", () {
- new File(_path).writeAsStringSync("@Annotation\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- expect(annotations.first.arguments, isNull);
- });
-
- test("with positional arguments", () {
- new File(_path).writeAsStringSync("@Annotation('foo', 12)\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- var args = annotations.first.arguments.arguments;
- expect(args, hasLength(2));
- expect(args[0], new isInstanceOf<StringLiteral>());
- expect(args[0].stringValue, equals('foo'));
- expect(args[1], new isInstanceOf<IntegerLiteral>());
- expect(args[1].value, equals(12));
- });
-
- test("with named arguments", () {
- new File(_path).writeAsStringSync(
- "@Annotation(name1: 'foo', name2: 12)\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- var args = annotations.first.arguments.arguments;
- expect(args, hasLength(2));
- expect(args[0], new isInstanceOf<NamedExpression>());
- expect(args[0].expression, new isInstanceOf<StringLiteral>());
- expect(args[0].expression.stringValue, equals('foo'));
- expect(args[1], new isInstanceOf<IntegerLiteral>());
- expect(args[1].expression, new isInstanceOf<IntegerLiteral>());
- expect(args[1].expression.value, equals(12));
- });
-
- test("with a prefix/named constructor", () {
- new File(_path).writeAsStringSync("@Annotation.name()\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name, new isInstanceOf<PrefixedIdentifier>());
- expect(annotations.first.name.prefix.name, equals('Annotation'));
- expect(annotations.first.name.identifier.name, equals('name'));
- expect(annotations.first.constructorName, isNull);
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("with a prefix and named constructor", () {
- new File(_path).writeAsStringSync(
- "@prefix.Annotation.name()\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name, new isInstanceOf<PrefixedIdentifier>());
- expect(annotations.first.name.prefix.name, equals('prefix'));
- expect(annotations.first.name.identifier.name, equals('Annotation'));
- expect(annotations.first.constructorName.name, equals('name'));
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("annotations after the first directive are ignored", () {
- new File(_path).writeAsStringSync(
- "library foo;\n@prefix.Annotation.name()");
-
- expect(parseAnnotations(_path), isEmpty);
- });
-
- group("comments are ignored", () {
- test("before an annotation", () {
- new File(_path).writeAsStringSync(
- "/* comment */@Annotation()\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("within an annotation", () {
- new File(_path).writeAsStringSync(
- "@Annotation(/* comment */)\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("after an annotation", () {
- new File(_path).writeAsStringSync(
- "@Annotation()/* comment */\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(1));
- expect(annotations.first.name.name, equals('Annotation'));
- expect(annotations.first.arguments.arguments, isEmpty);
- });
-
- test("between annotations", () {
- new File(_path).writeAsStringSync(
- "@Annotation1()/* comment */@Annotation2()\nlibrary foo;");
-
- var annotations = parseAnnotations(_path);
- expect(annotations, hasLength(2));
- expect(annotations[0].name.name, equals('Annotation1'));
- expect(annotations[0].arguments.arguments, isEmpty);
- expect(annotations[1].name.name, equals('Annotation2'));
- expect(annotations[1].arguments.arguments, isEmpty);
- });
- });
-}
« no previous file with comments | « test/runner/parse_metadata_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698