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