Skip to content

Commit 5720e97

Browse files
committed
Merge pull request scala#3430 from som-snytt/issue/8205-backport
SI-8205 [nomaster] backport test pos.lineContent
2 parents 50453ce + 8ee165c commit 5720e97

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package scala.reflect.internal.util
2+
3+
import org.junit.Assert._
4+
import org.junit.Test
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.JUnit4
7+
8+
@RunWith(classOf[JUnit4])
9+
class SourceFileTest {
10+
def lineContentOf(code: String, offset: Int) =
11+
new OffsetPosition(new BatchSourceFile("", code), offset).lineContent
12+
//Position.offset(new BatchSourceFile("", code), offset).lineContent
13+
14+
/*
15+
@Test
16+
def si8205_overflow(): Unit = {
17+
val file = new BatchSourceFile("", "code no newline")
18+
// the bug in lineToString counted until MaxValue, and the AIOOBE came from here
19+
assertFalse(file.isEndOfLine(Int.MaxValue))
20+
}
21+
*/
22+
23+
@Test
24+
def si8205_lineToString(): Unit = {
25+
assertEquals("", lineContentOf("", 0))
26+
assertEquals("abc", lineContentOf("abc", 0))
27+
assertEquals("abc", lineContentOf("abc", 3))
28+
assertEquals("code no newline", lineContentOf("code no newline", 1))
29+
assertEquals("", lineContentOf("\n", 0))
30+
assertEquals("abc", lineContentOf("abc\ndef", 0))
31+
assertEquals("abc", lineContentOf("abc\ndef", 3))
32+
assertEquals("def", lineContentOf("abc\ndef", 4))
33+
assertEquals("def", lineContentOf("abc\ndef", 6))
34+
assertEquals("def", lineContentOf("abc\ndef\n", 7))
35+
}
36+
37+
@Test
38+
def CRisEOL(): Unit = {
39+
assertEquals("", lineContentOf("\r", 0))
40+
assertEquals("abc", lineContentOf("abc\rdef", 0))
41+
assertEquals("abc", lineContentOf("abc\rdef", 3))
42+
assertEquals("def", lineContentOf("abc\rdef", 4))
43+
assertEquals("def", lineContentOf("abc\rdef", 6))
44+
assertEquals("def", lineContentOf("abc\rdef\r", 7))
45+
}
46+
47+
@Test
48+
def CRNLisEOL(): Unit = {
49+
assertEquals("", lineContentOf("\r\n", 0))
50+
assertEquals("abc", lineContentOf("abc\r\ndef", 0))
51+
assertEquals("abc", lineContentOf("abc\r\ndef", 3))
52+
assertEquals("abc", lineContentOf("abc\r\ndef", 4))
53+
assertEquals("def", lineContentOf("abc\r\ndef", 5))
54+
assertEquals("def", lineContentOf("abc\r\ndef", 7))
55+
assertEquals("def", lineContentOf("abc\r\ndef", 8))
56+
assertEquals("def", lineContentOf("abc\r\ndef\r\n", 9))
57+
}
58+
}

0 commit comments

Comments
 (0)