Skip to content

Commit b2f440e

Browse files
committed
---
yaml --- r: 13804 b: refs/heads/try c: 259ea4e h: refs/heads/master v: v3
1 parent 8087f6a commit b2f440e

File tree

2 files changed

+73
-23
lines changed

2 files changed

+73
-23
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: 5166cc29e9fd051845fe68d6c16226b20e0cd105
5+
refs/heads/try: 259ea4e4b49cfe00efdb39e0226211a71807ec76
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustdoc/attr_parser.rs

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ 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;
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;
1414

1515
type crate_attrs = {
1616
name: option<str>
@@ -39,6 +39,40 @@ type const_attrs = {
3939
desc: option<str>
4040
};
4141

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: 0u,
67+
mutable byte_pos: 0u
68+
};
69+
let parser = parser::new_parser_from_source_str(
70+
parse_sess, [], "-", @source);
71+
72+
parser::parse_outer_attributes(parser)
73+
}
74+
}
75+
4276
fn doc_meta(
4377
attrs: [ast::attribute]
4478
) -> option<@ast::meta_item> {
@@ -333,27 +367,43 @@ fn should_parse_const_long_doc() {
333367
assert attrs.desc == some("b");
334368
}
335369

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+
}
338382

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+
}
344393

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: 0u,
352-
mutable byte_pos: 0u
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+
}
356401

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");
359409
}

0 commit comments

Comments
 (0)