Files
sdk/tests/standalone/io/non_utf8_directory_test.dart
T
Jonas Termansen 3433d8cfc3 [nnbd] Migrate standalone/io to NNBD.
The tests are also now dartfmt.

Bug: https://github.com/dart-lang/sdk/issues/40040
Change-Id: I8dece8097b37b70d47a5374dae2f3fadb0fc4b90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134338
Commit-Queue: Jonas Termansen <sortie@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2020-02-07 14:41:36 +00:00

92 lines
2.7 KiB
Dart

// Copyright (c) 2018, 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 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:test/test.dart';
Future main() async {
var asyncDir;
var syncDir;
test('Non-UTF8 Directory Listing', () async {
final tmp =
await Directory.systemTemp.createTemp('non_utf8_directory_test_async');
try {
final rawPath = new Uint8List.fromList([182]);
asyncDir = new Directory.fromRawPath(rawPath);
if (Platform.isMacOS || Platform.isIOS) {
try {
await asyncDir.create();
} on FileSystemException catch (e) {
// Macos doesn't support non-UTF-8 paths.
await tmp.delete(recursive: true);
return;
}
} else {
await asyncDir.create();
}
expect(await asyncDir.exists(), isTrue);
await for (final e in tmp.list()) {
// FIXME(bkonyi): reenable when rawPath is exposed.
/*
if (Platform.isWindows) {
// Windows replaces invalid characters with when creating file system
// entities.
final raw = e.rawPath;
expect(raw.sublist(raw.length - 3), [239, 191, 189]);
} else {
expect(e.rawPath.last, 182);
}
*/
}
await asyncDir.delete(recursive: true);
} finally {
await tmp.delete(recursive: true);
}
});
test('Non-UTF8 Directory Sync Listing', () {
final tmp =
Directory.systemTemp.createTempSync('non_utf8_directory_test_sync');
try {
final rawPath = new Uint8List.fromList([182]);
syncDir = new Directory.fromRawPath(rawPath);
if (Platform.isMacOS || Platform.isIOS) {
try {
syncDir.createSync();
} on FileSystemException catch (e) {
// Macos doesn't support non-UTF-8 paths.
tmp.deleteSync(recursive: true);
return;
}
} else {
syncDir.createSync();
}
expect(syncDir.existsSync(), isTrue);
for (final e in tmp.listSync()) {
// FIXME(bkonyi): reenable when rawPath is exposed.
/*
if (Platform.isWindows) {
// Windows replaces invalid characters with when creating file system
// entities.
final raw = e.rawPath;
expect(raw.sublist(raw.length - 3), [239, 191, 189]);
} else {
expect(e.rawPath.last, 182);
}
*/
}
syncDir.deleteSync(recursive: true);
} finally {
tmp.deleteSync(recursive: true);
}
});
}