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/js_ast/js_ast.dart' show TypeRef, Identifier; | 10 import 'package:dev_compiler/src/js_ast/js_ast.dart' show TypeRef, Identifier; |
11 | 11 |
12 void main() { | 12 void main() { |
13 group('ClosureAnnotation', () { | 13 group('ClosureAnnotation', () { |
14 var anyType = new TypeRef.any(); | 14 var anyType = new TypeRef.any(); |
15 var unknownType = new TypeRef.unknown(); | 15 var unknownType = new TypeRef.unknown(); |
16 var numberType = new TypeRef.number(); | 16 var numberType = new TypeRef.number(); |
17 var stringType = new TypeRef.string(); | 17 var stringType = new TypeRef.string(); |
18 var booleanType = new TypeRef.boolean(); | 18 var booleanType = new TypeRef.boolean(); |
19 var fooType = new TypeRef.qualified( | 19 var fooType = |
20 [new Identifier("foo"), new Identifier("Foo")]); | 20 new TypeRef.qualified([new Identifier("foo"), new Identifier("Foo")]); |
21 var barType = new TypeRef.named("Bar"); | 21 var barType = new TypeRef.named("Bar"); |
22 var bazType = new TypeRef.named("Baz"); | 22 var bazType = new TypeRef.named("Baz"); |
23 var bamType = new TypeRef.named("Bam"); | 23 var bamType = new TypeRef.named("Bam"); |
24 var batType = new TypeRef.named("Bat"); | 24 var batType = new TypeRef.named("Bat"); |
25 | 25 |
26 test('gives empty comment when no has no meaningful info', () { | 26 test('gives empty comment when no has no meaningful info', () { |
27 expect(new ClosureAnnotation().toString(), ""); | 27 expect(new ClosureAnnotation().toString(), ""); |
28 expect(new ClosureAnnotation(type: anyType).toString(), ""); | 28 expect(new ClosureAnnotation(type: anyType).toString(), ""); |
29 expect(new ClosureAnnotation(type: unknownType).toString(), ""); | 29 expect(new ClosureAnnotation(type: unknownType).toString(), ""); |
30 }); | 30 }); |
31 | 31 |
32 test('gives single line comment when it fits', () { | 32 test('gives single line comment when it fits', () { |
33 expect(new ClosureAnnotation(type: numberType).toString(), | 33 expect(new ClosureAnnotation(type: numberType).toString(), |
34 "/** @type {number} */"); | 34 "/** @type {number} */"); |
35 expect(new ClosureAnnotation(paramTypes: {'foo': anyType}).toString(), | 35 expect(new ClosureAnnotation(paramTypes: {'foo': anyType}).toString(), |
36 "/** @param {*} foo */"); | 36 "/** @param {*} foo */"); |
37 expect(new ClosureAnnotation(paramTypes: {'foo': unknownType}).toString(), | 37 expect(new ClosureAnnotation(paramTypes: {'foo': unknownType}).toString(), |
38 "/** @param {?} foo */"); | 38 "/** @param {?} foo */"); |
39 }); | 39 }); |
40 | 40 |
41 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', () { |
42 expect(new ClosureAnnotation( | 42 expect( |
43 returnType: stringType, paramTypes: {'foo': numberType}) | 43 new ClosureAnnotation( |
44 .toString(), | 44 returnType: stringType, |
| 45 paramTypes: {'foo': numberType}).toString(), |
45 "/**\n" | 46 "/**\n" |
46 " * @param {number} foo\n" | 47 " * @param {number} foo\n" |
47 " * @return {string}\n" | 48 " * @return {string}\n" |
48 " */"); | 49 " */"); |
49 }); | 50 }); |
50 | 51 |
51 test('inserts indentation', () { | 52 test('inserts indentation', () { |
52 expect(new ClosureAnnotation( | 53 expect( |
53 returnType: stringType, paramTypes: {'foo': numberType}) | 54 new ClosureAnnotation( |
54 .toString(" "), | 55 returnType: stringType, |
| 56 paramTypes: {'foo': numberType}).toString(" "), |
55 "/**\n" // No indent on first line. | 57 "/**\n" // No indent on first line. |
56 " * @param {number} foo\n" | 58 " * @param {number} foo\n" |
57 " * @return {string}\n" | 59 " * @return {string}\n" |
58 " */"); | 60 " */"); |
59 }); | 61 }); |
60 | 62 |
61 test('compresses @type, @final, @const, @private, @protected, @typedef', | 63 test('compresses @type, @final, @const, @private, @protected, @typedef', |
62 () { | 64 () { |
63 expect(new ClosureAnnotation(type: stringType).toString(), | 65 expect(new ClosureAnnotation(type: stringType).toString(), |
64 "/** @type {string} */"); | 66 "/** @type {string} */"); |
65 expect(new ClosureAnnotation(type: stringType, isConst: true).toString(), | 67 expect(new ClosureAnnotation(type: stringType, isConst: true).toString(), |
66 "/** @const {string} */"); | 68 "/** @const {string} */"); |
67 expect(new ClosureAnnotation(type: stringType, isFinal: true).toString(), | 69 expect(new ClosureAnnotation(type: stringType, isFinal: true).toString(), |
68 "/** @final {string} */"); | 70 "/** @final {string} */"); |
69 expect( | 71 expect( |
70 new ClosureAnnotation(type: stringType, isPrivate: true).toString(), | 72 new ClosureAnnotation(type: stringType, isPrivate: true).toString(), |
71 "/** @private {string} */"); | 73 "/** @private {string} */"); |
72 expect( | 74 expect( |
73 new ClosureAnnotation(type: stringType, isTypedef: true).toString(), | 75 new ClosureAnnotation(type: stringType, isTypedef: true).toString(), |
74 "/** @typedef {string} */"); | 76 "/** @typedef {string} */"); |
75 expect( | 77 expect( |
76 new ClosureAnnotation(type: stringType, isProtected: true).toString(), | 78 new ClosureAnnotation(type: stringType, isProtected: true).toString(), |
77 "/** @protected {string} */"); | 79 "/** @protected {string} */"); |
78 expect(new ClosureAnnotation( | 80 expect( |
79 type: stringType, | 81 new ClosureAnnotation( |
80 isPrivate: true, | 82 type: stringType, |
81 isConst: true, | 83 isPrivate: true, |
82 isFinal: true, | 84 isConst: true, |
83 isProtected: true, | 85 isFinal: true, |
84 isTypedef: true).toString(), | 86 isProtected: true, |
| 87 isTypedef: true) |
| 88 .toString(), |
85 "/** @private @protected @final @const @typedef {string} */"); | 89 "/** @private @protected @final @const @typedef {string} */"); |
86 }); | 90 }); |
87 | 91 |
88 test('supports a full constructor annotation', () { | 92 test('supports a full constructor annotation', () { |
89 expect(new ClosureAnnotation( | 93 expect( |
| 94 new ClosureAnnotation( |
90 returnType: booleanType, | 95 returnType: booleanType, |
91 throwsType: bamType, | 96 throwsType: bamType, |
92 thisType: fooType, | 97 thisType: fooType, |
93 superType: barType, | 98 superType: barType, |
94 lendsToType: batType, | 99 lendsToType: batType, |
95 interfaces: [bazType], | 100 interfaces: [bazType], |
96 isStruct: true, | 101 isStruct: true, |
97 isPrivate: true, | 102 isPrivate: true, |
98 isProtected: true, | 103 isProtected: true, |
99 isOverride: true, | 104 isOverride: true, |
(...skipping 15 matching lines...) Expand all Loading... |
115 ' * @constructor @struct @extends {Bar}\n' | 120 ' * @constructor @struct @extends {Bar}\n' |
116 ' * @implements {Baz}\n' | 121 ' * @implements {Baz}\n' |
117 ' * @param {string} x\n' | 122 ' * @param {string} x\n' |
118 ' * @param {number} y\n' | 123 ' * @param {number} y\n' |
119 ' * @return {boolean}\n' | 124 ' * @return {boolean}\n' |
120 ' * @throws {Bam}\n' | 125 ' * @throws {Bam}\n' |
121 ' */'); | 126 ' */'); |
122 }); | 127 }); |
123 }); | 128 }); |
124 } | 129 } |
OLD | NEW |