@@ -5,205 +5,154 @@ import org.junit.Test
5
5
import org .junit .Assert .assertEquals
6
6
7
7
class DocTests extends ReplTest {
8
+
8
9
@ 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)
10
+ eval(" /** doc */ def foo = 0" ).andThen { implicit s =>
11
+ assertEquals(" /** doc */" , doc(" foo" ))
14
12
}
15
13
16
14
@ 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)
15
+ eval(" /** doc */ val foo = 0" ).andThen { implicit s =>
16
+ assertEquals(" /** doc */" , doc(" foo" ))
22
17
}
23
18
24
19
@ 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)
20
+ eval(" /** doc */ object Foo" ).andThen { implicit s =>
21
+ assertEquals(" /** doc */" , doc(" Foo" ))
30
22
}
31
23
32
24
@ 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)
25
+ eval(" /** doc */ class Foo" ).andThen { implicit s =>
26
+ assertEquals(" /** doc */" , doc(" new Foo" ))
38
27
}
39
28
40
29
@ 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)
30
+ eval(" /** doc */ trait Foo" ).andThen { implicit s =>
31
+ assertEquals(" /** doc */" , doc(" new Foo" ))
46
32
}
47
33
48
34
@ 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)
35
+ eval(" object O { /** doc */ def foo = 0 }" ).andThen { implicit s =>
36
+ assertEquals(" /** doc */" , doc(" O.foo" ))
54
37
}
55
38
56
39
@ 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)
40
+ eval(" object O { /** doc */ val foo = 0 }" ).andThen { implicit s =>
41
+ assertEquals(" /** doc */" , doc(" O.foo" ))
62
42
}
63
43
64
44
@ 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)
45
+ eval(" object O { /** doc */ object Foo }" ).andThen { implicit s =>
46
+ assertEquals(" /** doc */" , doc(" O.Foo" ))
70
47
}
71
48
72
49
@ 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)
50
+ eval(" object O { /** doc */ class Foo }" ).andThen { implicit s =>
51
+ assertEquals(" /** doc */" , doc(" new O.Foo" ))
78
52
}
79
53
80
54
@ 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)
55
+ eval(" object O { /** doc */ trait Foo }" ).andThen { implicit s =>
56
+ assertEquals(" /** doc */" , doc(" new O.Foo" ))
86
57
}
87
58
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)
59
+ @ Test def docOfDefInClass =
60
+ eval(
61
+ """ class C { /** doc */ def foo = 0 }
62
+ |val c = new C
63
+ """ .stripMargin).andThen { implicit s =>
64
+ assertEquals(" /** doc */" , doc(" c.foo" ))
95
65
}
96
66
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)
67
+ @ Test def docOfValInClass =
68
+ eval(
69
+ """ class C { /** doc */ val foo = 0 }
70
+ |val c = new C
71
+ """ .stripMargin).andThen { implicit s =>
72
+ assertEquals(" /** doc */" , doc(" c.foo" ))
104
73
}
105
74
106
75
@ 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)
76
+ eval(
77
+ """ class C { /** doc */ object Foo }
78
+ |val c = new C
79
+ """ .stripMargin).andThen { implicit s =>
80
+ assertEquals(" /** doc */" , doc(" c.Foo" ))
113
81
}
114
82
115
83
@ 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)
84
+ eval(
85
+ """ class C { /** doc */ class Foo }
86
+ |val c = new C
87
+ """ .stripMargin).andThen { implicit s =>
88
+ assertEquals(" /** doc */" , doc(" new c.Foo" ))
122
89
}
123
90
124
91
@ 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)
92
+ eval(
93
+ """ class C { /** doc */ trait Foo }
94
+ |val c = new C
95
+ """ .stripMargin).andThen { implicit s =>
96
+ assertEquals(" /** doc */" , doc(" new c.Foo" ))
131
97
}
132
98
133
99
@ 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)
100
+ eval(
101
+ """ object O {
102
+ | /** doc0 */ def foo(x: Int) = x
103
+ | /** doc1 */ def foo(x: String) = x
104
+ |}
105
+ """ .stripMargin).andThen { implicit s =>
106
+ assertEquals(" /** doc0 */" , doc(" O.foo(_: Int)" ))
107
+ assertEquals(" /** doc1 */" , doc(" O.foo(_: String)" ))
149
108
}
150
109
151
110
@ 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)
111
+ eval(
112
+ """ class C { /** doc */ def foo = 0 }
113
+ |object O extends C
114
+ """ .stripMargin).andThen { implicit s =>
115
+ assertEquals(" /** doc */" , doc(" O.foo" ))
158
116
}
159
117
160
118
@ Test def docOfOverride =
161
- fromInitialState { implicit s =>
162
- run(""" abstract class A {
163
- |/** doc0 */ def foo(x: Int): Int = x + 1
164
- |/** doc1 */ def foo(x: String): String = x + "foo"
165
- |}""" .stripMargin)
166
- }
167
- .andThen { implicit s =>
168
- run(""" object O extends A {
169
- | override def foo(x: Int): Int = x
170
- | /** overridden doc */ override def foo(x: String): String = x
171
- |}""" .stripMargin)
172
- }
173
- .andThen { implicit s =>
174
- storedOutput()
175
- run(" :doc O.foo(_: Int)" )
176
- assertEquals(" /** doc0 */" , storedOutput().trim)
177
- s
178
- }
179
- .andThen { implicit s =>
180
- run(" :doc O.foo(_: String)" )
181
- assertEquals(" /** overridden doc */" , storedOutput().trim)
119
+ eval(
120
+ """ abstract class A {
121
+ | /** doc0 */ def foo(x: Int): Int = x + 1
122
+ | /** doc1 */ def foo(x: String): String = x + "foo"
123
+ |}
124
+ |object O extends A {
125
+ | override def foo(x: Int): Int = x
126
+ | /** overridden doc */ override def foo(x: String): String = x
127
+ |}
128
+ """ .stripMargin).andThen { implicit s =>
129
+ assertEquals(" /** doc0 */" , doc(" O.foo(_: Int)" ))
130
+ assertEquals(" /** overridden doc */" , doc(" O.foo(_: String)" ))
182
131
}
183
132
184
133
@ Test def docOfOverrideObject =
185
- fromInitialState { implicit s =>
186
- run( """ abstract class A {
187
- | abstract class Companion { /** doc0 */ def bar: Int }
188
- | /** companion */ def foo: Companion
189
- |} """ .stripMargin)
190
- .andThen { implicit s =>
191
- run( """ object O extends A {
192
- | override object foo extends Companion {
193
- | override def bar: Int = 0
194
- | }
195
- |} """ .stripMargin)
196
- }
197
- .andThen { implicit s =>
198
- storedOutput()
199
- run( " :doc O.foo " )
200
- assertEquals( " /** companion */ " , storedOutput().trim)
201
- s
202
- }
203
- .andThen { implicit s =>
204
- run( " :doc O.foo.bar " )
205
- assertEquals( " /** doc0 */ " , storedOutput().trim )
206
- }
207
- }
134
+ eval(
135
+ """ abstract class A {
136
+ | abstract class Companion { /** doc0 */ def bar: Int }
137
+ | /** companion */ def foo: Companion
138
+ |}
139
+ |object O extends A {
140
+ | override object foo extends Companion {
141
+ | override def bar: Int = 0
142
+ | }
143
+ | }
144
+ """ .stripMargin).andThen { implicit s =>
145
+ assertEquals( " /** companion */ " , doc( " O.foo " ))
146
+ assertEquals( " /** doc0 */ " , doc( " O.foo.bar " ))
147
+ }
148
+
149
+ private def eval ( code : String ) : State =
150
+ fromInitialState { implicit s => run(code) }
151
+
152
+ private def doc ( expr : String )( implicit s : State ) : String = {
153
+ storedOutput( )
154
+ run( s " :doc $expr " )
155
+ storedOutput().trim
156
+ }
208
157
209
158
}
0 commit comments