Skip to content

Commit 46f334a

Browse files
committed
Prefer context functions for ReplTests
1 parent 6a50e5c commit 46f334a

File tree

7 files changed

+122
-173
lines changed

7 files changed

+122
-173
lines changed

compiler/test/dotty/tools/repl/DocTests.scala

Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,110 +6,76 @@ import org.junit.Assert.assertEquals
66

77
class DocTests extends ReplTest {
88

9-
@Test def docOfDef =
10-
eval("/** doc */ def foo = 0").andThen { implicit s =>
11-
assertEquals("doc", doc("foo"))
12-
}
9+
@Test def docOfDef = eval("/** doc */ def foo = 0") andThen assertEquals("doc", doc("foo"))
1310

14-
@Test def docOfVal =
15-
eval("/** doc */ val foo = 0").andThen { implicit s =>
16-
assertEquals("doc", doc("foo"))
17-
}
11+
@Test def docOfVal = eval("/** doc */ val foo = 0") andThen assertEquals("doc", doc("foo"))
1812

19-
@Test def docOfObject =
20-
eval("/** doc */ object Foo").andThen { implicit s =>
21-
assertEquals("doc", doc("Foo"))
22-
}
13+
@Test def docOfObject = eval("/** doc */ object Foo") andThen assertEquals("doc", doc("Foo"))
2314

24-
@Test def docOfClass =
25-
eval("/** doc */ class Foo").andThen { implicit s =>
26-
assertEquals("doc", doc("new Foo"))
27-
}
15+
@Test def docOfClass = eval("/** doc */ class Foo") andThen assertEquals("doc", doc("new Foo"))
2816

29-
@Test def docOfTrait =
30-
eval("/** doc */ trait Foo").andThen { implicit s =>
31-
assertEquals("doc", doc("new Foo"))
32-
}
33-
/*
34-
@Test def docOfExtension1 =
35-
eval("/** doc */ extension (x: Int) def foo = 0").andThen { implicit s =>
36-
assertEquals("doc", doc("extension_foo"))
37-
}
17+
@Test def docOfTrait = eval("/** doc */ trait Foo") andThen assertEquals("doc", doc("new Foo"))
3818

39-
@Test def docOfExtension2 =
40-
eval("extension (x: Int) /** doc */ def foo = 0").andThen { implicit s =>
41-
assertEquals("doc", doc("extension_foo"))
42-
}
19+
/*@Test*/ def docOfExtension1 =
20+
eval("/** doc */ extension (x: Int) def foo = 0") andThen assertEquals("doc", doc("extension_foo"))
4321

44-
@Test def docOfExtension3 =
45-
eval("/** doc0 */ extension (x: Int) { /** doc1 */ def foo = 0; /** doc2 */ def bar = 0; def baz = 0 }").andThen { implicit s =>
22+
/*@Test*/ def docOfExtension2 =
23+
eval("extension (x: Int) /** doc */ def foo = 0") andThen assertEquals("doc", doc("extension_foo"))
24+
25+
/*@Test*/ def docOfExtension3 =
26+
eval("/** doc0 */ extension (x: Int) { /** doc1 */ def foo = 0; /** doc2 */ def bar = 0; def baz = 0 }") andThen {
4627
assertEquals("doc1", doc("extension_foo"))
4728
assertEquals("doc2", doc("extension_bar"))
4829
assertEquals("doc0", doc("extension_baz"))
4930
}
50-
*/
51-
@Test def docOfDefInObject =
52-
eval("object O { /** doc */ def foo = 0 }").andThen { implicit s =>
53-
assertEquals("doc", doc("O.foo"))
54-
}
5531

56-
@Test def docOfValInObject =
57-
eval("object O { /** doc */ val foo = 0 }").andThen { implicit s =>
58-
assertEquals("doc", doc("O.foo"))
59-
}
32+
@Test def docOfDefInObject = eval("object O { /** doc */ def foo = 0 }") andThen assertEquals("doc", doc("O.foo"))
6033

61-
@Test def docOfObjectInObject =
62-
eval("object O { /** doc */ object Foo }").andThen { implicit s =>
63-
assertEquals("doc", doc("O.Foo"))
64-
}
34+
@Test def docOfValInObject = eval("object O { /** doc */ val foo = 0 }") andThen assertEquals("doc", doc("O.foo"))
6535

66-
@Test def docOfClassInObject =
67-
eval("object O { /** doc */ class Foo }").andThen { implicit s =>
68-
assertEquals("doc", doc("new O.Foo"))
69-
}
36+
@Test def docOfObjectInObject = eval("object O { /** doc */ object Foo }") andThen assertEquals("doc", doc("O.Foo"))
7037

71-
@Test def docOfTraitInObject =
72-
eval("object O { /** doc */ trait Foo }").andThen { implicit s =>
73-
assertEquals("doc", doc("new O.Foo"))
74-
}
38+
@Test def docOfClassInObject = eval("object O { /** doc */ class Foo }") andThen assertEquals("doc", doc("new O.Foo"))
39+
40+
@Test def docOfTraitInObject = eval("object O { /** doc */ trait Foo }") andThen assertEquals("doc", doc("new O.Foo"))
7541

7642
@Test def docOfDefInClass =
7743
eval(
7844
"""class C { /** doc */ def foo = 0 }
7945
|val c = new C
80-
""".stripMargin).andThen { implicit s =>
46+
""".stripMargin) andThen {
8147
assertEquals("doc", doc("c.foo"))
8248
}
8349

8450
@Test def docOfValInClass =
8551
eval(
8652
"""class C { /** doc */ val foo = 0 }
8753
|val c = new C
88-
""".stripMargin).andThen { implicit s =>
54+
""".stripMargin) andThen {
8955
assertEquals("doc", doc("c.foo"))
9056
}
9157

9258
@Test def docOfObjectInClass =
9359
eval(
9460
"""class C { /** doc */ object Foo }
9561
|val c = new C
96-
""".stripMargin).andThen { implicit s =>
62+
""".stripMargin) andThen {
9763
assertEquals("doc", doc("c.Foo"))
9864
}
9965

10066
@Test def docOfClassInClass =
10167
eval(
10268
"""class C { /** doc */ class Foo }
10369
|val c = new C
104-
""".stripMargin).andThen { implicit s =>
70+
""".stripMargin) andThen {
10571
assertEquals("doc", doc("new c.Foo"))
10672
}
10773

10874
@Test def docOfTraitInClass =
10975
eval(
11076
"""class C { /** doc */ trait Foo }
11177
|val c = new C
112-
""".stripMargin).andThen { implicit s =>
78+
""".stripMargin) andThen {
11379
assertEquals("doc", doc("new c.Foo"))
11480
}
11581

@@ -119,7 +85,7 @@ class DocTests extends ReplTest {
11985
| /** doc0 */ def foo(x: Int) = x
12086
| /** doc1 */ def foo(x: String) = x
12187
|}
122-
""".stripMargin).andThen { implicit s =>
88+
""".stripMargin) andThen {
12389
assertEquals("doc0", doc("O.foo(_: Int)"))
12490
assertEquals("doc1", doc("O.foo(_: String)"))
12591
}
@@ -128,7 +94,7 @@ class DocTests extends ReplTest {
12894
eval(
12995
"""class C { /** doc */ def foo = 0 }
13096
|object O extends C
131-
""".stripMargin).andThen { implicit s =>
97+
""".stripMargin) andThen {
13298
assertEquals("doc", doc("O.foo"))
13399
}
134100

@@ -142,7 +108,7 @@ class DocTests extends ReplTest {
142108
| override def foo(x: Int): Int = x
143109
| /** overridden doc */ override def foo(x: String): String = x
144110
|}
145-
""".stripMargin).andThen { implicit s =>
111+
""".stripMargin) andThen {
146112
assertEquals("doc0", doc("O.foo(_: Int)"))
147113
assertEquals("overridden doc", doc("O.foo(_: String)"))
148114
}
@@ -158,38 +124,34 @@ class DocTests extends ReplTest {
158124
| override def bar: Int = 0
159125
| }
160126
|}
161-
""".stripMargin).andThen { implicit s =>
127+
""".stripMargin) andThen {
162128
assertEquals("companion", doc("O.foo"))
163129
assertEquals("doc0", doc("O.foo.bar"))
164130
}
165131

166132
@Test def docIsCooked =
167133
eval(
168-
"""/**
169-
| * An object
134+
"""/** An object
170135
| * @define Variable some-value
171136
| */
172137
|object Foo {
173138
| /** Expansion: $Variable */
174139
| def hello = "world"
175140
|}
176-
""".stripMargin).andThen { implicit s =>
141+
""".stripMargin) andThen {
177142
assertEquals("Expansion: some-value", doc("Foo.hello"))
178143
}
179144

180-
@Test def docOfEmpty =
181-
fromInitialState { implicit s =>
145+
@Test def docOfEmpty = initially {
182146
run(":doc")
183147
assertEquals(":doc <expression>", storedOutput().trim)
184148
}
185149

186-
private def eval(code: String): State =
187-
fromInitialState { implicit s => run(code) }
150+
private def eval(code: String): State = initially(run(code))
188151

189-
private def doc(expr: String)(implicit s: State): String = {
152+
private def doc(expr: String)(using State): String = {
190153
storedOutput()
191154
run(s":doc $expr")
192155
storedOutput().trim
193156
}
194-
195157
}

compiler/test/dotty/tools/repl/JavaDefinedTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import org.junit.Assert._
44
import org.junit.Test
55

66
class JavaDefinedTests extends ReplTest {
7-
@Test def typeOfJavaDefinedString = fromInitialState { implicit s =>
7+
@Test def typeOfJavaDefinedString = initially {
88
run("String")
99
assertTrue(storedOutput().contains("Java defined class String is not a value"))
1010
}
1111

12-
@Test def typeOfJavaDefinedClass = fromInitialState { implicit s =>
12+
@Test def typeOfJavaDefinedClass = initially {
1313
run("Class")
1414
assertTrue(storedOutput().contains("Java defined class Class is not a value"))
1515
}

compiler/test/dotty/tools/repl/LoadTests.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ class LoadTests extends ReplTest {
4646
)
4747

4848
def loadTest(file: String, defs: String, runCode: String, output: String) =
49-
eval(s":load ${writeFile(file)}").andThen { implicit s =>
49+
eval(s":load ${writeFile(file)}") andThen {
5050
assertMultiLineEquals(defs, storedOutput())
5151
run(runCode)
5252
assertMultiLineEquals(output, storedOutput())
5353
}
5454

55-
private def eval(code: String): State =
56-
fromInitialState { implicit s => run(code) }
57-
55+
private def eval(code: String): State = initially(run(code))
5856
}
5957

6058
object LoadTests {

0 commit comments

Comments
 (0)