@@ -138,7 +138,7 @@ fn write_mod_contents(
138
138
doc:: enumtag ( enumdoc) { write_enum ( ctxt, enumdoc) }
139
139
doc:: restag ( resdoc) { write_res ( ctxt, resdoc) }
140
140
doc:: ifacetag ( ifacedoc) { write_iface ( ctxt, ifacedoc) }
141
- doc:: impltag ( impldoc) { fail }
141
+ doc:: impltag ( impldoc) { write_impl ( ctxt , impldoc ) }
142
142
}
143
143
}
144
144
}
@@ -648,6 +648,101 @@ fn should_write_iface_method_failure_conditions() {
648
648
assert str:: contains ( markdown, "Failure conditions: nuked" ) ;
649
649
}
650
650
651
+ fn write_impl ( ctxt : ctxt , doc : doc:: impldoc ) {
652
+ assert option:: is_some ( doc. self_ty ) ;
653
+ let self_ty = option:: get ( doc. self_ty ) ;
654
+ alt doc. iface_ty {
655
+ some ( iface_ty) {
656
+ write_header ( ctxt, h2,
657
+ #fmt ( "Implementation `%s` of `%s` for `%s`" ,
658
+ doc. name , iface_ty, self_ty) ) ;
659
+ }
660
+ none {
661
+ write_header( ctxt, h2,
662
+ #fmt ( "Implementation `%s` for `%s`" ,
663
+ doc. name , self_ty) ) ;
664
+ }
665
+ }
666
+ write_brief ( ctxt, doc. brief ) ;
667
+ write_desc ( ctxt, doc. desc ) ;
668
+ write_methods ( ctxt, doc. methods ) ;
669
+ }
670
+
671
+ #[ test]
672
+ fn should_write_impl_header ( ) {
673
+ let markdown = test:: render ( "impl i for int { fn a() { } }" ) ;
674
+ assert str:: contains ( markdown, "## Implementation `i` for `int`" ) ;
675
+ }
676
+
677
+ #[ test]
678
+ fn should_write_impl_header_with_iface ( ) {
679
+ let markdown = test:: render ( "impl i of j for int { fn a() { } }" ) ;
680
+ assert str:: contains ( markdown, "## Implementation `i` of `j` for `int`" ) ;
681
+ }
682
+
683
+ #[ test]
684
+ fn should_write_impl_brief ( ) {
685
+ let markdown = test:: render (
686
+ "#[doc(brief = \" brief\" )] impl i for int { fn a() { } }" ) ;
687
+ assert str:: contains ( markdown, "brief" ) ;
688
+ }
689
+
690
+ #[ test]
691
+ fn should_write_impl_desc ( ) {
692
+ let markdown = test:: render (
693
+ "#[doc(desc = \" desc\" )] impl i for int { fn a() { } }" ) ;
694
+ assert str:: contains ( markdown, "desc" ) ;
695
+ }
696
+
697
+ #[ test]
698
+ fn should_write_impl_method_header ( ) {
699
+ let markdown = test:: render (
700
+ "impl i for int { fn a() { } }" ) ;
701
+ assert str:: contains ( markdown, "### Method `a`" ) ;
702
+ }
703
+
704
+ #[ test]
705
+ fn should_write_impl_method_signature ( ) {
706
+ let markdown = test:: render (
707
+ "impl i for int { fn a() { } }" ) ;
708
+ assert str:: contains ( markdown, "\n fn a()" ) ;
709
+ }
710
+
711
+ #[ test]
712
+ fn should_write_impl_method_argument_header ( ) {
713
+ let markdown = test:: render (
714
+ "impl a for int { fn a(b: int) { } }" ) ;
715
+ assert str:: contains ( markdown, "\n \n Arguments:\n \n " ) ;
716
+ }
717
+
718
+ #[ test]
719
+ fn should_write_impl_method_arguments ( ) {
720
+ let markdown = test:: render (
721
+ "impl a for int { fn a(b: int) { } }" ) ;
722
+ assert str:: contains ( markdown, "* `b`: `int`\n " ) ;
723
+ }
724
+
725
+ #[ test]
726
+ fn should_not_write_impl_method_arguments_if_none ( ) {
727
+ let markdown = test:: render (
728
+ "impl a for int { fn a() { } }" ) ;
729
+ assert !str:: contains ( markdown, "Arguments" ) ;
730
+ }
731
+
732
+ #[ test]
733
+ fn should_write_impl_method_return_info ( ) {
734
+ let markdown = test:: render (
735
+ "impl a for int { fn a() -> int { } }" ) ;
736
+ assert str:: contains ( markdown, "Returns `int`" ) ;
737
+ }
738
+
739
+ #[ test]
740
+ fn should_write_impl_method_failure_conditions ( ) {
741
+ let markdown = test:: render (
742
+ "impl a for int { #[doc(failure = \" nuked\" )] fn a() { } }" ) ;
743
+ assert str:: contains ( markdown, "Failure conditions: nuked" ) ;
744
+ }
745
+
651
746
#[ cfg( test) ]
652
747
mod test {
653
748
fn render ( source : str ) -> str {
0 commit comments