Skip to content

Commit 0ba6d2e

Browse files
authored
Merge pull request #3766 from dotty-staging/ide-tests
Add IDE tests
2 parents f7d5fe4 + ef978a7 commit 0ba6d2e

36 files changed

+1150
-7
lines changed

.drone.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ pipeline:
4343
- cp -R . /tmp/3/ && cd /tmp/3/
4444
- ./project/scripts/sbt dotty-optimised/test
4545

46-
test_sbt:
46+
test_ide:
4747
group: test
4848
image: lampepfl/dotty:2018-04-10
4949
commands:
5050
- cp -R . /tmp/4/ && cd /tmp/4/
51+
- ./project/scripts/sbt dotty-language-server/test
52+
53+
test_sbt:
54+
group: test
55+
image: lampepfl/dotty:2017-11-17
56+
commands:
57+
- cp -R . /tmp/5/ && cd /tmp/5/
5158
- ./project/scripts/sbt sbt-dotty/scripted
5259
when:
5360
# sbt scripted tests are slow and only run on nightly or deployment

compiler/src/dotty/tools/dotc/util/DiffUtil.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ object DiffUtil {
5959
(fnd, exp, totalChange.toDouble / (expected.length + found.length))
6060
}
6161

62+
/**
63+
* Return a colored diff between the tokens of every line in `expected` and `actual`. Each line of
64+
* output contains the expected value on the left and the actual value on the right.
65+
*
66+
* @param expected The expected lines
67+
* @param actual The actual lines
68+
* @return A string with one element of `expected` and `actual` on each lines, where
69+
* differences are highlighted.
70+
*/
71+
def mkColoredLineDiff(expected: Seq[String], actual: Seq[String]): String = {
72+
val expectedSize = EOF.length max expected.maxBy(_.length).length
73+
actual.padTo(expected.length, "").zip(expected.padTo(actual.length, "")).map { case (act, exp) =>
74+
mkColoredLineDiff(exp, act, expectedSize)
75+
}.mkString(System.lineSeparator)
76+
}
77+
6278
def mkColoredLineDiff(expected: String, actual: String, expectedSize: Int): String = {
6379
lazy val diff = {
6480
val tokens = splitTokens(expected, Nil).toArray

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
612612

613613
if (outputLines.length != checkLines.length || !linesMatch) {
614614
// Print diff to files and summary:
615-
val expectedSize = DiffUtil.EOF.length max checkLines.map(_.length).max
616-
val diff = outputLines.padTo(checkLines.length, "").zip(checkLines.padTo(outputLines.length, "")).map { case (act, exp) =>
617-
DiffUtil.mkColoredLineDiff(exp, act, expectedSize)
618-
}.mkString("\n")
615+
val diff = DiffUtil.mkColoredLineDiff(checkLines, outputLines)
619616

620617
val msg =
621618
s"""|Output from '$sourceTitle' did not match check file.

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ class DottyLanguageServer extends LanguageServer
303303
val newName = params.getNewName
304304

305305
val refs = Interactive.namedTrees(trees, includeReferences = true, tree =>
306-
(Interactive.matchSymbol(tree, sym, Include.overriding)
307-
|| (linkedSym != NoSymbol && Interactive.matchSymbol(tree, linkedSym, Include.overriding))))
306+
tree.pos.isSourceDerived
307+
&& (Interactive.matchSymbol(tree, sym, Include.overriding)
308+
|| (linkedSym != NoSymbol && Interactive.matchSymbol(tree, linkedSym, Include.overriding))))
308309

309310
val changes = refs.groupBy(ref => toUri(ref.source).toString).mapValues(_.map(ref => new TextEdit(range(ref.namePos), newName)).asJava)
310311

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
import org.eclipse.lsp4j.CompletionItemKind
5+
6+
import dotty.tools.languageserver.util.Code._
7+
8+
class CompletionTest {
9+
10+
@Test def completion0: Unit = {
11+
code"class Foo { val xyz: Int = 0; def y: Int = xy$m1 }".withSource
12+
.completion(m1, Set(("xyz", CompletionItemKind.Field, "Int")))
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class DefinitionTest {
8+
9+
@Test def classDefinitionNotFound0: Unit =
10+
code"class Foo { new ${m1}Bar$m2 }".withSource.definition(m1 to m2, Nil)
11+
12+
@Test def classDefinition0: Unit = {
13+
withSources(
14+
code"class ${m1}Foo$m2 { new Foo }",
15+
code"class Bar { val foo: ${m3}Foo$m4 = new ${m5}Foo$m6 }"
16+
) .definition(m1 to m2, List(m1 to m2))
17+
.definition(m3 to m4, List(m1 to m2))
18+
.definition(m5 to m6, List(m1 to m2))
19+
}
20+
21+
@Test def valDefinition0: Unit = {
22+
withSources(
23+
code"class Foo { val ${m1}x$m2 = 0; ${m3}x$m4 }",
24+
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
25+
) .definition(m1 to m2, List(m1 to m2))
26+
.definition(m3 to m4, List(m1 to m2))
27+
.definition(m5 to m6, List(m1 to m2))
28+
}
29+
30+
@Test def defDefinition0: Unit = {
31+
withSources(
32+
code"class Foo { def ${m1}x$m2 = 0; ${m3}x$m4 }",
33+
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
34+
) .definition(m1 to m2, List(m1 to m2))
35+
.definition(m3 to m4, List(m1 to m2))
36+
.definition(m5 to m6, List(m1 to m2))
37+
}
38+
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
import org.eclipse.lsp4j.SymbolKind
5+
6+
import dotty.tools.languageserver.util.Code._
7+
8+
9+
class DocumentSymbolTest {
10+
11+
@Test def documentSymbol0: Unit =
12+
code"class ${m1}Foo$m2".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
13+
14+
@Test def documentSymbol1: Unit =
15+
code"class ${m1}Foo$m2; class ${m3}Bar$m4".withSource
16+
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class), (m3 to m4).symInfo("Bar", SymbolKind.Class))
17+
18+
@Test def documentSymbol3: Unit = {
19+
withSources(
20+
code"class ${m1}Foo$m2",
21+
code"class ${m3}Bar$m4"
22+
) .documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
23+
.documentSymbol(m3, (m3 to m4).symInfo("Bar", SymbolKind.Class))
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
import dotty.tools.languageserver.util.Code._
5+
import org.eclipse.lsp4j.DocumentHighlightKind
6+
7+
class HighlightTest {
8+
9+
@Test def valHighlight0: Unit = {
10+
val xDef = (m1 to m2).withCode("x")
11+
code"class X { val $xDef = 9 }".withSource
12+
.highlight(xDef.range, (xDef.range, DocumentHighlightKind.Read))
13+
}
14+
15+
@Test def valHighlight1: Unit = {
16+
val xDef = (m1 to m2).withCode("x")
17+
val xRef = (m3 to m4).withCode("x")
18+
code"class X { val $xDef = 9; $xRef}".withSource
19+
.highlight(xRef.range, (xDef.range, DocumentHighlightKind.Read), (xRef.range, DocumentHighlightKind.Read))
20+
}
21+
22+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class HoverTest {
8+
9+
@Test def hoverOnWhiteSpace0: Unit =
10+
code"$m1 $m2".withSource.hover(m1 to m2, "")
11+
12+
@Test def hoverOnClass0: Unit = {
13+
code"""$m1 ${m2}class Foo $m3 $m4""".withSource
14+
.hover(m1 to m2, "")
15+
.hover(m2 to m3, "Foo")
16+
.hover(m3 to m4, "")
17+
}
18+
19+
@Test def hoverOnClass1: Unit = {
20+
code"""$m1 ${m2}class Foo { } $m3 $m4""".withSource
21+
.hover(m1 to m2, "")
22+
.hover(m2 to m3, "Foo")
23+
.hover(m3 to m4, "")
24+
}
25+
26+
@Test def hoverOnValDef0: Unit = {
27+
code"""class Foo {
28+
| ${m1}val x = ${m2}8$m3; ${m4}x$m5
29+
|}""".withSource
30+
.hover(m1 to m2, "Int")
31+
.hover(m2 to m3, "Int(8)")
32+
.hover(m4 to m5, "Int")
33+
}
34+
35+
@Test def hoverOnValDef1: Unit = {
36+
code"""class Foo {
37+
| ${m1}final val x = 8$m2; ${m3}x$m4
38+
|}""".withSource
39+
.hover(m1 to m2, "Int(8)")
40+
.hover(m3 to m4, "Int(8)")
41+
}
42+
43+
@Test def hoverOnDefDef0: Unit = {
44+
code"""class Foo {
45+
| ${m1}def x = ${m2}8$m3; ${m4}x$m5
46+
|}""".withSource
47+
.hover(m1 to m2, "Int")
48+
.hover(m2 to m3, "Int(8)")
49+
.hover(m4 to m5, "Int")
50+
}
51+
52+
@Test def hoverMissingRef0: Unit = {
53+
code"""class Foo {
54+
| ${m1}x$m2
55+
|}""".withSource
56+
.hover(m1 to m2, "<error not found: x>")
57+
}
58+
59+
@Test def hoverFun0: Unit = {
60+
code"""class Foo {
61+
| def x: String = $m1"abc"$m2
62+
| ${m3}x$m4
63+
|
64+
| def y(): Int = 9
65+
| ${m5}y($m6)$m7
66+
|}
67+
""".withSource
68+
.hover(m1 to m2, "String(\"abc\")")
69+
.hover(m3 to m4, "String")
70+
.hover(m5 to m6, "(): Int")
71+
.hover(m6 to m7, "Int")
72+
}
73+
74+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class ReferencesTest {
8+
9+
@Test def valNoReferences0: Unit =
10+
code"class X { val ${m1}x$m2 = 9 }".withSource.references(m1 to m2, Nil)
11+
12+
@Test def valReferences0: Unit = {
13+
code"class X { val ${m1}x$m2 = 9; ${m3}x$m4; ${m5}x$m6 }".withSource
14+
.references(m1 to m2, List(m3 to m4, m5 to m6))
15+
}
16+
17+
@Test def valReferences1: Unit = {
18+
code"class X { val ${m1}x$m2 = 9; ${m3}x$m4; ${m5}x$m6 }".withSource
19+
.references(m1 to m2, List(m1 to m2, m3 to m4, m5 to m6), withDecl = true)
20+
}
21+
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
import dotty.tools.languageserver.util.embedded.CodeMarker
7+
8+
class RenameTest {
9+
10+
@Test def rename0: Unit = {
11+
def testRenameFrom(m: CodeMarker) =
12+
code"class ${m1}Foo$m2 { new ${m3}Foo$m4 }".withSource.rename(m, "Bar", Set(m1 to m2, m3 to m4))
13+
testRenameFrom(m1)
14+
testRenameFrom(m3)
15+
}
16+
17+
18+
@Test def rename1: Unit = {
19+
def testRenameFrom(m: CodeMarker) =
20+
withSources(
21+
code"class ${m1}Foo$m2 { new ${m3}Foo$m4 }",
22+
code"class Bar { new ${m5}Foo$m6 }"
23+
).rename(m, "Bar", Set(m1 to m2, m3 to m4, m5 to m6))
24+
25+
testRenameFrom(m1)
26+
testRenameFrom(m3)
27+
testRenameFrom(m5)
28+
}
29+
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
import org.eclipse.lsp4j.SymbolKind
5+
6+
import dotty.tools.languageserver.util.Code._
7+
8+
class SymbolTest {
9+
10+
@Test def symbol0: Unit = {
11+
val Foo = (m1 to m2).withCode("Foo")
12+
withSources(code"class $Foo").symbol("Foo", Foo.range.symInfo("Foo", SymbolKind.Class))
13+
}
14+
15+
@Test def symbol1: Unit = {
16+
val Foo = (m1 to m2).withCode("Foo")
17+
val Bar = (m3 to m4).withCode("Bar")
18+
val fooFoo = (m5 to m6).withCode("Foo")
19+
withSources(
20+
code"class $Foo",
21+
code"class $Bar",
22+
code"""package foo
23+
|class $fooFoo {
24+
| class Bar
25+
|}
26+
"""
27+
) .symbol("Foo", Foo.range.symInfo("Foo", SymbolKind.Class), fooFoo.range.symInfo("Foo", SymbolKind.Class, "foo"))
28+
.symbol("Bar", Bar.range.symInfo("Bar", SymbolKind.Class))
29+
}
30+
}

0 commit comments

Comments
 (0)