package thb.jeanluc.adventure.io.text;

import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class StyledTextTest {

    @Test
    void builder_collectsSpansInOrder() {
        StyledText t = StyledText.builder()
                .plain("You take ").item("the brass lamp").plain(".").build();
        assertThat(t.spans()).hasSize(3);
        assertThat(t.spans().get(1).style()).isEqualTo(Style.ITEM);
        assertThat(t.spans().get(1).text()).isEqualTo("the brass lamp");
    }

    @Test
    void plainText_concatenatesAllSpanText() {
        StyledText t = StyledText.builder()
                .plain("You take ").item("the brass lamp").plain(".").build();
        assertThat(t.plainText()).isEqualTo("You take the brass lamp.");
    }

    @Test
    void of_createsSinglePlainSpan() {
        StyledText t = StyledText.of("hello");
        assertThat(t.spans()).hasSize(1);
        assertThat(t.spans().getFirst().style()).isEqualTo(Style.PLAIN);
        assertThat(t.plainText()).isEqualTo("hello");
    }

    @Test
    void span_rejectsNulls() {
        assertThatThrownBy(() -> new Span(null, Style.PLAIN))
                .isInstanceOf(IllegalArgumentException.class);
    }
}
