OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dev_compiler.test.closure_annotation_test; | 5 library dev_compiler.test.closure_annotation_test; |
6 | 6 |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 | 8 |
9 import 'package:dev_compiler/src/closure/closure_annotation.dart'; | 9 import 'package:dev_compiler/src/closure/closure_annotation.dart'; |
10 import 'package:dev_compiler/src/closure/closure_type.dart'; | 10 import 'package:dev_compiler/src/js/js_ast.dart' show TypeRef, Identifier; |
11 | 11 |
12 void main() { | 12 void main() { |
13 group('ClosureAnnotation', () { | 13 group('ClosureAnnotation', () { |
14 var allType = new ClosureType.all(); | 14 var anyType = new TypeRef.any(); |
15 var unknownType = new ClosureType.unknown(); | 15 var unknownType = new TypeRef.unknown(); |
16 var numberType = new ClosureType.number(); | 16 var numberType = new TypeRef.number(); |
17 var stringType = new ClosureType.string(); | 17 var stringType = new TypeRef.string(); |
18 var booleanType = new ClosureType.boolean(); | 18 var booleanType = new TypeRef.boolean(); |
19 var fooType = new ClosureType.type("foo.Foo"); | 19 var fooType = new TypeRef.qualified( |
20 var barType = new ClosureType.type("bar.Bar"); | 20 [new Identifier("foo"), new Identifier("Foo")]); |
21 var bazType = new ClosureType.type("baz.Baz"); | 21 var barType = new TypeRef.named("Bar"); |
22 var bamType = new ClosureType.type("bam.Bam"); | 22 var bazType = new TypeRef.named("Baz"); |
23 var batType = new ClosureType.type("bat.Bat"); | 23 var bamType = new TypeRef.named("Bam"); |
| 24 var batType = new TypeRef.named("Bat"); |
24 | 25 |
25 test('gives empty comment when no has no meaningful info', () { | 26 test('gives empty comment when no has no meaningful info', () { |
26 expect(new ClosureAnnotation().toString(), ""); | 27 expect(new ClosureAnnotation().toString(), ""); |
27 expect(new ClosureAnnotation(type: allType).toString(), ""); | 28 expect(new ClosureAnnotation(type: anyType).toString(), ""); |
28 expect(new ClosureAnnotation(type: unknownType).toString(), ""); | 29 expect(new ClosureAnnotation(type: unknownType).toString(), ""); |
29 }); | 30 }); |
30 | 31 |
31 test('gives single line comment when it fits', () { | 32 test('gives single line comment when it fits', () { |
32 expect(new ClosureAnnotation(type: numberType).toString(), | 33 expect(new ClosureAnnotation(type: numberType).toString(), |
33 "/** @type {number} */"); | 34 "/** @type {number} */"); |
34 expect(new ClosureAnnotation(paramTypes: {'foo': allType}).toString(), | 35 expect(new ClosureAnnotation(paramTypes: {'foo': anyType}).toString(), |
35 "/** @param {*} foo */"); | 36 "/** @param {*} foo */"); |
36 expect(new ClosureAnnotation(paramTypes: {'foo': unknownType}).toString(), | 37 expect(new ClosureAnnotation(paramTypes: {'foo': unknownType}).toString(), |
37 "/** @param {?} foo */"); | 38 "/** @param {?} foo */"); |
38 }); | 39 }); |
39 | 40 |
40 test('gives multiple line comment when it it does not fit on one line', () { | 41 test('gives multiple line comment when it it does not fit on one line', () { |
41 expect(new ClosureAnnotation( | 42 expect(new ClosureAnnotation( |
42 returnType: stringType, paramTypes: {'foo': numberType}) | 43 returnType: stringType, paramTypes: {'foo': numberType}) |
43 .toString(), | 44 .toString(), |
44 "/**\n" | 45 "/**\n" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 isNoSideEffects: true, | 103 isNoSideEffects: true, |
103 isNoCollapse: true, | 104 isNoCollapse: true, |
104 paramTypes: {'x': stringType, 'y': numberType}, | 105 paramTypes: {'x': stringType, 'y': numberType}, |
105 templates: ['A', 'B']).toString(), | 106 templates: ['A', 'B']).toString(), |
106 '/**\n' | 107 '/**\n' |
107 ' * @template A, B\n' | 108 ' * @template A, B\n' |
108 ' * @this {foo.Foo}\n' | 109 ' * @this {foo.Foo}\n' |
109 ' * @override\n' | 110 ' * @override\n' |
110 ' * @nosideeffects\n' | 111 ' * @nosideeffects\n' |
111 ' * @nocollapse\n' | 112 ' * @nocollapse\n' |
112 ' * @lends {bat.Bat}\n' | 113 ' * @lends {Bat}\n' |
113 ' * @private @protected @final @const\n' | 114 ' * @private @protected @final @const\n' |
114 ' * @constructor @struct @extends {bar.Bar}\n' | 115 ' * @constructor @struct @extends {Bar}\n' |
115 ' * @implements {baz.Baz}\n' | 116 ' * @implements {Baz}\n' |
116 ' * @param {string} x\n' | 117 ' * @param {string} x\n' |
117 ' * @param {number} y\n' | 118 ' * @param {number} y\n' |
118 ' * @return {boolean}\n' | 119 ' * @return {boolean}\n' |
119 ' * @throws {bam.Bam}\n' | 120 ' * @throws {Bam}\n' |
120 ' */'); | 121 ' */'); |
121 }); | 122 }); |
122 }); | 123 }); |
123 } | 124 } |
OLD | NEW |