|
|
@@ -0,0 +1,45 @@
|
|
|
+package net.ranides.assira.lexer;
|
|
|
+
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import static org.junit.Assert.*;
|
|
|
+
|
|
|
+public class SimpleStreamerTest {
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void usage() {
|
|
|
+ SimpleStreamer streamer = new SimpleStreamer("hello world text ");
|
|
|
+
|
|
|
+ assertEquals("hello", streamer.next(c -> c!=' '));
|
|
|
+ assertEquals(" ", streamer.next(c -> c==' '));
|
|
|
+ assertEquals("", streamer.next(c -> c==' '));
|
|
|
+ assertEquals("world", streamer.next(c -> c!=' '));
|
|
|
+ assertEquals(" ", streamer.next(c -> c==' '));
|
|
|
+
|
|
|
+ assertEquals('t', streamer.peek());
|
|
|
+ assertEquals("text", streamer.peek(c -> c!=' '));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void peek() {
|
|
|
+ SimpleStreamer streamer = new SimpleStreamer("hello world!");
|
|
|
+
|
|
|
+ assertEquals("hello", streamer.peek(c -> c!=' '));
|
|
|
+ assertEquals("hello world", streamer.peek(c -> c!='!'));
|
|
|
+ assertEquals("hello world!", streamer.peek(c -> c!='?'));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void next() {
|
|
|
+ SimpleStreamer streamer1 = new SimpleStreamer("hello world!");
|
|
|
+ SimpleStreamer streamer2 = new SimpleStreamer("hello world!");
|
|
|
+ SimpleStreamer streamer3 = new SimpleStreamer("hello world!");
|
|
|
+
|
|
|
+ assertEquals("hello", streamer1.next(c -> c!=' '));
|
|
|
+ assertEquals("hello world", streamer2.next(c -> c!='!'));
|
|
|
+ assertEquals("hello world!", streamer3.next(c -> c!='?'));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|