package net.ranides.assira.lexer;

import net.ranides.assira.text.StringUtils;
import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.*;

public class CharStreamerTest {

    @Test
    public void allocation() {
        StringBuilder target = new StringBuilder();
        CharStreamer<Object> stream = new CharStreamer<>((type, data) -> {
            target.append(type).append("<").append(new String(data)).append(">");
        });

        stream.put("hello ".toCharArray());
        stream.put("world!".toCharArray());
        stream.forward(8);
        stream.send("a");
        stream.put("somewhere".toCharArray());
        stream.forward(8);
        stream.send("b");
        stream.put("here".toCharArray());
        stream.forward(stream.available());
        stream.send("c");

        assertThrows(IllegalStateException.class, () -> {
            stream.forward(3);
        });

        assertEquals("a<hello wo>b<rld!some>c<wherehere>", target.toString());
    }
}