public void testEmptyBuffer() throws Exception { SourceBuffer buffer = getSourceBuffer(""); assertNull(buffer.getSnippet(new LineColumn(1, 1), new LineColumn(1, 1))); }
public void testSimpleUsage() throws Exception { SourceBuffer buffer = getSourceBuffer("println 'hello world'"); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); }
public void testUnixLineUsage() throws Exception { String endOfLine = "\n"; StringBuffer src = new StringBuffer(); src.append("println 'hello world'").append(endOfLine); src.append("println 'oh not, not that again'").append(endOfLine); SourceBuffer buffer = getSourceBuffer(src.toString()); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); assertEquals("world'" + endOfLine + "print", buffer.getSnippet(new LineColumn(1, 16), new LineColumn(2, 6))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(1, 22), new LineColumn(1, 23))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(2, 33), new LineColumn(2, 34))); }
public void testOutOfBounds() throws Exception { String endOfLine = "\n"; StringBuffer src = new StringBuffer(); src.append("println 'hello world'").append(endOfLine); src.append("println 'oh not, not that again'").append(endOfLine); SourceBuffer buffer = getSourceBuffer(src.toString()); assertEquals("println", buffer.getSnippet(new LineColumn(0, 0), new LineColumn(1, 8))); assertEquals("println", buffer.getSnippet(new LineColumn(-10, -1), new LineColumn(1, 8))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(2, 33), new LineColumn(2, 40))); assertEquals("", buffer.getSnippet(new LineColumn(3, 33), new LineColumn(6, 40))); }
public void testDOSLineUsage() throws Exception { String endOfLine = "\r\n"; StringBuffer src = new StringBuffer(); src.append("println 'hello world'").append(endOfLine); src.append("println 'oh not, not that again'").append(endOfLine); SourceBuffer buffer = getSourceBuffer(src.toString()); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); assertEquals("oh not", buffer.getSnippet(new LineColumn(2, 10), new LineColumn(2, 16))); assertEquals("world'" + endOfLine + "print", buffer.getSnippet(new LineColumn(1, 16), new LineColumn(2, 6))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(1, 22), new LineColumn(1, 24))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(2, 33), new LineColumn(2, 35))); }