| 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 test.src.task.driver_test; | 5 library test.src.task.driver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisContext, CacheState, RetentionPriority; | 10 show AnalysisContext, CacheState, RetentionPriority; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 expect(entry.getState(result), CacheState.INVALID); | 201 expect(entry.getState(result), CacheState.INVALID); |
| 202 } | 202 } |
| 203 | 203 |
| 204 test_getValue() { | 204 test_getValue() { |
| 205 String defaultValue = 'value'; | 205 String defaultValue = 'value'; |
| 206 ResultDescriptor result = new ResultDescriptor('test', defaultValue); | 206 ResultDescriptor result = new ResultDescriptor('test', defaultValue); |
| 207 CacheEntry entry = new CacheEntry(); | 207 CacheEntry entry = new CacheEntry(); |
| 208 expect(entry.getValue(result), defaultValue); | 208 expect(entry.getValue(result), defaultValue); |
| 209 } | 209 } |
| 210 | 210 |
| 211 test_getMemento_noResult() { |
| 212 String defaultValue = 'value'; |
| 213 ResultDescriptor result = new ResultDescriptor('test', defaultValue); |
| 214 CacheEntry entry = new CacheEntry(); |
| 215 expect(entry.getMemento(result), null); |
| 216 } |
| 217 |
| 211 test_hasAstStructure_false() { | 218 test_hasAstStructure_false() { |
| 212 CacheEntry entry = new CacheEntry(); | 219 CacheEntry entry = new CacheEntry(); |
| 213 expect(entry.hasAstStructure, false); | 220 expect(entry.hasAstStructure, false); |
| 214 } | 221 } |
| 215 | 222 |
| 216 test_hasAstStructure_true() { | 223 test_hasAstStructure_true() { |
| 217 ResultDescriptor result = new ResultDescriptor('test', null); | 224 ResultDescriptor result = new ResultDescriptor('test', null); |
| 218 CacheEntry entry = new CacheEntry(); | 225 CacheEntry entry = new CacheEntry(); |
| 219 entry.setValue(result, new NullLiteral(null), TargetedResult.EMPTY_LIST); | 226 entry.setValue(result, new NullLiteral(null), TargetedResult.EMPTY_LIST); |
| 220 expect(entry.hasAstStructure, true); | 227 expect(entry.hasAstStructure, true); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // set IN_PROCESS | 367 // set IN_PROCESS |
| 361 entry.setState(result, CacheState.IN_PROCESS); | 368 entry.setState(result, CacheState.IN_PROCESS); |
| 362 expect(entry.getState(result), CacheState.IN_PROCESS); | 369 expect(entry.getState(result), CacheState.IN_PROCESS); |
| 363 expect(entry.getValue(result), 10); | 370 expect(entry.getValue(result), 10); |
| 364 } | 371 } |
| 365 | 372 |
| 366 test_setState_invalid() { | 373 test_setState_invalid() { |
| 367 ResultDescriptor result = new ResultDescriptor('test', 1); | 374 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 368 CacheEntry entry = new CacheEntry(); | 375 CacheEntry entry = new CacheEntry(); |
| 369 // set VALID | 376 // set VALID |
| 370 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 377 String memento = 'main() {}'; |
| 378 entry.setValue(result, 10, TargetedResult.EMPTY_LIST, memento); |
| 371 expect(entry.getState(result), CacheState.VALID); | 379 expect(entry.getState(result), CacheState.VALID); |
| 372 expect(entry.getValue(result), 10); | 380 expect(entry.getValue(result), 10); |
| 373 // set INVALID | 381 // set INVALID |
| 374 entry.setState(result, CacheState.INVALID); | 382 entry.setState(result, CacheState.INVALID); |
| 375 expect(entry.getState(result), CacheState.INVALID); | 383 expect(entry.getState(result), CacheState.INVALID); |
| 376 expect(entry.getValue(result), 1); | 384 expect(entry.getValue(result), 1); |
| 385 expect(entry.getMemento(result), memento); |
| 377 } | 386 } |
| 378 | 387 |
| 379 test_setState_invalid_invalidateDependent() { | 388 test_setState_invalid_invalidateDependent() { |
| 380 AnalysisCache cache = createCache(); | 389 AnalysisCache cache = createCache(); |
| 381 AnalysisTarget target = new TestSource(); | 390 AnalysisTarget target = new TestSource(); |
| 382 CacheEntry entry = new CacheEntry(); | 391 CacheEntry entry = new CacheEntry(); |
| 383 cache.put(target, entry); | 392 cache.put(target, entry); |
| 384 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 393 ResultDescriptor result1 = new ResultDescriptor('result1', -1); |
| 385 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 394 ResultDescriptor result2 = new ResultDescriptor('result2', -2); |
| 386 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 395 ResultDescriptor result3 = new ResultDescriptor('result3', -3); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 410 expect(entry.getValue(result4), 444); | 419 expect(entry.getValue(result4), 444); |
| 411 } | 420 } |
| 412 | 421 |
| 413 test_setState_valid() { | 422 test_setState_valid() { |
| 414 ResultDescriptor result = new ResultDescriptor('test', null); | 423 ResultDescriptor result = new ResultDescriptor('test', null); |
| 415 CacheEntry entry = new CacheEntry(); | 424 CacheEntry entry = new CacheEntry(); |
| 416 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); | 425 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); |
| 417 } | 426 } |
| 418 | 427 |
| 419 test_setValue() { | 428 test_setValue() { |
| 429 ResultDescriptor result = new ResultDescriptor('test', null); |
| 420 String value = 'value'; | 430 String value = 'value'; |
| 421 ResultDescriptor result = new ResultDescriptor('test', null); | 431 String memento = 'main() {}'; |
| 422 CacheEntry entry = new CacheEntry(); | 432 CacheEntry entry = new CacheEntry(); |
| 423 entry.setValue(result, value, TargetedResult.EMPTY_LIST); | 433 entry.setValue(result, value, TargetedResult.EMPTY_LIST, memento); |
| 424 expect(entry.getState(result), CacheState.VALID); | 434 expect(entry.getState(result), CacheState.VALID); |
| 425 expect(entry.getValue(result), value); | 435 expect(entry.getValue(result), value); |
| 436 expect(entry.getMemento(result), memento); |
| 426 } | 437 } |
| 427 | 438 |
| 428 test_setValue_invalidateDependent() { | 439 test_setValue_invalidateDependent() { |
| 429 AnalysisCache cache = createCache(); | 440 AnalysisCache cache = createCache(); |
| 430 AnalysisTarget target = new TestSource(); | 441 AnalysisTarget target = new TestSource(); |
| 431 CacheEntry entry = new CacheEntry(); | 442 CacheEntry entry = new CacheEntry(); |
| 432 cache.put(target, entry); | 443 cache.put(target, entry); |
| 433 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 444 ResultDescriptor result1 = new ResultDescriptor('result1', -1); |
| 434 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 445 ResultDescriptor result2 = new ResultDescriptor('result2', -2); |
| 435 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 446 ResultDescriptor result3 = new ResultDescriptor('result3', -3); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 return new UniversalCachePartition(null, 8, policy); | 650 return new UniversalCachePartition(null, 8, policy); |
| 640 } | 651 } |
| 641 | 652 |
| 642 void test_contains() { | 653 void test_contains() { |
| 643 UniversalCachePartition partition = | 654 UniversalCachePartition partition = |
| 644 new UniversalCachePartition(null, 8, null); | 655 new UniversalCachePartition(null, 8, null); |
| 645 TestSource source = new TestSource(); | 656 TestSource source = new TestSource(); |
| 646 expect(partition.contains(source), isTrue); | 657 expect(partition.contains(source), isTrue); |
| 647 } | 658 } |
| 648 } | 659 } |
| OLD | NEW |