package thb.jeanluc.adventure.io;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class ChooseDefaultTest {

    @Test
    void returnsZeroBasedIndexOfValidChoice() {
        TestIO io = new TestIO().enqueue("2");
        int i = io.choose("Menu", List.of("A", "B", "C"));
        assertThat(i).isEqualTo(1);
    }

    @Test
    void rePromptsOnInvalidThenAccepts() {
        TestIO io = new TestIO().enqueue("9").enqueue("x").enqueue("1");
        int i = io.choose("Menu", List.of("A", "B"));
        assertThat(i).isZero();
        assertThat(io.allOutput()).contains("between 1 and 2");
    }

    @Test
    void eofReturnsLastOption() {
        TestIO io = new TestIO(); // empty queue → readLine() returns null
        int i = io.choose("Menu", List.of("Play", "Quit"));
        assertThat(i).isEqualTo(1);
    }
}
