about summary refs log tree commit diff
path: root/src/rustdoc/attr_parser.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-25 17:31:50 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-25 21:04:52 -0800
commit259ea4e4b49cfe00efdb39e0226211a71807ec76 (patch)
treeee87bbc1e24b98b3d0f277f7c7b8711b5d68efe1 /src/rustdoc/attr_parser.rs
parent5166cc29e9fd051845fe68d6c16226b20e0cd105 (diff)
downloadrust-259ea4e4b49cfe00efdb39e0226211a71807ec76.tar.gz
rust-259ea4e4b49cfe00efdb39e0226211a71807ec76.zip
rustdoc: Parse enum doc attributes
Diffstat (limited to 'src/rustdoc/attr_parser.rs')
-rw-r--r--src/rustdoc/attr_parser.rs94
1 files changed, 72 insertions, 22 deletions
diff --git a/src/rustdoc/attr_parser.rs b/src/rustdoc/attr_parser.rs
index f97a88c8837..52fdb40d395 100644
--- a/src/rustdoc/attr_parser.rs
+++ b/src/rustdoc/attr_parser.rs
@@ -9,8 +9,8 @@ import rustc::syntax::ast;
 import rustc::front::attr;
 import core::tuple;
 
-export crate_attrs, mod_attrs, fn_attrs, arg_attrs, const_attrs;
-export parse_crate, parse_mod, parse_fn, parse_const;
+export crate_attrs, mod_attrs, fn_attrs, arg_attrs, const_attrs, enum_attrs;
+export parse_crate, parse_mod, parse_fn, parse_const, parse_enum;
 
 type crate_attrs = {
     name: option<str>
@@ -39,6 +39,40 @@ type const_attrs = {
     desc: option<str>
 };
 
+type enum_attrs = {
+    brief: option<str>,
+    desc: option<str>
+};
+
+type variant_attrs = {
+    desc: option<str>
+};
+
+#[cfg(test)]
+mod test {
+
+    fn parse_attributes(source: str) -> [ast::attribute] {
+        import rustc::syntax::parse::parser;
+        // FIXME: Uncommenting this results in rustc bugs
+        //import rustc::syntax::codemap;
+        import rustc::driver::diagnostic;
+
+        let cm = rustc::syntax::codemap::new_codemap();
+        let handler = diagnostic::mk_handler(none);
+        let parse_sess = @{
+            cm: cm,
+            mutable next_id: 0,
+            span_diagnostic: diagnostic::mk_span_handler(handler, cm),
+            mutable chpos: 0u,
+            mutable byte_pos: 0u
+        };
+        let parser = parser::new_parser_from_source_str(
+            parse_sess, [], "-", @source);
+
+        parser::parse_outer_attributes(parser)
+    }
+}
+
 fn doc_meta(
     attrs: [ast::attribute]
 ) -> option<@ast::meta_item> {
@@ -333,27 +367,43 @@ fn should_parse_const_long_doc() {
     assert attrs.desc == some("b");
 }
 
-#[cfg(test)]
-mod test {
+fn parse_enum(attrs: [ast::attribute]) -> enum_attrs {
+    parse_short_doc_or(
+        attrs,
+        {|desc|
+            {
+                brief: none,
+                desc: desc
+            }
+        },
+        parse_enum_long_doc
+    )
+}
 
-    fn parse_attributes(source: str) -> [ast::attribute] {
-        import rustc::syntax::parse::parser;
-        // FIXME: Uncommenting this results in rustc bugs
-        //import rustc::syntax::codemap;
-        import rustc::driver::diagnostic;
+fn parse_enum_long_doc(
+    _items: [@ast::meta_item],
+    brief: option<str>,
+    desc: option<str>
+) -> enum_attrs {
+    {
+        brief: brief,
+        desc: desc
+    }
+}
 
-        let cm = rustc::syntax::codemap::new_codemap();
-        let handler = diagnostic::mk_handler(none);
-        let parse_sess = @{
-            cm: cm,
-            mutable next_id: 0,
-            span_diagnostic: diagnostic::mk_span_handler(handler, cm),
-            mutable chpos: 0u,
-            mutable byte_pos: 0u
-        };
-        let parser = parser::new_parser_from_source_str(
-            parse_sess, [], "-", @source);
+#[test]
+fn should_parse_enum_short_doc() {
+    let source = "#[doc = \"description\"]";
+    let attrs = test::parse_attributes(source);
+    let attrs = parse_enum(attrs);
+    assert attrs.desc == some("description");
+}
 
-        parser::parse_outer_attributes(parser)
-    }
+#[test]
+fn should_parse_enum_long_doc() {
+    let source = "#[doc(brief = \"a\", desc = \"b\")]";
+    let attrs = test::parse_attributes(source);
+    let attrs = parse_enum(attrs);
+    assert attrs.brief == some("a");
+    assert attrs.desc == some("b");
 }