Zum Inhalt

apple/PhysarumApp/Tests/AppStateBootPresetTests.swift

#if DEBUG
import XCTest
@testable import Physarum

/// The DEBUG-only capture hook that boots the app into a specific filled-slot preset
/// (PHYSARUM_BOOT_PRESET=<index>) for deterministic App Store media capture.
final class AppStateBootPresetTests: XCTestCase {
    func testValidIndexParses() {
        XCTAssertEqual(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "0"], filledCount: 7), 0)
        XCTAssertEqual(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "3"], filledCount: 7), 3)
        XCTAssertEqual(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "6"], filledCount: 7), 6)
    }

    func testOutOfRangeOrMalformedReturnsNil() {
        XCTAssertNil(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "7"], filledCount: 7), "index == count is out of range")
        XCTAssertNil(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "-1"], filledCount: 7))
        XCTAssertNil(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "x"], filledCount: 7))
        XCTAssertNil(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": ""], filledCount: 7))
        XCTAssertNil(AppState.bootPresetIndex(from: [:], filledCount: 7), "missing env → nil")
        XCTAssertNil(AppState.bootPresetIndex(from: ["PHYSARUM_BOOT_PRESET": "0"], filledCount: 0), "no filled slots → nil")
    }
}
#endif