@@ -9,8 +9,8 @@ import rustc::syntax::ast;
9
9
import rustc:: front:: attr;
10
10
import core:: tuple;
11
11
12
- export crate_attrs, mod_attrs, fn_attrs, arg_attrs;
13
- export parse_crate, parse_mod, parse_fn;
12
+ export crate_attrs, mod_attrs, fn_attrs, arg_attrs, const_attrs ;
13
+ export parse_crate, parse_mod, parse_fn, parse_const ;
14
14
15
15
type crate_attrs = {
16
16
name : option < str >
@@ -33,6 +33,11 @@ type arg_attrs = {
33
33
desc : str
34
34
} ;
35
35
36
+ type const_attrs = {
37
+ brief : option < str > ,
38
+ desc : option < str >
39
+ } ;
40
+
36
41
fn doc_meta (
37
42
attrs : [ ast:: attribute ]
38
43
) -> option < @ast:: meta_item > {
@@ -276,6 +281,47 @@ fn parse_fn_should_parse_the_argument_descriptions() {
276
281
assert attrs. args [ 1 ] == { name: "b", desc: " arg b"};
277
282
}
278
283
284
+ fn parse_const(attrs: [ast::attribute]) -> const_attrs {
285
+ parse_short_doc_or(
286
+ attrs,
287
+ {|desc|
288
+ {
289
+ brief: none,
290
+ desc: desc
291
+ }
292
+ },
293
+ parse_const_long_doc
294
+ )
295
+ }
296
+
297
+ fn parse_const_long_doc(
298
+ _items: [@ast::meta_item],
299
+ brief: option<str>,
300
+ desc: option<str>
301
+ ) -> const_attrs {
302
+ {
303
+ brief: brief,
304
+ desc: desc
305
+ }
306
+ }
307
+
308
+ #[test]
309
+ fn should_parse_const_short_doc() {
310
+ let source = " #[ doc = \"description\" ] ";
311
+ let attrs = test:: parse_attributes ( source) ;
312
+ let attrs = parse_fn ( attrs) ;
313
+ assert attrs. desc == some ( "description" ) ;
314
+ }
315
+
316
+ #[ test]
317
+ fn should_parse_const_long_doc ( ) {
318
+ let source = "#[doc(brief = \" a\" , desc = \" b\" )]" ;
319
+ let attrs = test:: parse_attributes ( source) ;
320
+ let attrs = parse_fn ( attrs) ;
321
+ assert attrs. brief == some ( "a" ) ;
322
+ assert attrs. desc == some ( "b" ) ;
323
+ }
324
+
279
325
#[ cfg( test) ]
280
326
mod test {
281
327
0 commit comments