@@ -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, const_attrs;
13
- export parse_crate, parse_mod, parse_fn, parse_const;
12
+ export crate_attrs, mod_attrs, fn_attrs, arg_attrs, const_attrs, enum_attrs ;
13
+ export parse_crate, parse_mod, parse_fn, parse_const, parse_enum ;
14
14
15
15
type crate_attrs = {
16
16
name : option < str >
@@ -39,6 +39,40 @@ type const_attrs = {
39
39
desc : option < str >
40
40
} ;
41
41
42
+ type enum_attrs = {
43
+ brief : option < str > ,
44
+ desc : option < str >
45
+ } ;
46
+
47
+ type variant_attrs = {
48
+ desc : option < str >
49
+ } ;
50
+
51
+ #[ cfg( test) ]
52
+ mod test {
53
+
54
+ fn parse_attributes ( source : str ) -> [ ast:: attribute ] {
55
+ import rustc:: syntax:: parse:: parser;
56
+ // FIXME: Uncommenting this results in rustc bugs
57
+ //import rustc::syntax::codemap;
58
+ import rustc:: driver:: diagnostic;
59
+
60
+ let cm = rustc:: syntax:: codemap:: new_codemap ( ) ;
61
+ let handler = diagnostic:: mk_handler ( none) ;
62
+ let parse_sess = @{
63
+ cm: cm,
64
+ mutable next_id: 0 ,
65
+ span_diagnostic: diagnostic:: mk_span_handler ( handler, cm) ,
66
+ mutable chpos: 0 u,
67
+ mutable byte_pos: 0 u
68
+ } ;
69
+ let parser = parser:: new_parser_from_source_str (
70
+ parse_sess, [ ] , "-" , @source) ;
71
+
72
+ parser:: parse_outer_attributes ( parser)
73
+ }
74
+ }
75
+
42
76
fn doc_meta (
43
77
attrs : [ ast:: attribute ]
44
78
) -> option < @ast:: meta_item > {
@@ -333,27 +367,43 @@ fn should_parse_const_long_doc() {
333
367
assert attrs. desc == some ( "b" ) ;
334
368
}
335
369
336
- #[ cfg( test) ]
337
- mod test {
370
+ fn parse_enum ( attrs : [ ast:: attribute ] ) -> enum_attrs {
371
+ parse_short_doc_or (
372
+ attrs,
373
+ { |desc|
374
+ {
375
+ brief: none,
376
+ desc: desc
377
+ }
378
+ } ,
379
+ parse_enum_long_doc
380
+ )
381
+ }
338
382
339
- fn parse_attributes ( source : str ) -> [ ast:: attribute ] {
340
- import rustc:: syntax:: parse:: parser;
341
- // FIXME: Uncommenting this results in rustc bugs
342
- //import rustc::syntax::codemap;
343
- import rustc:: driver:: diagnostic;
383
+ fn parse_enum_long_doc (
384
+ _items : [ @ast:: meta_item ] ,
385
+ brief : option < str > ,
386
+ desc : option < str >
387
+ ) -> enum_attrs {
388
+ {
389
+ brief: brief,
390
+ desc: desc
391
+ }
392
+ }
344
393
345
- let cm = rustc:: syntax:: codemap:: new_codemap ( ) ;
346
- let handler = diagnostic:: mk_handler ( none) ;
347
- let parse_sess = @{
348
- cm: cm,
349
- mutable next_id: 0 ,
350
- span_diagnostic: diagnostic:: mk_span_handler ( handler, cm) ,
351
- mutable chpos: 0 u,
352
- mutable byte_pos: 0 u
353
- } ;
354
- let parser = parser:: new_parser_from_source_str (
355
- parse_sess, [ ] , "-" , @source) ;
394
+ #[ test]
395
+ fn should_parse_enum_short_doc ( ) {
396
+ let source = "#[doc = \" description\" ]" ;
397
+ let attrs = test:: parse_attributes ( source) ;
398
+ let attrs = parse_enum ( attrs) ;
399
+ assert attrs. desc == some ( "description" ) ;
400
+ }
356
401
357
- parser:: parse_outer_attributes ( parser)
358
- }
402
+ #[ test]
403
+ fn should_parse_enum_long_doc ( ) {
404
+ let source = "#[doc(brief = \" a\" , desc = \" b\" )]" ;
405
+ let attrs = test:: parse_attributes ( source) ;
406
+ let attrs = parse_enum ( attrs) ;
407
+ assert attrs. brief == some ( "a" ) ;
408
+ assert attrs. desc == some ( "b" ) ;
359
409
}
0 commit comments