|
| 1 | +package dotty.tools |
| 2 | +package repl |
| 3 | + |
| 4 | +import org.junit.Test |
| 5 | +import org.junit.Assert.assertEquals |
| 6 | + |
| 7 | +import ReplTest._ |
| 8 | + |
| 9 | +class DocTests extends ReplTest { |
| 10 | + @Test def docOfDef = |
| 11 | + fromInitialState { implicit s => compile("/** doc */ def foo = 0") } |
| 12 | + .andThen { implicit s => |
| 13 | + compiler.docOf("foo") |
| 14 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 15 | + } |
| 16 | + |
| 17 | + @Test def docOfVal = |
| 18 | + fromInitialState { implicit s => compile("/** doc */ val foo = 0") } |
| 19 | + .andThen { implicit s => |
| 20 | + compiler.docOf("foo") |
| 21 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 22 | + } |
| 23 | + |
| 24 | + @Test def docOfObject = |
| 25 | + fromInitialState { implicit s => compile("/** doc */ object Foo") } |
| 26 | + .andThen { implicit s => |
| 27 | + compiler.docOf("Foo") |
| 28 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 29 | + } |
| 30 | + |
| 31 | + @Test def docOfClass = |
| 32 | + fromInitialState { implicit s => compile("/** doc */ class Foo") } |
| 33 | + .andThen { implicit s => |
| 34 | + compiler.docOf("new Foo") |
| 35 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 36 | + } |
| 37 | + |
| 38 | + @Test def docOfTrait = |
| 39 | + fromInitialState { implicit s => compile("/** doc */ trait Foo") } |
| 40 | + .andThen { implicit s => |
| 41 | + compiler.docOf("new Foo") |
| 42 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 43 | + } |
| 44 | + |
| 45 | + @Test def docOfDefInObject = |
| 46 | + fromInitialState { implicit s => compile("object O { /** doc */ def foo = 0 }") } |
| 47 | + .andThen { implicit s => |
| 48 | + compiler.docOf("O.foo") |
| 49 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 50 | + } |
| 51 | + |
| 52 | + @Test def docOfValInObject = |
| 53 | + fromInitialState { implicit s => compile("object O { /** doc */ val foo = 0 }") } |
| 54 | + .andThen { implicit s => |
| 55 | + compiler.docOf("O.foo") |
| 56 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 57 | + } |
| 58 | + |
| 59 | + @Test def docOfObjectInObject = |
| 60 | + fromInitialState { implicit s => compile("object O { /** doc */ object Foo }") } |
| 61 | + .andThen { implicit s => |
| 62 | + compiler.docOf("O.Foo") |
| 63 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 64 | + } |
| 65 | + |
| 66 | + @Test def docOfClassInObject = |
| 67 | + fromInitialState { implicit s => compile("object O { /** doc */ class Foo }") } |
| 68 | + .andThen { implicit s => |
| 69 | + compiler.docOf("new O.Foo") |
| 70 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 71 | + } |
| 72 | + |
| 73 | + @Test def docOfTraitInObject = |
| 74 | + fromInitialState { implicit s => compile("object O { /** doc */ trait Foo }") } |
| 75 | + .andThen { implicit s => |
| 76 | + compiler.docOf("new O.Foo") |
| 77 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 78 | + } |
| 79 | + |
| 80 | + @Test def docOfDetInClass = |
| 81 | + fromInitialState { implicit s => compile("class C { /** doc */ def foo = 0 }") } |
| 82 | + .andThen { implicit s => compile("val c = new C") } |
| 83 | + .andThen { implicit s => |
| 84 | + compiler.docOf("c.foo") |
| 85 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 86 | + } |
| 87 | + |
| 88 | + @Test def docOfVatInClass = |
| 89 | + fromInitialState { implicit s => compile("class C { /** doc */ val foo = 0 }") } |
| 90 | + .andThen { implicit s => compile("val c = new C") } |
| 91 | + .andThen { implicit s => |
| 92 | + compiler.docOf("c.foo") |
| 93 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 94 | + } |
| 95 | + |
| 96 | + @Test def docOfObjectInClass = |
| 97 | + fromInitialState { implicit s => compile("class C { /** doc */ object Foo }") } |
| 98 | + .andThen { implicit s => compile("val c = new C") } |
| 99 | + .andThen { implicit s => |
| 100 | + compiler.docOf("c.Foo") |
| 101 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 102 | + } |
| 103 | + |
| 104 | + @Test def docOfClassInClass = |
| 105 | + fromInitialState { implicit s => compile("class C { /** doc */ class Foo }") } |
| 106 | + .andThen { implicit s => compile("val c = new C") } |
| 107 | + .andThen { implicit s => |
| 108 | + compiler.docOf("new c.Foo") |
| 109 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 110 | + } |
| 111 | + |
| 112 | + @Test def docOfTraitInClass = |
| 113 | + fromInitialState { implicit s => compile("class C { /** doc */ trait Foo }") } |
| 114 | + .andThen { implicit s => compile("val c = new C") } |
| 115 | + .andThen { implicit s => |
| 116 | + compiler.docOf("new c.Foo") |
| 117 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 118 | + } |
| 119 | + |
| 120 | + @Test def docOfOverloadedDef = |
| 121 | + fromInitialState { implicit s => |
| 122 | + compile("""object O { |
| 123 | + |/** doc0 */ def foo(x: Int) = x |
| 124 | + |/** doc1 */ def foo(x: String) = x |
| 125 | + |}""".stripMargin) |
| 126 | + } |
| 127 | + .andThen { implicit s => |
| 128 | + compiler.docOf("O.foo(_: Int)") |
| 129 | + .fold(onErrors, assertEquals("/** doc0 */", _)) |
| 130 | + s |
| 131 | + } |
| 132 | + .andThen { implicit s => |
| 133 | + compiler.docOf("O.foo(_: String)") |
| 134 | + .fold(onErrors, assertEquals("/** doc1 */", _)) |
| 135 | + } |
| 136 | + |
| 137 | + @Test def docOfInherited = |
| 138 | + fromInitialState { implicit s => compile("class C { /** doc */ def foo = 0 }") } |
| 139 | + .andThen { implicit s => compile("object O extends C") } |
| 140 | + .andThen { implicit s => |
| 141 | + compiler.docOf("O.foo") |
| 142 | + .fold(onErrors, assertEquals("/** doc */", _)) |
| 143 | + } |
| 144 | + |
| 145 | +} |
0 commit comments