Skip to content

Add IDE tests #3766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ pipeline:
- cp -R . /tmp/3/ && cd /tmp/3/
- ./project/scripts/sbt dotty-optimised/test

test_sbt:
test_ide:
group: test
image: lampepfl/dotty:2018-04-10
commands:
- cp -R . /tmp/4/ && cd /tmp/4/
- ./project/scripts/sbt dotty-language-server/test

test_sbt:
group: test
image: lampepfl/dotty:2017-11-17
commands:
- cp -R . /tmp/5/ && cd /tmp/5/
- ./project/scripts/sbt sbt-dotty/scripted
when:
# sbt scripted tests are slow and only run on nightly or deployment
Expand Down
16 changes: 16 additions & 0 deletions compiler/src/dotty/tools/dotc/util/DiffUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ object DiffUtil {
(fnd, exp, totalChange.toDouble / (expected.length + found.length))
}

/**
* Return a colored diff between the tokens of every line in `expected` and `actual`. Each line of
* output contains the expected value on the left and the actual value on the right.
*
* @param expected The expected lines
* @param actual The actual lines
* @return A string with one element of `expected` and `actual` on each lines, where
* differences are highlighted.
*/
def mkColoredLineDiff(expected: Seq[String], actual: Seq[String]): String = {
val expectedSize = EOF.length max expected.maxBy(_.length).length
actual.padTo(expected.length, "").zip(expected.padTo(actual.length, "")).map { case (act, exp) =>
mkColoredLineDiff(exp, act, expectedSize)
}.mkString(System.lineSeparator)
}

def mkColoredLineDiff(expected: String, actual: String, expectedSize: Int): String = {
lazy val diff = {
val tokens = splitTokens(expected, Nil).toArray
Expand Down
5 changes: 1 addition & 4 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>

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

val msg =
s"""|Output from '$sourceTitle' did not match check file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ class DottyLanguageServer extends LanguageServer
val newName = params.getNewName

val refs = Interactive.namedTrees(trees, includeReferences = true, tree =>
(Interactive.matchSymbol(tree, sym, Include.overriding)
|| (linkedSym != NoSymbol && Interactive.matchSymbol(tree, linkedSym, Include.overriding))))
tree.pos.isSourceDerived
&& (Interactive.matchSymbol(tree, sym, Include.overriding)
|| (linkedSym != NoSymbol && Interactive.matchSymbol(tree, linkedSym, Include.overriding))))

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dotty.tools.languageserver

import org.junit.Test
import org.eclipse.lsp4j.CompletionItemKind

import dotty.tools.languageserver.util.Code._

class CompletionTest {

@Test def completion0: Unit = {
code"class Foo { val xyz: Int = 0; def y: Int = xy$m1 }".withSource
.completion(m1, Set(("xyz", CompletionItemKind.Field, "Int")))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dotty.tools.languageserver

import org.junit.Test

import dotty.tools.languageserver.util.Code._

class DefinitionTest {

@Test def classDefinitionNotFound0: Unit =
code"class Foo { new ${m1}Bar$m2 }".withSource.definition(m1 to m2, Nil)

@Test def classDefinition0: Unit = {
withSources(
code"class ${m1}Foo$m2 { new Foo }",
code"class Bar { val foo: ${m3}Foo$m4 = new ${m5}Foo$m6 }"
) .definition(m1 to m2, List(m1 to m2))
.definition(m3 to m4, List(m1 to m2))
.definition(m5 to m6, List(m1 to m2))
}

@Test def valDefinition0: Unit = {
withSources(
code"class Foo { val ${m1}x$m2 = 0; ${m3}x$m4 }",
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
) .definition(m1 to m2, List(m1 to m2))
.definition(m3 to m4, List(m1 to m2))
.definition(m5 to m6, List(m1 to m2))
}

@Test def defDefinition0: Unit = {
withSources(
code"class Foo { def ${m1}x$m2 = 0; ${m3}x$m4 }",
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
) .definition(m1 to m2, List(m1 to m2))
.definition(m3 to m4, List(m1 to m2))
.definition(m5 to m6, List(m1 to m2))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dotty.tools.languageserver

import org.junit.Test
import org.eclipse.lsp4j.SymbolKind

import dotty.tools.languageserver.util.Code._


class DocumentSymbolTest {

@Test def documentSymbol0: Unit =
code"class ${m1}Foo$m2".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))

@Test def documentSymbol1: Unit =
code"class ${m1}Foo$m2; class ${m3}Bar$m4".withSource
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class), (m3 to m4).symInfo("Bar", SymbolKind.Class))

@Test def documentSymbol3: Unit = {
withSources(
code"class ${m1}Foo$m2",
code"class ${m3}Bar$m4"
) .documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
.documentSymbol(m3, (m3 to m4).symInfo("Bar", SymbolKind.Class))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dotty.tools.languageserver

import org.junit.Test
import dotty.tools.languageserver.util.Code._
import org.eclipse.lsp4j.DocumentHighlightKind

class HighlightTest {

@Test def valHighlight0: Unit = {
val xDef = (m1 to m2).withCode("x")
code"class X { val $xDef = 9 }".withSource
.highlight(xDef.range, (xDef.range, DocumentHighlightKind.Read))
}

@Test def valHighlight1: Unit = {
val xDef = (m1 to m2).withCode("x")
val xRef = (m3 to m4).withCode("x")
code"class X { val $xDef = 9; $xRef}".withSource
.highlight(xRef.range, (xDef.range, DocumentHighlightKind.Read), (xRef.range, DocumentHighlightKind.Read))
}

}
74 changes: 74 additions & 0 deletions language-server/test/dotty/tools/languageserver/HoverTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package dotty.tools.languageserver

import org.junit.Test

import dotty.tools.languageserver.util.Code._

class HoverTest {

@Test def hoverOnWhiteSpace0: Unit =
code"$m1 $m2".withSource.hover(m1 to m2, "")

@Test def hoverOnClass0: Unit = {
code"""$m1 ${m2}class Foo $m3 $m4""".withSource
.hover(m1 to m2, "")
.hover(m2 to m3, "Foo")
.hover(m3 to m4, "")
}

@Test def hoverOnClass1: Unit = {
code"""$m1 ${m2}class Foo { } $m3 $m4""".withSource
.hover(m1 to m2, "")
.hover(m2 to m3, "Foo")
.hover(m3 to m4, "")
}

@Test def hoverOnValDef0: Unit = {
code"""class Foo {
| ${m1}val x = ${m2}8$m3; ${m4}x$m5
|}""".withSource
.hover(m1 to m2, "Int")
.hover(m2 to m3, "Int(8)")
.hover(m4 to m5, "Int")
}

@Test def hoverOnValDef1: Unit = {
code"""class Foo {
| ${m1}final val x = 8$m2; ${m3}x$m4
|}""".withSource
.hover(m1 to m2, "Int(8)")
.hover(m3 to m4, "Int(8)")
}

@Test def hoverOnDefDef0: Unit = {
code"""class Foo {
| ${m1}def x = ${m2}8$m3; ${m4}x$m5
|}""".withSource
.hover(m1 to m2, "Int")
.hover(m2 to m3, "Int(8)")
.hover(m4 to m5, "Int")
}

@Test def hoverMissingRef0: Unit = {
code"""class Foo {
| ${m1}x$m2
|}""".withSource
.hover(m1 to m2, "<error not found: x>")
}

@Test def hoverFun0: Unit = {
code"""class Foo {
| def x: String = $m1"abc"$m2
| ${m3}x$m4
|
| def y(): Int = 9
| ${m5}y($m6)$m7
|}
""".withSource
.hover(m1 to m2, "String(\"abc\")")
.hover(m3 to m4, "String")
.hover(m5 to m6, "(): Int")
.hover(m6 to m7, "Int")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dotty.tools.languageserver

import org.junit.Test

import dotty.tools.languageserver.util.Code._

class ReferencesTest {

@Test def valNoReferences0: Unit =
code"class X { val ${m1}x$m2 = 9 }".withSource.references(m1 to m2, Nil)

@Test def valReferences0: Unit = {
code"class X { val ${m1}x$m2 = 9; ${m3}x$m4; ${m5}x$m6 }".withSource
.references(m1 to m2, List(m3 to m4, m5 to m6))
}

@Test def valReferences1: Unit = {
code"class X { val ${m1}x$m2 = 9; ${m3}x$m4; ${m5}x$m6 }".withSource
.references(m1 to m2, List(m1 to m2, m3 to m4, m5 to m6), withDecl = true)
}

}
30 changes: 30 additions & 0 deletions language-server/test/dotty/tools/languageserver/RenameTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dotty.tools.languageserver

import org.junit.Test

import dotty.tools.languageserver.util.Code._
import dotty.tools.languageserver.util.embedded.CodeMarker

class RenameTest {

@Test def rename0: Unit = {
def testRenameFrom(m: CodeMarker) =
code"class ${m1}Foo$m2 { new ${m3}Foo$m4 }".withSource.rename(m, "Bar", Set(m1 to m2, m3 to m4))
testRenameFrom(m1)
testRenameFrom(m3)
}


@Test def rename1: Unit = {
def testRenameFrom(m: CodeMarker) =
withSources(
code"class ${m1}Foo$m2 { new ${m3}Foo$m4 }",
code"class Bar { new ${m5}Foo$m6 }"
).rename(m, "Bar", Set(m1 to m2, m3 to m4, m5 to m6))

testRenameFrom(m1)
testRenameFrom(m3)
testRenameFrom(m5)
}

}
30 changes: 30 additions & 0 deletions language-server/test/dotty/tools/languageserver/SymbolTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dotty.tools.languageserver

import org.junit.Test
import org.eclipse.lsp4j.SymbolKind

import dotty.tools.languageserver.util.Code._

class SymbolTest {

@Test def symbol0: Unit = {
val Foo = (m1 to m2).withCode("Foo")
withSources(code"class $Foo").symbol("Foo", Foo.range.symInfo("Foo", SymbolKind.Class))
}

@Test def symbol1: Unit = {
val Foo = (m1 to m2).withCode("Foo")
val Bar = (m3 to m4).withCode("Bar")
val fooFoo = (m5 to m6).withCode("Foo")
withSources(
code"class $Foo",
code"class $Bar",
code"""package foo
|class $fooFoo {
| class Bar
|}
"""
) .symbol("Foo", Foo.range.symInfo("Foo", SymbolKind.Class), fooFoo.range.symInfo("Foo", SymbolKind.Class, "foo"))
.symbol("Bar", Bar.range.symInfo("Bar", SymbolKind.Class))
}
}
Loading