OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library test.index.store.separate_file_mananer; | |
6 | |
7 import 'dart:io'; | |
8 | |
9 import 'package:analysis_server/src/index/store/separate_file_manager.dart'; | |
10 import 'package:path/path.dart'; | |
11 import 'package:unittest/unittest.dart'; | |
12 | |
13 import '../../reflective_tests.dart'; | |
14 | |
15 | |
16 main() { | |
17 groupSep = ' | '; | |
18 group('SeparateFileManager', () { | |
19 runReflectiveTests(_SeparateFileManagerTest); | |
20 }); | |
21 } | |
22 | |
23 | |
24 @ReflectiveTestCase() | |
25 class _SeparateFileManagerTest { | |
26 SeparateFileManager fileManager; | |
27 Directory tempDir; | |
28 | |
29 void setUp() { | |
30 tempDir = Directory.systemTemp.createTempSync('AnalysisServer_index'); | |
31 fileManager = new SeparateFileManager(tempDir); | |
32 } | |
33 | |
34 void tearDown() { | |
35 tempDir.delete(recursive: true); | |
36 } | |
37 | |
38 test_clear() { | |
39 String name = "42.index"; | |
40 // create the file | |
41 return fileManager.write(name, <int>[1, 2, 3, 4]).then((_) { | |
42 // check that the file exists | |
43 expect(_existsSync(name), isTrue); | |
44 // clear | |
45 fileManager.clear(); | |
46 expect(_existsSync(name), isFalse); | |
47 }); | |
48 } | |
49 | |
50 test_delete_doesNotExist() { | |
51 String name = "42.index"; | |
52 fileManager.delete(name); | |
53 } | |
54 | |
55 test_outputInput() { | |
56 String name = "42.index"; | |
57 // create the file | |
58 return fileManager.write(name, <int>[1, 2, 3, 4]).then((_) { | |
59 // check that that the file exists | |
60 expect(_existsSync(name), isTrue); | |
61 // read the file | |
62 return fileManager.read(name).then((bytes) { | |
63 expect(bytes, <int>[1, 2, 3, 4]); | |
64 // delete | |
65 fileManager.delete(name); | |
66 // the file does not exist anymore | |
67 return fileManager.read(name).then((bytes) { | |
68 expect(bytes, isNull); | |
69 }); | |
70 }); | |
71 }); | |
72 } | |
73 | |
74 bool _existsSync(String name) { | |
75 return new File(join(tempDir.path, name)).existsSync(); | |
76 } | |
77 } | |
OLD | NEW |