Skip to content

Commit a25bc19

Browse files
committed
rustdoc: Parse variant doc attributes
1 parent 87c3a5c commit a25bc19

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/rustdoc/attr_parser.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import rustc::syntax::ast;
99
import rustc::front::attr;
1010
import core::tuple;
1111

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;
12+
export crate_attrs, mod_attrs, fn_attrs, arg_attrs,
13+
const_attrs, enum_attrs, variant_attrs;
14+
export parse_crate, parse_mod, parse_fn, parse_const,
15+
parse_enum, parse_variant;
1416

1517
type crate_attrs = {
1618
name: option<str>
@@ -370,3 +372,48 @@ fn should_parse_enum_long_doc() {
370372
assert attrs.brief == some("a");
371373
assert attrs.desc == some("b");
372374
}
375+
376+
fn parse_variant(attrs: [ast::attribute]) -> variant_attrs {
377+
parse_short_doc_or(
378+
attrs,
379+
{|desc|
380+
{
381+
desc: desc
382+
}
383+
},
384+
{|_items, brief, desc|
385+
if option::is_some(brief) && option::is_some(desc) {
386+
// FIXME: Warn about dropping brief description
387+
}
388+
389+
{
390+
// Prefer desc over brief
391+
desc: option::maybe(brief, desc, {|s| some(s) })
392+
}
393+
}
394+
)
395+
}
396+
397+
#[test]
398+
fn should_parse_variant_short_doc() {
399+
let source = "#[doc = \"a\"]";
400+
let attrs = test::parse_attributes(source);
401+
let attrs = parse_variant(attrs);
402+
assert attrs.desc == some("a");
403+
}
404+
405+
#[test]
406+
fn should_parse_variant_brief_doc() {
407+
let source = "#[doc(brief = \"a\")]";
408+
let attrs = test::parse_attributes(source);
409+
let attrs = parse_variant(attrs);
410+
assert attrs.desc == some("a");
411+
}
412+
413+
#[test]
414+
fn should_parse_variant_long_doc() {
415+
let source = "#[doc(desc = \"a\")]";
416+
let attrs = test::parse_attributes(source);
417+
let attrs = parse_variant(attrs);
418+
assert attrs.desc == some("a");
419+
}

0 commit comments

Comments
 (0)