mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 15:31:32 +00:00
091f8860c2
Change-Id: I67801c1c544e0ee197386dd3aad82cc7507a98a1 Reviewed-on: https://dart-review.googlesource.com/61963 Reviewed-by: Zach Anderson <zra@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
100 lines
3 KiB
Dart
100 lines
3 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 asyncFile;
|
||
var syncFile;
|
||
|
||
test('Non-UTF8 Filename', () async {
|
||
Directory tmp;
|
||
try {
|
||
tmp = await Directory.systemTemp.createTemp('non_utf8_file_test_async');
|
||
final rawPath = new Uint8List.fromList([182]);
|
||
asyncFile = new File.fromRawPath(rawPath);
|
||
if (Platform.isMacOS || Platform.isIOS) {
|
||
try {
|
||
await asyncFile.create();
|
||
} on FileSystemException catch (e) {
|
||
// Macos doesn't support non-UTF-8 paths.
|
||
await tmp.delete(recursive: true);
|
||
return;
|
||
}
|
||
} else {
|
||
await asyncFile.create();
|
||
}
|
||
expect(await asyncFile.exists(), isTrue);
|
||
|
||
for (final file in tmp.listSync()) {
|
||
// FIXME(bkonyi): reenable when rawPath is exposed.
|
||
/*
|
||
if (Platform.isWindows) {
|
||
// Windows replaces invalid characters with <20> when creating file system
|
||
// entities.
|
||
final raw = file.rawPath;
|
||
expect(raw.sublist(raw.length - 3), [239, 191, 189]);
|
||
} else {
|
||
expect(file.rawPath.last, 182);
|
||
}
|
||
*/
|
||
// FIXME(bkonyi): this isn't true on some versions of MacOS. Why?
|
||
if (!Platform.isMacOS && !Platform.isIOS) {
|
||
expect(file.path.endsWith('<EFBFBD>'), isTrue);
|
||
}
|
||
}
|
||
await asyncFile.delete();
|
||
} finally {
|
||
await tmp.delete(recursive: true);
|
||
}
|
||
});
|
||
|
||
test('Non-UTF8 Filename Sync', () {
|
||
Directory tmp;
|
||
try {
|
||
tmp = Directory.systemTemp.createTempSync('non_utf8_file_test_sync');
|
||
final rawPath = new Uint8List.fromList([182]);
|
||
syncFile = new File.fromRawPath(rawPath);
|
||
|
||
if (Platform.isMacOS || Platform.isIOS) {
|
||
try {
|
||
syncFile.createSync();
|
||
} on FileSystemException catch (e) {
|
||
// Macos doesn't support non-UTF-8 paths.
|
||
tmp.deleteSync(recursive: true);
|
||
return;
|
||
}
|
||
} else {
|
||
syncFile.createSync();
|
||
}
|
||
expect(syncFile.existsSync(), isTrue);
|
||
|
||
for (final file in tmp.listSync()) {
|
||
// FIXME(bkonyi): reenable when rawPath is exposed.
|
||
/*
|
||
if (Platform.isWindows) {
|
||
// Windows replaces invalid characters with <20> when creating file system
|
||
// entities.
|
||
final raw = file.rawPath;
|
||
expect(raw.sublist(raw.length - 3), [239, 191, 189]);
|
||
} else {
|
||
expect(file.rawPath.last, 182);
|
||
}
|
||
*/
|
||
// FIXME(bkonyi): this isn't true on some versions of MacOS. Why?
|
||
if (!Platform.isMacOS && !Platform.isIOS) {
|
||
expect(file.path.endsWith('<EFBFBD>'), isTrue);
|
||
}
|
||
}
|
||
syncFile.deleteSync();
|
||
} finally {
|
||
tmp.deleteSync(recursive: true);
|
||
}
|
||
});
|
||
}
|