diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-01-29 08:21:02 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-01-29 08:21:02 -0800 |
commit | f0809f41149174634abc1034e4b17e944c491dcc (patch) | |
tree | acfd9a1134cf1e810ed4ef8200845c380f3b0da0 /test | |
parent | 3255f841cd100c2e7fcbec8253649b55a7014396 (diff) | |
parent | 0eefa77be199b1d8186a7a6978f8e01132f35cd9 (diff) | |
download | scala-f0809f41149174634abc1034e4b17e944c491dcc.tar.gz scala-f0809f41149174634abc1034e4b17e944c491dcc.tar.bz2 scala-f0809f41149174634abc1034e4b17e944c491dcc.zip |
Merge pull request #3427 from retronym/ticket/8205
Avoid long, slow march to AIIOBE in SourceFile#lineContent
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/reflect/internal/util/SourceFileTest.scala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/junit/scala/reflect/internal/util/SourceFileTest.scala b/test/junit/scala/reflect/internal/util/SourceFileTest.scala new file mode 100644 index 0000000000..bbd5685ef7 --- /dev/null +++ b/test/junit/scala/reflect/internal/util/SourceFileTest.scala @@ -0,0 +1,33 @@ +package scala.reflect.internal.util + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class SourceFileTest { + def lineContentOf(code: String, offset: Int) = + Position.offset(new BatchSourceFile("", code), offset).lineContent + + @Test + def si8205_overflow(): Unit = { + val file = new BatchSourceFile("", "code no newline") + // the bug in lineToString counted until MaxValue, and the AIOOBE came from here + assertFalse(file.isEndOfLine(Int.MaxValue)) + } + + @Test + def si8205_lineToString(): Unit = { + assertEquals("", lineContentOf("", 0)) + assertEquals("abc", lineContentOf("abc", 0)) + assertEquals("abc", lineContentOf("abc", 3)) + assertEquals("code no newline", lineContentOf("code no newline", 1)) + assertEquals("", lineContentOf("\n", 0)) + assertEquals("abc", lineContentOf("abc\ndef", 0)) + assertEquals("abc", lineContentOf("abc\ndef", 3)) + assertEquals("def", lineContentOf("abc\ndef", 4)) + assertEquals("def", lineContentOf("abc\ndef", 6)) + assertEquals("def", lineContentOf("abc\ndef\n", 7)) + } +} |