File tree Expand file tree Collapse file tree 2 files changed +46
-21
lines changed Expand file tree Collapse file tree 2 files changed +46
-21
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,27 @@ fn write_return(
204
204
}
205
205
}
206
206
207
+ #[ test]
208
+ fn should_write_return_type_on_new_line ( ) {
209
+ let markdown = test:: render ( "fn a() -> int { }" ) ;
210
+ assert str:: contains ( markdown, "\n Returns `int`" ) ;
211
+ }
212
+
213
+ #[ test]
214
+ fn should_write_blank_line_between_return_type_and_next_header ( ) {
215
+ let markdown = test:: render (
216
+ "fn a() -> int { } \
217
+ fn b() -> int { }"
218
+ ) ;
219
+ assert str:: contains ( markdown, "Returns `int`\n \n ##" ) ;
220
+ }
221
+
222
+ #[ test]
223
+ fn should_not_write_return_type_when_there_is_none ( ) {
224
+ let markdown = test:: render ( "fn a() { }" ) ;
225
+ assert !str:: contains ( markdown, "Returns" ) ;
226
+ }
227
+
207
228
#[ cfg( test) ]
208
229
mod test {
209
230
fn render ( source : str ) -> str {
@@ -272,18 +293,4 @@ mod test {
272
293
assert str:: contains ( markdown, "brief\n \n desc" ) ;
273
294
}
274
295
275
- #[ test]
276
- fn should_write_return_type_on_new_line ( ) {
277
- let markdown = render ( "fn a() -> int { }" ) ;
278
- assert str:: contains ( markdown, "\n Returns `int`" ) ;
279
- }
280
-
281
- #[ test]
282
- fn should_write_blank_line_between_return_type_and_next_header ( ) {
283
- let markdown = render (
284
- "fn a() -> int { } \
285
- fn b() -> int { }"
286
- ) ;
287
- assert str:: contains ( markdown, "Returns `int`\n \n ##" ) ;
288
- }
289
296
}
Original file line number Diff line number Diff line change @@ -46,27 +46,36 @@ fn merge_ret_ty(
46
46
fn_id : doc:: ast_id ,
47
47
doc : option < doc:: retdoc >
48
48
) -> option < doc:: retdoc > {
49
- let ty = get_ret_ty ( srv, fn_id) ;
50
49
alt doc {
51
50
some( doc) {
52
51
fail "unimplemented" ;
53
52
}
54
53
none. {
55
- some ( {
56
- desc: none,
57
- ty: some ( ty)
58
- } )
54
+ alt get_ret_ty ( srv, fn_id) {
55
+ some ( ty) {
56
+ some ( {
57
+ desc: none,
58
+ ty: some ( ty)
59
+ } )
60
+ }
61
+ none. { none }
62
+ }
59
63
}
60
64
}
61
65
}
62
66
63
- fn get_ret_ty ( srv : astsrv:: srv , id : doc:: ast_id ) -> str {
67
+ fn get_ret_ty ( srv : astsrv:: srv , id : doc:: ast_id ) -> option < str > {
64
68
astsrv:: exec ( srv) { |ctxt|
65
69
alt ctxt. map . get ( id) {
66
70
ast_map:: node_item ( @{
67
71
node: ast:: item_fn ( decl, _, _) , _
68
72
} ) {
69
- pprust:: ty_to_str ( decl. output )
73
+ if decl. output . node != ast:: ty_nil {
74
+ some ( pprust:: ty_to_str ( decl. output ) )
75
+ } else {
76
+ // Nil-typed return values are not interesting
77
+ none
78
+ }
70
79
}
71
80
}
72
81
}
@@ -81,6 +90,15 @@ fn should_add_fn_ret_types() {
81
90
assert option:: get ( doc. topmod . fns [ 0 ] . return ) . ty == some ( "int" ) ;
82
91
}
83
92
93
+ #[ test]
94
+ fn should_not_add_nil_ret_type ( ) {
95
+ let source = "fn a() { }" ;
96
+ let srv = astsrv:: mk_srv_from_str ( source) ;
97
+ let doc = extract:: from_srv ( srv, "" ) ;
98
+ let doc = run ( srv, doc) ;
99
+ assert doc. topmod . fns [ 0 ] . return == none;
100
+ }
101
+
84
102
fn merge_arg_tys (
85
103
srv : astsrv:: srv ,
86
104
fn_id : doc:: ast_id ,
You can’t perform that action at this time.
0 commit comments