diff options
Diffstat (limited to 'test/junit/scala/reflect/internal/util/SourceFileTest.scala')
-rw-r--r-- | test/junit/scala/reflect/internal/util/SourceFileTest.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/junit/scala/reflect/internal/util/SourceFileTest.scala b/test/junit/scala/reflect/internal/util/SourceFileTest.scala index cad23eba14..2f2029ad2d 100644 --- a/test/junit/scala/reflect/internal/util/SourceFileTest.scala +++ b/test/junit/scala/reflect/internal/util/SourceFileTest.scala @@ -5,6 +5,8 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import scala.tools.testing.AssertUtil._ + @RunWith(classOf[JUnit4]) class SourceFileTest { def lineContentOf(code: String, offset: Int) = @@ -57,4 +59,21 @@ class SourceFileTest { assertEquals("def", lineContentOf("abc\r\ndef", 8)) assertEquals("def", lineContentOf("abc\r\ndef\r\n", 9)) } + + @Test def si9885_lineToOffset(): Unit = { + val text = "a\nb\nc\n" + val f = new BatchSourceFile("batch", text) + assertThrows[IndexOutOfBoundsException] { + f.lineToOffset(3) + } + assertEquals(4, f.lineToOffset(2)) + + val p = Position.offset(f, text.length - 1) + val q = Position.offset(f, f.lineToOffset(p.line - 1)) + assertEquals(p.line, q.line) + assertEquals(p.column, q.column + 1) + assertThrows[IndexOutOfBoundsException] { + Position.offset(f, f.lineToOffset(p.line)) + } + } } |