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

Side by Side Diff: tests/compiler/dart2js/private_test.dart

Issue 1062913003: Extract CallStructure from Selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix expentancy in unittest Created 5 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 import 'dart:async';
5 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
6 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
7 import 'mock_compiler.dart'; 8 import 'mock_compiler.dart';
8 9
9 import 'package:compiler/src/io/source_file.dart'; 10 import 'package:compiler/src/io/source_file.dart';
10 import 'package:compiler/src/dart2jslib.dart'; 11 import 'package:compiler/src/dart2jslib.dart';
11 12
12 const String PRIVATE_SOURCE_URI = 'src:private'; 13 const String PRIVATE_SOURCE_URI = 'src:private';
13 const String PRIVATE_SOURCE = ''' 14 const String PRIVATE_SOURCE = '''
14 15
(...skipping 19 matching lines...) Expand all
34 class PublicClass extends _PrivateClass { 35 class PublicClass extends _PrivateClass {
35 PublicClass() : super(); 36 PublicClass() : super();
36 PublicClass.publicConstructor() : super.publicConstructor(); 37 PublicClass.publicConstructor() : super.publicConstructor();
37 PublicClass._privateConstructor() : super._privateConstructor(); 38 PublicClass._privateConstructor() : super._privateConstructor();
38 39
39 _PrivateClass get private => this; 40 _PrivateClass get private => this;
40 } 41 }
41 '''; 42 ''';
42 43
43 44
44 void analyze(String text, [expectedWarnings]) { 45 analyze(String text, [expectedWarnings]) {
45 if (expectedWarnings == null) expectedWarnings = []; 46 return () {
46 if (expectedWarnings is !List) expectedWarnings = [expectedWarnings]; 47 if (expectedWarnings == null) expectedWarnings = [];
48 if (expectedWarnings is !List) expectedWarnings = [expectedWarnings];
47 49
48 MockCompiler compiler = new MockCompiler.internal(analyzeOnly: true); 50 MockCompiler compiler = new MockCompiler.internal(analyzeOnly: true);
49 compiler.registerSource(Uri.parse(PRIVATE_SOURCE_URI), PRIVATE_SOURCE); 51 compiler.registerSource(Uri.parse(PRIVATE_SOURCE_URI), PRIVATE_SOURCE);
50 compiler.diagnosticHandler = (uri, int begin, int end, String message, kind) { 52 compiler.diagnosticHandler =
51 SourceFile sourceFile = compiler.sourceFiles[uri.toString()]; 53 (uri, int begin, int end, String message, kind) {
52 if (sourceFile != null) { 54 SourceFile sourceFile = compiler.sourceFiles[uri.toString()];
53 print(sourceFile.getLocationMessage(message, begin, end)); 55 if (sourceFile != null) {
54 } else { 56 print(sourceFile.getLocationMessage(message, begin, end));
55 print(message); 57 } else {
56 } 58 print(message);
59 }
60 };
61
62 String source = '''
63 library public;
64
65 import '$PRIVATE_SOURCE_URI';
66
67 void main() {
68 PublicClass publicClass;
69 $text
70 }
71 ''';
72 Uri uri = Uri.parse('src:public');
73 compiler.registerSource(uri, source);
74 return compiler.runCompiler(uri).then((_) {
75 compareWarningKinds(text, expectedWarnings, compiler.warnings);
76 });
57 }; 77 };
58
59 String source = '''
60 library public;
61
62 import '$PRIVATE_SOURCE_URI';
63
64 void main() {
65 PublicClass publicClass;
66 $text
67 }
68 ''';
69 Uri uri = Uri.parse('src:public');
70 compiler.registerSource(uri, source);
71 asyncTest(() => compiler.runCompiler(uri).then((_) {
72 compareWarningKinds(text, expectedWarnings, compiler.warnings);
73 }));
74 } 78 }
75 79
76 void main() { 80 void main() {
77 // Read from private variable. 81 asyncTest(() => Future.forEach([
78 analyze('var value = _privateVariable;', MessageKind.CANNOT_RESOLVE); 82 // Read from private variable.
79 // Write to private variable. 83 analyze('var value = _privateVariable;', MessageKind.CANNOT_RESOLVE),
80 analyze('_privateVariable = 0;', MessageKind.CANNOT_RESOLVE); 84 // Write to private variable.
81 // Access private function. 85 analyze('_privateVariable = 0;', MessageKind.CANNOT_RESOLVE),
82 analyze('var value = _privateFunction;', MessageKind.CANNOT_RESOLVE); 86 // Access private function.
83 // Call private function. 87 analyze('var value = _privateFunction;', MessageKind.CANNOT_RESOLVE),
84 analyze('_privateFunction();', MessageKind.CANNOT_RESOLVE); 88 // Call private function.
89 analyze('_privateFunction();', MessageKind.CANNOT_RESOLVE),
85 90
86 // Call unnamed (public) constructor on private class. 91 // Call unnamed (public) constructor on private class.
87 analyze('new _PrivateClass();', MessageKind.CANNOT_RESOLVE); 92 analyze('new _PrivateClass();', MessageKind.CANNOT_RESOLVE),
88 // Call public constructor on private class. 93 // Call public constructor on private class.
89 analyze('new _PrivateClass.publicConstructor();', 94 analyze('new _PrivateClass.publicConstructor();',
90 MessageKind.CANNOT_RESOLVE); 95 MessageKind.CANNOT_RESOLVE),
91 // Call private constructor on private class. 96 // Call private constructor on private class.
92 analyze('new _PrivateClass._privateConstructor();', 97 analyze('new _PrivateClass._privateConstructor();',
93 MessageKind.CANNOT_RESOLVE); 98 MessageKind.CANNOT_RESOLVE),
94 // Call public getter of private type. 99 // Call public getter of private type.
95 analyze('var value = publicClass.private;'); 100 analyze('var value = publicClass.private;'),
96 // Read from private field on private class. 101 // Read from private field on private class.
97 analyze('var value = publicClass.private._privateField;', 102 analyze('var value = publicClass.private._privateField;',
98 MessageKind.PRIVATE_ACCESS); 103 MessageKind.PRIVATE_ACCESS),
99 // Write to private field on private class. 104 // Write to private field on private class.
100 analyze('publicClass.private._privateField = 0;', 105 analyze('publicClass.private._privateField = 0;',
101 MessageKind.PRIVATE_ACCESS); 106 MessageKind.PRIVATE_ACCESS),
102 // Call private getter on private class. 107 // Call private getter on private class.
103 analyze('var value = publicClass.private._privateGetter;', 108 analyze('var value = publicClass.private._privateGetter;',
104 MessageKind.PRIVATE_ACCESS); 109 MessageKind.PRIVATE_ACCESS),
105 // Call private setter on private class. 110 // Call private setter on private class.
106 analyze('publicClass.private._privateSetter = 0;', 111 analyze('publicClass.private._privateSetter = 0;',
107 MessageKind.PRIVATE_ACCESS); 112 MessageKind.PRIVATE_ACCESS),
108 // Access private method on private class. 113 // Access private method on private class.
109 analyze('var value = publicClass.private._privateMethod;', 114 analyze('var value = publicClass.private._privateMethod;',
110 MessageKind.PRIVATE_ACCESS); 115 MessageKind.PRIVATE_ACCESS),
111 // Call private method on private class. 116 // Call private method on private class.
112 analyze('publicClass.private._privateMethod();', 117 analyze('publicClass.private._privateMethod();',
113 MessageKind.PRIVATE_ACCESS); 118 MessageKind.PRIVATE_ACCESS),
114 119
115 // Read from public field on private class. 120 // Read from public field on private class.
116 analyze('var value = publicClass.private.publicField;'); 121 analyze('var value = publicClass.private.publicField;'),
117 // Write to public field on private class. 122 // Write to public field on private class.
118 analyze('publicClass.private.publicField = 0;'); 123 analyze('publicClass.private.publicField = 0;'),
119 // Call public getter on private class. 124 // Call public getter on private class.
120 analyze('var value = publicClass.private.publicGetter;'); 125 analyze('var value = publicClass.private.publicGetter;'),
121 // Call public setter on private class. 126 // Call public setter on private class.
122 analyze('publicClass.private.publicSetter = 0;'); 127 analyze('publicClass.private.publicSetter = 0;'),
123 // Access public method on private class. 128 // Access public method on private class.
124 analyze('var value = publicClass.private.publicMethod;'); 129 analyze('var value = publicClass.private.publicMethod;'),
125 // Call public method on private class. 130 // Call public method on private class.
126 analyze('publicClass.private.publicMethod();'); 131 analyze('publicClass.private.publicMethod();'),
127 132
128 // Call unnamed (public) constructor on public class. 133 // Call unnamed (public) constructor on public class.
129 analyze('publicClass = new PublicClass();'); 134 analyze('publicClass = new PublicClass();'),
130 // Call public constructor on public class. 135 // Call public constructor on public class.
131 analyze('publicClass = new PublicClass.publicConstructor();'); 136 analyze('publicClass = new PublicClass.publicConstructor();'),
132 // Call private constructor on public class. 137 // Call private constructor on public class.
133 analyze('publicClass = new PublicClass._privateConstructor();', 138 analyze('publicClass = new PublicClass._privateConstructor();',
134 MessageKind.PRIVATE_ACCESS); 139 MessageKind.CANNOT_FIND_CONSTRUCTOR),
135 // Read from private field on public class. 140 // Read from private field on public class.
136 analyze('var value = publicClass._privateField;', 141 analyze('var value = publicClass._privateField;',
137 MessageKind.PRIVATE_ACCESS); 142 MessageKind.PRIVATE_ACCESS),
138 // Write to private field on public class. 143 // Write to private field on public class.
139 analyze('publicClass._privateField = 0;', 144 analyze('publicClass._privateField = 0;',
140 MessageKind.PRIVATE_ACCESS); 145 MessageKind.PRIVATE_ACCESS),
141 // Call private getter on public class. 146 // Call private getter on public class.
142 analyze('var value = publicClass._privateGetter;', 147 analyze('var value = publicClass._privateGetter;',
143 MessageKind.PRIVATE_ACCESS); 148 MessageKind.PRIVATE_ACCESS),
144 // Call private setter on public class. 149 // Call private setter on public class.
145 analyze('publicClass._privateSetter = 0;', 150 analyze('publicClass._privateSetter = 0;',
146 MessageKind.PRIVATE_ACCESS); 151 MessageKind.PRIVATE_ACCESS),
147 // Access private method on public class. 152 // Access private method on public class.
148 analyze('var value = publicClass._privateMethod;', 153 analyze('var value = publicClass._privateMethod;',
149 MessageKind.PRIVATE_ACCESS); 154 MessageKind.PRIVATE_ACCESS),
150 // Call private method on public class. 155 // Call private method on public class.
151 analyze('publicClass._privateMethod();', 156 analyze('publicClass._privateMethod();',
152 MessageKind.PRIVATE_ACCESS); 157 MessageKind.PRIVATE_ACCESS),
153 158
154 // Read from public field on public class. 159 // Read from public field on public class.
155 analyze('var value = publicClass.publicField;'); 160 analyze('var value = publicClass.publicField;'),
156 // Write to public field on public class. 161 // Write to public field on public class.
157 analyze('publicClass.publicField = 0;'); 162 analyze('publicClass.publicField = 0;'),
158 // Call public getter on public class. 163 // Call public getter on public class.
159 analyze('var value = publicClass.publicGetter;'); 164 analyze('var value = publicClass.publicGetter;'),
160 // Call public setter on public class. 165 // Call public setter on public class.
161 analyze('publicClass.publicSetter = 0;'); 166 analyze('publicClass.publicSetter = 0;'),
162 // Access public method on public class. 167 // Access public method on public class.
163 analyze('var value = publicClass.publicMethod;'); 168 analyze('var value = publicClass.publicMethod;'),
164 // Call public method on public class. 169 // Call public method on public class.
165 analyze('publicClass.publicMethod();'); 170 analyze('publicClass.publicMethod();'),
171 ], (f) => f()));
166 } 172 }
167 173
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698