import AppKit
import Carbon.HIToolbox
import XCTest
import SwiftTerm
@testable import CommandNotch

final class TerminalCommandArrowBehaviorTests: XCTestCase {
    func testCommandLeftUsesHomeSequence() {
        let sequence = TerminalCommandArrowBehavior.sequence(
            for: [.command],
            keyCode: UInt16(kVK_LeftArrow),
            applicationCursor: false
        )

        XCTAssertEqual(sequence, EscapeSequences.moveHomeNormal)
    }

    func testCommandRightUsesApplicationEndSequence() {
        let sequence = TerminalCommandArrowBehavior.sequence(
            for: [.command],
            keyCode: UInt16(kVK_RightArrow),
            applicationCursor: true
        )

        XCTAssertEqual(sequence, EscapeSequences.moveEndApp)
    }

    func testOptionLeftKeepsSwiftTermWordNavigationPath() {
        let sequence = TerminalCommandArrowBehavior.sequence(
            for: [.option],
            keyCode: UInt16(kVK_LeftArrow),
            applicationCursor: false
        )

        XCTAssertNil(sequence)
    }

    func testCommandDeleteUsesLineKillSequence() {
        let sequence = TerminalCommandArrowBehavior.sequence(
            for: [.command],
            keyCode: UInt16(kVK_Delete),
            applicationCursor: false
        )

        XCTAssertEqual(sequence, [0x15])
    }

    func testCommandLUsesClearScreenSequence() {
        let sequence = TerminalCommandArrowBehavior.sequence(
            for: [.command],
            keyCode: UInt16(kVK_ANSI_L),
            applicationCursor: false
        )

        XCTAssertEqual(sequence, [0x0c])
    }
}
