blob: a85ed745ad464b02bbedaa2655a658843aa9e3fb [file] [log] [blame]
// Copyright 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:file/memory.dart';
import 'package:test/test.dart';
import 'package:deps/useful_directory.dart';
main() {
test('resolve', () {
final fs = MemoryFileSystem.test();
final dir = fs.directory('/path');
expect(dir.resolve('some/other').path, '/path/some/other');
});
test('resolveFile', () {
final fs = MemoryFileSystem.test();
final dir = fs.directory('/path');
expect(dir.resolveFile('some/other').path, '/path/some/other');
});
test('move', () async {
final fs = MemoryFileSystem.test();
final dir = await fs.directory('/path').create();
await fs.directory('/path/from').create();
await dir.move('from', 'in/to');
expect(
dir.listSync(recursive: true).map((f) => f.path),
unorderedEquals([
'/path/in',
'/path/in/to',
]));
});
test('move up', () async {
final fs = MemoryFileSystem.test();
final dir = await fs.directory('/path').create();
await fs.directory('/path/from').create();
await dir.move('from', '../to');
expect(
fs.directory('/').listSync(recursive: true).map((f) => f.path),
unorderedEquals([
'path',
'to',
]));
});
test('move on existing directory fails', () async {
final fs = MemoryFileSystem.test();
final dir = await fs.directory('/path').create();
await fs.directory('/path/from').create();
expectLater(dir.move('from', '../path'), throwsException);
expect(
fs.directory('/').listSync(recursive: true).map((f) => f.path),
unorderedEquals([
'path',
'path/from',
]));
});
}