mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 20:51:19 +00:00
3433d8cfc3
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>
99 lines
3 KiB
Dart
99 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 {
|
||
final tmp =
|
||
await Directory.systemTemp.createTemp('non_utf8_file_test_async');
|
||
try {
|
||
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', () {
|
||
final tmp = Directory.systemTemp.createTempSync('non_utf8_file_test_sync');
|
||
try {
|
||
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);
|
||
}
|
||
});
|
||
}
|