File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ fn run(
22
22
let fold = fold:: fold ( {
23
23
fold_crate: fold_crate,
24
24
fold_mod: fold_mod,
25
- fold_fn: fold_fn
25
+ fold_fn: fold_fn,
26
+ fold_const: fold_const
26
27
with * fold:: default_seq_fold ( srv)
27
28
} ) ;
28
29
fold. fold_crate ( fold, doc)
@@ -208,4 +209,35 @@ fn fold_fn_should_preserve_sig() {
208
209
let fold = fold:: default_seq_fold ( srv) ;
209
210
let doc = fold_fn ( fold, doc. topmod . fns [ 0 ] ) ;
210
211
assert doc. sig == some ( "fn a() -> int" ) ;
211
- }
212
+ }
213
+
214
+ fn fold_const (
215
+ fold : fold:: fold < astsrv:: srv > ,
216
+ doc : doc:: constdoc
217
+ ) -> doc:: constdoc {
218
+ let srv = fold. ctxt ;
219
+ let attrs = astsrv:: exec ( srv) { |ctxt|
220
+ let attrs = alt ctxt. map . get ( doc. id ) {
221
+ ast_map:: node_item ( item) { item. attrs }
222
+ } ;
223
+ attr_parser:: parse_mod ( attrs)
224
+ } ;
225
+
226
+ ~{
227
+ brief: attrs. brief ,
228
+ desc: attrs. desc
229
+ with * doc
230
+ }
231
+ }
232
+
233
+ #[ test]
234
+ fn fold_const_should_extract_docs ( ) {
235
+ let source = "#[doc(brief = \" foo\" , desc = \" bar\" )]\
236
+ const a: bool = true;";
237
+ let srv = astsrv:: mk_srv_from_str ( source) ;
238
+ let doc = extract:: from_srv ( srv, "" ) ;
239
+ let fold = fold:: default_seq_fold ( srv) ;
240
+ let doc = fold_const ( fold, doc. topmod . consts [ 0 ] ) ;
241
+ assert doc. brief == some ( "foo" ) ;
242
+ assert doc. desc == some ( "bar" ) ;
243
+ }
You can’t perform that action at this time.
0 commit comments