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

Side by Side Diff: test/directive_parser_test.dart

Issue 11275029: Support for specifying an output directory (issue #106) (Closed) Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library directive_parser_test;
6
7 import 'package:unittest/unittest.dart';
8 import 'package:unittest/vm_config.dart';
9 import 'package:web_components/src/info.dart' show DartCodeInfo;
10 import 'package:web_components/src/messages.dart' show messages;
11 import 'package:web_components/src/directive_parser.dart';
12 import 'testing.dart';
13
14 main() {
15 useVmConfiguration();
16 useMockMessages();
17
18 test('empty contents', () {
19 var info = parseDartCode('', messages);
20 expect(info, isNotNull);
21 expect(info.libraryName, isNull);
22 expect(info.partOf, isNull);
23 expect(info.directives, isEmpty);
24 expect(info.code, isEmpty);
25 });
26
27 test('no directives, no code', () {
28 var code = '/* a comment */\n\n/** another *///foo\n';
29 var info = parseDartCode(code, messages);
30 expect(info, isNotNull);
31 expect(info.libraryName, isNull);
32 expect(info.partOf, isNull);
33 expect(info.directives, isEmpty);
34 expect(info.code, isEmpty);
35 });
36
37 test('no directives, some code', () {
38 var code = '/* a comment */\n\n/** another *///foo\ncode();';
39 var info = parseDartCode(code, messages);
40 expect(info, isNotNull);
41 expect(info.libraryName, isNull);
42 expect(info.partOf, isNull);
43 expect(info.directives, isEmpty);
44 expect(info.code, equals('code();'));
45 });
46
47 test('library, but no directives', () {
48 var code = '// a comment\n library foo;\n/* \n\n */ code();\n';
49 var info = parseDartCode(code, messages);
50 expect(info, isNotNull);
51 expect(info.libraryName, equals('foo'));
52 expect(info.partOf, isNull);
53 expect(info.directives, isEmpty);
54 expect(info.code, equals('code();\n'));
55 });
56
57 test('directives, but no library', () {
58 var code = 'import "url";\n code();\n';
59 var info = parseDartCode(code, messages);
60 expect(info, isNotNull);
61 expect(info.libraryName, isNull);
62 expect(info.partOf, isNull);
63 expect(info.directives, hasLength(1));
64 expect(info.directives[0].uri, equals('url'));
65 expect(info.directives[0].prefix, isNull);
66 expect(info.directives[0].hide, isNull);
67 expect(info.directives[0].show, isNull);
68 expect(info.code, equals('code();\n'));
69 });
70
71 test('directives, no prefix', () {
72 var code = 'library foo.bar; import \'url2\';\n'
73 'export \'foo.dart\';\npart "part.dart";\n code();\n';
74 var info = parseDartCode(code, messages);
75 expect(info, isNotNull);
76 expect(info.libraryName, equals('foo.bar'));
77 expect(info.partOf, isNull);
78 expect(info.directives, hasLength(3));
79 expect(info.directives[0].label, equals('import'));
80 expect(info.directives[0].uri, equals('url2'));
81 expect(info.directives[0].prefix, isNull);
82 expect(info.directives[0].hide, isNull);
83 expect(info.directives[0].show, isNull);
84 expect(info.directives[1].label, equals('export'));
85 expect(info.directives[1].uri, equals('foo.dart'));
86 expect(info.directives[1].prefix, isNull);
87 expect(info.directives[1].hide, isNull);
88 expect(info.directives[1].show, isNull);
89 expect(info.directives[2].label, equals('part'));
90 expect(info.directives[2].uri, equals("part.dart"));
91 expect(info.code, equals('code();\n'));
92 });
93
94 test('part-of, but no directives', () {
95 var code = '/* ... */ part of foo.bar;\n/* \n\n */ code();\n';
96 var info = parseDartCode(code, messages);
97 expect(info, isNotNull);
98 expect(info.libraryName, isNull);
99 expect(info.partOf, equals('foo.bar'));
100 expect(info.directives, isEmpty);
101 expect(info.code, equals('code();\n'));
102 });
103
104 test('directives with prefix', () {
105 var code = 'library f;'
106 'import "a1.dart" as first;\n'
107 'import "a2.dart" as second;\n'
108 'import "a3.dart" as i3;\n'
109 'code();\n';
110 var info = parseDartCode(code, messages);
111 expect(info, isNotNull);
112 expect(info.libraryName, equals('f'));
113 expect(info.partOf, isNull);
114 expect(info.directives, hasLength(3));
115 expect(info.directives[0].label, equals('import'));
116 expect(info.directives[0].uri, equals('a1.dart'));
117 expect(info.directives[0].prefix, equals('first'));
118 expect(info.directives[0].hide, isNull);
119 expect(info.directives[0].show, isNull);
120 expect(info.directives[1].label, equals('import'));
121 expect(info.directives[1].uri, equals('a2.dart'));
122 expect(info.directives[1].prefix, equals('second'));
123 expect(info.directives[1].hide, isNull);
124 expect(info.directives[1].show, isNull);
125 expect(info.directives[2].label, equals('import'));
126 expect(info.directives[2].uri, equals('a3.dart'));
127 expect(info.directives[2].prefix, equals('i3'));
128 expect(info.directives[2].hide, isNull);
129 expect(info.directives[2].show, isNull);
130 expect(info.code, equals('code();\n'));
131 });
132
133 test('directives with combinators', () {
134 var code = 'library f;'
135 'import "a1.dart" as a1 show one, two hide bar;\n'
136 'export "a2.dart" show a, b, c hide d, e;\n'
137 'code();\n';
138 var info = parseDartCode(code, messages);
139 expect(info, isNotNull);
140 expect(info.libraryName, equals('f'));
141 expect(info.partOf, isNull);
142 expect(info.directives, hasLength(2));
143 expect(info.directives[0].label, equals('import'));
144 expect(info.directives[0].uri, equals('a1.dart'));
145 expect(info.directives[0].prefix, equals('a1'));
146 expect(info.directives[0].hide, equals(['bar']));
147 expect(info.directives[0].show, equals(['one', 'two']));
148 expect(info.directives[1].label, equals('export'));
149 expect(info.directives[1].uri, equals('a2.dart'));
150 expect(info.directives[1].prefix, isNull);
151 expect(info.directives[1].hide, equals(['d', 'e']));
152 expect(info.directives[1].show, equals(['a', 'b', 'c']));
153 expect(info.code, equals('code();\n'));
154 });
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698