Skip to content

Commit c35320c

Browse files
committed
---
yaml --- r: 13806 b: refs/heads/try c: a25bc19 h: refs/heads/master v: v3
1 parent 08a75e8 commit c35320c

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 87c3a5c1a3e2daee39afb60be83133bf4caf4413
5+
refs/heads/try: a25bc195e25fcce97301b907e2a03501daafb9b9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/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)