package net.ranides.assira.lexer;

import org.junit.Test;

import static org.junit.Assert.*;

public class ByteStreamerTest {

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

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

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

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

}