IndentDedentInputBuffer implements InputBuffer { public String extract(int start, int end) { return origBuffer.extract(map(start), map(end)); } IndentDedentInputBuffer(char[] input, int tabStop, String lineCommentStart, boolean strict);  IndentDedentInputBuffer(char[] input, int tabStop, String lineCommentStart, boolean strict,
                                   boolean skipEmptyLines); char charAt(int index); boolean test(int index, char[] characters); String extract(int start, int end); String extract(IndexRange range); Position getPosition(int index); int getOriginalIndex(int index); String extractLine(int lineNumber); int getLineCount();  }
@Test public void testEmptyIndentDedentInputBuffer() { InputBuffer buf = new IndentDedentInputBuffer(new char[0], 2, "#", false); assertEquals(buf.extract(0, 1), ""); }
@Test public void testIndentDedentInputBuffer1() { InputBuffer buf = new IndentDedentInputBuffer(("" + "level 1\n" + " \tlevel 2\n" + " still level 2\n" + "\t level 3\n" + " also 3\n" + " 2 again\n" + " another 3\n" + "and back to 1\n" + " another level 2 again").toCharArray(), 2, null, false); String bufContent = collectContent(buf); assertEquals(bufContent, "" + "level 1\n" + "»level 2\n" + "still level 2\n" + "»level 3\n" + "also 3\n" + "«2 again\n" + "»another 3\n" + "««and back to 1\n" + "»another level 2 again\n" + "«"); String text = "another 3"; int start = bufContent.indexOf(text); assertEquals(buf.extract(start, start + text.length()), text); text = "back to 1"; start = bufContent.indexOf(text); assertEquals(buf.extract(start, start + text.length()), text); }
@Test public void testIndentDedentInputBuffer2() { String input = FileUtils.readAllTextFromResource("IndentDedentBuffer2.test"); InputBuffer buf = new IndentDedentInputBuffer(input.toCharArray(), 4, "#", false); String bufContent = collectContent(buf); assertEquals(bufContent, FileUtils.readAllTextFromResource("IndentDedentBuffer2.converted.test")); String text = "go deep"; int start = bufContent.indexOf(text); assertEquals(buf.extract(start, start + text.length()), text); }
@Test public void testIndentDedentInputBuffer3() { String input = FileUtils.readAllTextFromResource("IndentDedentBuffer3.test"); InputBuffer buf = new IndentDedentInputBuffer(input.toCharArray(), 4, " String bufContent = collectContent(buf); assertEquals(bufContent, FileUtils.readAllTextFromResource("IndentDedentBuffer3.converted.test")); assertEquals(buf.extract(0, bufContent.length()), input); }