Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// End-to-end test of the analyzer2dart compiler. | 5 /// End-to-end test of the analyzer2dart compiler. |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'mock_sdk.dart'; | 9 import 'mock_sdk.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 return 0; | 196 return 0; |
| 197 } | 197 } |
| 198 '''); | 198 '''); |
| 199 }); | 199 }); |
| 200 | 200 |
| 201 test('Dynamic access', () { | 201 test('Dynamic access', () { |
| 202 checkResult(''' | 202 checkResult(''' |
| 203 main(a) { | 203 main(a) { |
| 204 return a.foo; | 204 return a.foo; |
| 205 } | 205 } |
| 206 ''', ''' | |
|
Johnni Winther
2014/10/21 10:27:04
Removing redundant expected results.
| |
| 207 main(a) { | |
| 208 return a.foo; | |
| 209 } | |
| 210 '''); | 206 '''); |
| 211 | 207 |
| 212 checkResult(''' | 208 checkResult(''' |
| 213 main() { | 209 main() { |
| 214 var a = ""; | 210 var a = ""; |
| 215 return a.foo; | 211 return a.foo; |
| 216 } | 212 } |
| 217 ''', ''' | 213 ''', ''' |
| 218 main() { | 214 main() { |
| 219 return "".foo; | 215 return "".foo; |
| 220 } | 216 } |
| 221 '''); | 217 '''); |
| 222 }); | 218 }); |
| 223 | 219 |
| 224 test('Dynamic invocation', () { | 220 test('Dynamic invocation', () { |
| 225 checkResult(''' | 221 checkResult(''' |
| 226 main(a) { | 222 main(a) { |
| 227 return a.foo(0); | 223 return a.foo(0); |
| 228 } | 224 } |
| 229 ''', ''' | |
| 230 main(a) { | |
| 231 return a.foo(0); | |
| 232 } | |
| 233 '''); | 225 '''); |
| 234 | 226 |
| 235 checkResult(''' | 227 checkResult(''' |
| 236 main() { | 228 main() { |
| 237 var a = ""; | 229 var a = ""; |
| 238 return a.foo(0, 1); | 230 return a.foo(0, 1); |
| 239 } | 231 } |
| 240 ''', ''' | 232 ''', ''' |
| 241 main() { | 233 main() { |
| 242 return "".foo(0, 1); | 234 return "".foo(0, 1); |
| 243 } | 235 } |
| 244 '''); | 236 '''); |
| 245 }); | 237 }); |
| 246 | 238 |
| 247 test('Binary expressions', () { | 239 test('Binary expressions', () { |
| 248 checkResult(''' | 240 checkResult(''' |
| 249 main(a) { | 241 main(a) { |
| 250 return a + deprecated; | 242 return a + deprecated; |
| 251 } | 243 } |
| 252 ''', ''' | |
| 253 main(a) { | |
| 254 return a + deprecated; | |
| 255 } | |
| 256 '''); | 244 '''); |
| 257 | 245 |
| 258 checkResult(''' | 246 checkResult(''' |
| 259 main(a) { | 247 main(a) { |
| 260 return a - deprecated; | 248 return a - deprecated; |
| 261 } | 249 } |
| 262 ''', ''' | |
| 263 main(a) { | |
| 264 return a - deprecated; | |
| 265 } | |
| 266 '''); | 250 '''); |
| 267 | 251 |
| 268 checkResult(''' | 252 checkResult(''' |
| 269 main(a) { | 253 main(a) { |
| 270 return a * deprecated; | 254 return a * deprecated; |
| 271 } | 255 } |
| 272 ''', ''' | |
| 273 main(a) { | |
| 274 return a * deprecated; | |
| 275 } | |
| 276 '''); | 256 '''); |
| 277 | 257 |
| 278 checkResult(''' | 258 checkResult(''' |
| 279 main(a) { | 259 main(a) { |
| 280 return a / deprecated; | 260 return a / deprecated; |
| 281 } | 261 } |
| 282 ''', ''' | |
| 283 main(a) { | |
| 284 return a / deprecated; | |
| 285 } | |
| 286 '''); | 262 '''); |
| 287 | 263 |
| 288 checkResult(''' | 264 checkResult(''' |
| 289 main(a) { | 265 main(a) { |
| 290 return a ~/ deprecated; | 266 return a ~/ deprecated; |
| 291 } | 267 } |
| 292 ''', ''' | |
| 293 main(a) { | |
| 294 return a ~/ deprecated; | |
| 295 } | |
| 296 '''); | 268 '''); |
| 297 | 269 |
| 298 checkResult(''' | 270 checkResult(''' |
| 299 main(a) { | 271 main(a) { |
| 300 return a % deprecated; | 272 return a % deprecated; |
| 301 } | 273 } |
| 302 ''', ''' | |
| 303 main(a) { | |
| 304 return a % deprecated; | |
| 305 } | |
| 306 '''); | 274 '''); |
| 307 | 275 |
| 308 checkResult(''' | 276 checkResult(''' |
| 309 main(a) { | 277 main(a) { |
| 310 return a < deprecated; | 278 return a < deprecated; |
| 311 } | 279 } |
| 312 ''', ''' | |
| 313 main(a) { | |
| 314 return a < deprecated; | |
| 315 } | |
| 316 '''); | 280 '''); |
| 317 | 281 |
| 318 checkResult(''' | 282 checkResult(''' |
| 319 main(a) { | 283 main(a) { |
| 320 return a <= deprecated; | 284 return a <= deprecated; |
| 321 } | 285 } |
| 322 ''', ''' | |
| 323 main(a) { | |
| 324 return a <= deprecated; | |
| 325 } | |
| 326 '''); | 286 '''); |
| 327 | 287 |
| 328 checkResult(''' | 288 checkResult(''' |
| 329 main(a) { | 289 main(a) { |
| 330 return a > deprecated; | 290 return a > deprecated; |
| 331 } | 291 } |
| 332 ''', ''' | |
| 333 main(a) { | |
| 334 return a > deprecated; | |
| 335 } | |
| 336 '''); | 292 '''); |
| 337 | 293 |
| 338 checkResult(''' | 294 checkResult(''' |
| 339 main(a) { | 295 main(a) { |
| 340 return a >= deprecated; | 296 return a >= deprecated; |
| 341 } | 297 } |
| 342 ''', ''' | |
| 343 main(a) { | |
| 344 return a >= deprecated; | |
| 345 } | |
| 346 '''); | 298 '''); |
| 347 | 299 |
| 348 checkResult(''' | 300 checkResult(''' |
| 349 main(a) { | 301 main(a) { |
| 350 return a << deprecated; | 302 return a << deprecated; |
| 351 } | 303 } |
| 352 ''', ''' | |
| 353 main(a) { | |
| 354 return a << deprecated; | |
| 355 } | |
| 356 '''); | 304 '''); |
| 357 | 305 |
| 358 checkResult(''' | 306 checkResult(''' |
| 359 main(a) { | 307 main(a) { |
| 360 return a >> deprecated; | 308 return a >> deprecated; |
| 361 } | 309 } |
| 362 ''', ''' | |
| 363 main(a) { | |
| 364 return a >> deprecated; | |
| 365 } | |
| 366 '''); | 310 '''); |
| 367 | 311 |
| 368 checkResult(''' | 312 checkResult(''' |
| 369 main(a) { | 313 main(a) { |
| 370 return a & deprecated; | 314 return a & deprecated; |
| 371 } | 315 } |
| 372 ''', ''' | |
| 373 main(a) { | |
| 374 return a & deprecated; | |
| 375 } | |
| 376 '''); | 316 '''); |
| 377 | 317 |
| 378 checkResult(''' | 318 checkResult(''' |
| 379 main(a) { | 319 main(a) { |
| 380 return a | deprecated; | 320 return a | deprecated; |
| 381 } | 321 } |
| 382 ''', ''' | |
| 383 main(a) { | |
| 384 return a | deprecated; | |
| 385 } | |
| 386 '''); | 322 '''); |
| 387 | 323 |
| 388 checkResult(''' | 324 checkResult(''' |
| 389 main(a) { | 325 main(a) { |
| 390 return a ^ deprecated; | 326 return a ^ deprecated; |
| 391 } | 327 } |
| 392 ''', ''' | |
| 393 main(a) { | |
| 394 return a ^ deprecated; | |
| 395 } | |
| 396 '''); | 328 '''); |
| 397 | 329 |
| 398 checkResult(''' | 330 checkResult(''' |
| 399 main(a) { | 331 main(a) { |
| 400 return a == deprecated; | 332 return a == deprecated; |
| 401 } | 333 } |
| 402 ''', ''' | |
| 403 main(a) { | |
| 404 return a == deprecated; | |
| 405 } | |
| 406 '''); | 334 '''); |
| 407 | 335 |
| 408 checkResult(''' | 336 checkResult(''' |
| 409 main(a) { | 337 main(a) { |
| 410 return a != deprecated; | 338 return a != deprecated; |
| 411 } | 339 } |
| 412 ''', ''' | 340 ''', ''' |
| 413 main(a) { | 341 main(a) { |
| 414 return !(a == deprecated); | 342 return !(a == deprecated); |
| 415 } | 343 } |
| 416 '''); | 344 '''); |
| 417 | 345 |
| 418 checkResult(''' | 346 checkResult(''' |
| 419 main(a) { | 347 main(a) { |
| 420 return a || deprecated; | 348 return a || deprecated; |
| 421 } | 349 } |
| 422 ''', ''' | |
| 423 main(a) { | |
| 424 return a || deprecated; | |
| 425 } | |
| 426 '''); | 350 '''); |
| 427 | 351 |
| 428 checkResult(''' | 352 checkResult(''' |
| 429 main(a) { | 353 main(a) { |
| 430 return a && deprecated; | 354 return a && deprecated; |
| 431 } | 355 } |
| 432 ''', ''' | |
| 433 main(a) { | |
| 434 return a && deprecated; | |
| 435 } | |
| 436 '''); | 356 '''); |
| 437 }); | 357 }); |
| 438 | 358 |
| 439 test('If statement', () { | 359 test('If statement', () { |
| 440 checkResult(''' | 360 checkResult(''' |
| 441 main(a) { | 361 main(a) { |
| 442 if (a) { | 362 if (a) { |
| 443 print(0); | 363 print(0); |
| 444 } | 364 } |
| 445 } | 365 } |
| 446 ''', ''' | |
| 447 main(a) { | |
| 448 if (a) { | |
| 449 print(0); | |
| 450 } | |
| 451 } | |
| 452 '''); | 366 '''); |
| 453 | 367 |
| 454 checkResult(''' | 368 checkResult(''' |
| 455 main(a) { | 369 main(a) { |
| 456 if (a) { | 370 if (a) { |
| 457 print(0); | 371 print(0); |
| 458 } else { | 372 } else { |
| 459 print(1); | 373 print(1); |
| 460 } | 374 } |
| 461 } | 375 } |
| 462 ''', ''' | 376 ''', ''' |
| 463 main(a) { | 377 main(a) { |
| 464 a ? print(0) : print(1); | 378 a ? print(0) : print(1); |
| 465 } | 379 } |
| 466 '''); | 380 '''); |
| 467 | 381 |
| 468 checkResult(''' | 382 checkResult(''' |
| 469 main(a) { | 383 main(a) { |
| 470 if (a) { | 384 if (a) { |
| 471 print(0); | 385 print(0); |
| 472 } else { | 386 } else { |
| 473 print(1); | 387 print(1); |
| 474 print(2); | 388 print(2); |
| 475 } | 389 } |
| 476 } | 390 } |
| 477 ''', ''' | |
| 478 main(a) { | |
| 479 if (a) { | |
| 480 print(0); | |
| 481 } else { | |
| 482 print(1); | |
| 483 print(2); | |
| 484 } | |
| 485 } | |
| 486 '''); | 391 '''); |
| 487 }); | 392 }); |
| 488 | 393 |
| 489 test('If statement', () { | 394 test('If statement', () { |
| 490 checkResult(''' | 395 checkResult(''' |
| 491 main(a) { | 396 main(a) { |
| 492 return a ? print(0) : print(1); | 397 return a ? print(0) : print(1); |
| 493 } | 398 } |
| 494 ''', ''' | |
| 495 main(a) { | |
| 496 return a ? print(0) : print(1); | |
| 497 } | |
| 498 '''); | 399 '''); |
| 499 }); | 400 }); |
| 401 | |
| 402 test('List literal', () { | |
| 403 checkResult(''' | |
| 404 main() { | |
| 405 return []; | |
| 406 } | |
| 407 '''); | |
| 408 | |
| 409 checkResult(''' | |
| 410 main() { | |
| 411 return <int>[]; | |
| 412 } | |
| 413 '''); | |
| 414 | |
| 415 checkResult(''' | |
| 416 main() { | |
| 417 return <int>[0]; | |
| 418 } | |
| 419 '''); | |
| 420 | |
| 421 checkResult(''' | |
| 422 main(a) { | |
| 423 return <int>[0, 1, a]; | |
| 424 } | |
| 425 '''); | |
| 426 | |
| 427 checkResult(''' | |
| 428 main(a) { | |
| 429 return [0, [1], [a, <int>[3]]]; | |
| 430 } | |
| 431 '''); | |
| 432 }); | |
| 433 | |
| 434 test('Map literal', () { | |
| 435 checkResult(''' | |
| 436 main() { | |
| 437 return {}; | |
| 438 } | |
| 439 '''); | |
| 440 | |
| 441 checkResult(''' | |
| 442 main() { | |
| 443 return <int, String>{}; | |
| 444 } | |
| 445 '''); | |
| 446 | |
| 447 checkResult(''' | |
| 448 main() { | |
| 449 return <String, int>{"a": 0}; | |
| 450 } | |
| 451 '''); | |
| 452 | |
| 453 // TODO(johnniwinther): Update expectations when issue 21369 has be | |
| 454 // resolved. | |
| 455 checkResult(''' | |
| 456 main(a) { | |
| 457 return <String, int>{"a": 0, "b": 1, "c": a}; | |
| 458 } | |
| 459 ''', ''' | |
| 460 main(a) { | |
| 461 var v0 = "a", v1 = "b", v2 = "c"; | |
| 462 return <String, int>{v0: 0, v1: 1, v2: a}; | |
| 463 } | |
| 464 '''); | |
| 465 | |
| 466 checkResult(''' | |
| 467 main(a) { | |
| 468 return {0: "a", 1: {2: "b"}, a: {3: "c"}}; | |
| 469 } | |
| 470 ''', ''' | |
| 471 main(a) { | |
| 472 var v0 = 0, v1 = 1; | |
| 473 return {v0: "a", v1: {2: "b"}, a: {3: "c"}}; | |
| 474 } | |
| 475 '''); | |
| 476 }); | |
| 500 } | 477 } |
| 501 | 478 |
| 502 checkResult(String input, [String expectedOutput]) { | 479 checkResult(String input, [String expectedOutput]) { |
| 503 if (expectedOutput == null) { | 480 if (expectedOutput == null) { |
| 504 expectedOutput = input; | 481 expectedOutput = input; |
| 505 } | 482 } |
| 506 | 483 |
| 507 CollectingOutputProvider outputProvider = new CollectingOutputProvider(); | 484 CollectingOutputProvider outputProvider = new CollectingOutputProvider(); |
| 508 MemoryResourceProvider provider = new MemoryResourceProvider(); | 485 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 509 DartSdk sdk = new MockSdk(); | 486 DartSdk sdk = new MockSdk(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 534 sb.write(text); | 511 sb.write(text); |
| 535 } | 512 } |
| 536 | 513 |
| 537 void addError(errorEvent, [StackTrace stackTrace]) {} | 514 void addError(errorEvent, [StackTrace stackTrace]) {} |
| 538 | 515 |
| 539 void close() {} | 516 void close() {} |
| 540 | 517 |
| 541 String get text => sb.toString(); | 518 String get text => sb.toString(); |
| 542 } | 519 } |
| 543 | 520 |
| OLD | NEW |