OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart'; | 4 import 'package:kernel/ast.dart'; |
5 import 'package:kernel/text/ast_to_text.dart'; | 5 import 'package:kernel/text/ast_to_text.dart'; |
6 import 'package:kernel/verifier.dart'; | 6 import 'package:kernel/verifier.dart'; |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 | 8 |
9 /// Checks that the verifier correctly find errors in invalid programs. | 9 /// Checks that the verifier correctly find errors in invalid programs. |
10 /// | 10 /// |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 negativeTest('Missing block parent pointer', () { | 118 negativeTest('Missing block parent pointer', () { |
119 var block = new Block([]); | 119 var block = new Block([]); |
120 block.statements.add(new ReturnStatement()); | 120 block.statements.add(new ReturnStatement()); |
121 return block; | 121 return block; |
122 }); | 122 }); |
123 negativeTest('Missing function parent pointer', () { | 123 negativeTest('Missing function parent pointer', () { |
124 var procedure = new Procedure(new Name('test'), ProcedureKind.Method, null); | 124 var procedure = new Procedure(new Name('test'), ProcedureKind.Method, null); |
125 procedure.function = new FunctionNode(new EmptyStatement()); | 125 procedure.function = new FunctionNode(new EmptyStatement()); |
126 return procedure; | 126 return procedure; |
127 }); | 127 }); |
| 128 negativeTest('StaticGet without target', () { |
| 129 return new StaticGet(null); |
| 130 }); |
| 131 negativeTest('StaticSet without target', () { |
| 132 return new StaticSet(null, new NullLiteral()); |
| 133 }); |
| 134 negativeTest('StaticInvocation without target', () { |
| 135 return new StaticInvocation(null, new Arguments.empty()); |
| 136 }); |
| 137 positiveTest('Correct StaticInvocation', () { |
| 138 var method = new Procedure(new Name('test'), ProcedureKind.Method, null, |
| 139 isStatic: true); |
| 140 method.function = new FunctionNode( |
| 141 new ReturnStatement( |
| 142 new StaticInvocation(method, new Arguments([new NullLiteral()]))), |
| 143 positionalParameters: [new VariableDeclaration('p')])..parent = method; |
| 144 return new Class( |
| 145 name: 'Test', |
| 146 supertype: objectClass.asRawSupertype, |
| 147 procedures: [method]); |
| 148 }); |
| 149 negativeTest('StaticInvocation with too many parameters', () { |
| 150 var method = new Procedure(new Name('test'), ProcedureKind.Method, null, |
| 151 isStatic: true); |
| 152 method.function = new FunctionNode(new ReturnStatement( |
| 153 new StaticInvocation(method, new Arguments([new NullLiteral()])))) |
| 154 ..parent = method; |
| 155 return new Class( |
| 156 name: 'Test', |
| 157 supertype: objectClass.asRawSupertype, |
| 158 procedures: [method]); |
| 159 }); |
| 160 negativeTest('StaticInvocation with too few parameters', () { |
| 161 var method = new Procedure(new Name('test'), ProcedureKind.Method, null, |
| 162 isStatic: true); |
| 163 method.function = new FunctionNode( |
| 164 new ReturnStatement( |
| 165 new StaticInvocation(method, new Arguments.empty())), |
| 166 positionalParameters: [new VariableDeclaration('p')])..parent = method; |
| 167 return new Class( |
| 168 name: 'Test', |
| 169 supertype: objectClass.asRawSupertype, |
| 170 procedures: [method]); |
| 171 }); |
| 172 negativeTest('StaticInvocation with unmatched named parameter', () { |
| 173 var method = new Procedure(new Name('test'), ProcedureKind.Method, null, |
| 174 isStatic: true); |
| 175 method.function = new FunctionNode(new ReturnStatement(new StaticInvocation( |
| 176 method, |
| 177 new Arguments([], |
| 178 named: [new NamedExpression('p', new NullLiteral())])))) |
| 179 ..parent = method; |
| 180 return new Class( |
| 181 name: 'Test', |
| 182 supertype: objectClass.asRawSupertype, |
| 183 procedures: [method]); |
| 184 }); |
| 185 negativeTest('StaticInvocation with missing type argument', () { |
| 186 var method = new Procedure(new Name('test'), ProcedureKind.Method, null, |
| 187 isStatic: true); |
| 188 method.function = new FunctionNode( |
| 189 new ReturnStatement( |
| 190 new StaticInvocation(method, new Arguments.empty())), |
| 191 typeParameters: [makeTypeParameter()])..parent = method; |
| 192 return new Class( |
| 193 name: 'Test', |
| 194 supertype: objectClass.asRawSupertype, |
| 195 procedures: [method]); |
| 196 }); |
| 197 negativeTest('ConstructorInvocation with missing type argument', () { |
| 198 var constructor = new Constructor(null); |
| 199 constructor.function = new FunctionNode(new ReturnStatement( |
| 200 new ConstructorInvocation(constructor, new Arguments.empty()))) |
| 201 ..parent = constructor; |
| 202 return new Class( |
| 203 name: 'Test', |
| 204 typeParameters: [makeTypeParameter()], |
| 205 supertype: objectClass.asRawSupertype, |
| 206 constructors: [constructor]); |
| 207 }); |
128 } | 208 } |
129 | 209 |
130 checkHasError(Program program) { | 210 checkHasError(Program program) { |
131 bool passed = false; | 211 bool passed = false; |
132 try { | 212 try { |
133 verifyProgram(program); | 213 verifyProgram(program); |
134 passed = true; | 214 passed = true; |
135 } catch (e) {} | 215 } catch (e) {} |
136 if (passed) { | 216 if (passed) { |
137 fail('Failed to reject invalid program:\n${programToString(program)}'); | 217 fail('Failed to reject invalid program:\n${programToString(program)}'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 test(name, () { | 268 test(name, () { |
189 verifyProgram(makeProgram(makeBody)); | 269 verifyProgram(makeProgram(makeBody)); |
190 }); | 270 }); |
191 } | 271 } |
192 | 272 |
193 VariableDeclaration makeVariable() => new VariableDeclaration(null); | 273 VariableDeclaration makeVariable() => new VariableDeclaration(null); |
194 | 274 |
195 TypeParameter makeTypeParameter([String name]) { | 275 TypeParameter makeTypeParameter([String name]) { |
196 return new TypeParameter(name, new InterfaceType(objectClass)); | 276 return new TypeParameter(name, new InterfaceType(objectClass)); |
197 } | 277 } |
OLD | NEW |