Files
cutdex/packages/cutdex_native/tool/macos/file_drop_policy_test.swift
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

44 lines
1.9 KiB
Swift

import Cocoa
import FlutterMacOS
@main
struct FileDropPolicyTests {
static func main() throws {
let files = FileManager.default
let root = files.temporaryDirectory.appendingPathComponent(UUID().uuidString)
try files.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? files.removeItem(at: root) }
let file = root.appendingPathComponent("input.WAV")
try Data([0]).write(to: file)
let directory = root.appendingPathComponent("directory.wav")
try files.createDirectory(at: directory, withIntermediateDirectories: true)
let missing = root.appendingPathComponent("missing.wav")
let unrestricted = NativeFileDropPolicy(arguments: [
"allowedExtensions": NSNull(), "maximumFileCount": NSNull()
])!
let audio = NativeFileDropPolicy(arguments: [
"allowedExtensions": ["wav"], "maximumFileCount": 1
])!
var failures = 0
func check(_ condition: Bool, _ label: String) {
if !condition {
failures += 1
fputs("FAIL: \(label)\n", stderr)
}
}
check(audio.accepts([file]), "existing file with uppercase extension")
check(unrestricted.accepts([file]), "existing file without extension restrictions")
check(!audio.accepts([directory]), "directory with a permitted extension")
check(!unrestricted.accepts([directory]), "directory without extension restrictions")
check(!audio.accepts([missing]), "missing file with a permitted extension")
check(!unrestricted.accepts([missing]), "missing file without extension restrictions")
check(!audio.accepts([file, file]), "file count limit")
check(!audio.accepts([]), "empty input")
check(!unrestricted.accepts([URL(string: "https://example.com/input.wav")!]), "non-file URL")
try files.removeItem(at: file)
check(!audio.accepts([file]), "file deleted after entering the drop destination")
if failures > 0 { exit(1) }
print("Native file drop policy passed")
}
}