@@ -606,12 +606,20 @@ pub fn run(mut krate: clean::Crate,
606606}
607607
608608// A short, single-line view of `s`.
609- fn concise_str ( s : & str ) -> String {
609+ fn concise_str ( mut s : & str ) -> String {
610610 if s. contains ( '\n' ) {
611- return format ! ( "{}..." , s. lines( ) . next( ) . expect( "Impossible! We just found a newline" ) ) ;
611+ s = s. lines ( ) . next ( ) . expect ( "Impossible! We just found a newline" ) ;
612612 }
613613 if s. len ( ) > 70 {
614- return format ! ( "{} ... {}" , & s[ ..50 ] , & s[ s. len( ) -20 ..] ) ;
614+ let mut lo = 50 ;
615+ let mut hi = s. len ( ) - 20 ;
616+ while !s. is_char_boundary ( lo) {
617+ lo -= 1 ;
618+ }
619+ while !s. is_char_boundary ( hi) {
620+ hi += 1 ;
621+ }
622+ return format ! ( "{} ... {}" , & s[ ..lo] , & s[ hi..] ) ;
615623 }
616624 s. to_owned ( )
617625}
@@ -660,9 +668,13 @@ fn render_difference(diff: &html_diff::Difference) {
660668 elem. path, elem. element_name, elem_attributes, opposite_elem_attributes) ;
661669 }
662670 html_diff:: Difference :: NodeText { ref elem, ref elem_text, ref opposite_elem_text, .. } => {
663- let ( s1, s2) = concise_compared_strs ( elem_text, opposite_elem_text) ;
664- println ! ( " {} Text differs:\n expected: `{}`\n found: `{}`" ,
665- elem. path, s1, s2) ;
671+ if elem_text. split ( "\n " )
672+ . zip ( opposite_elem_text. split ( "\n " ) )
673+ . any ( |( a, b) | a. trim ( ) != b. trim ( ) ) {
674+ let ( s1, s2) = concise_compared_strs ( elem_text, opposite_elem_text) ;
675+ println ! ( " {} Text differs:\n expected: `{}`\n found: `{}`" ,
676+ elem. path, s1, s2) ;
677+ }
666678 }
667679 html_diff:: Difference :: NotPresent { ref elem, ref opposite_elem } => {
668680 if let Some ( ref elem) = * elem {
@@ -1756,18 +1768,18 @@ fn render_markdown(w: &mut fmt::Formatter,
17561768 // We only emit warnings if the user has opted-in to Pulldown rendering.
17571769 let output = if render_type == RenderType :: Pulldown {
17581770 let pulldown_output = format ! ( "{}" , Markdown ( md_text, RenderType :: Pulldown ) ) ;
1759- let differences = html_diff:: get_differences ( & pulldown_output, & hoedown_output) ;
1760- let differences = differences. into_iter ( )
1761- . filter ( |s| {
1762- match * s {
1763- html_diff:: Difference :: NodeText { ref elem_text,
1764- ref opposite_elem_text,
1765- .. }
1766- if match_non_whitespace ( elem_text, opposite_elem_text) => false ,
1767- _ => true ,
1771+ let mut differences = html_diff:: get_differences ( & pulldown_output, & hoedown_output) ;
1772+ differences. retain ( |s| {
1773+ match * s {
1774+ html_diff:: Difference :: NodeText { ref elem_text,
1775+ ref opposite_elem_text,
1776+ .. }
1777+ if elem_text. split_whitespace ( ) . eq ( opposite_elem_text. split_whitespace ( ) ) => {
1778+ false
17681779 }
1769- } )
1770- . collect :: < Vec < _ > > ( ) ;
1780+ _ => true ,
1781+ }
1782+ } ) ;
17711783
17721784 if !differences. is_empty ( ) {
17731785 scx. markdown_warnings . borrow_mut ( ) . push ( ( span, md_text. to_owned ( ) , differences) ) ;
@@ -1781,40 +1793,6 @@ fn render_markdown(w: &mut fmt::Formatter,
17811793 write ! ( w, "<div class='docblock'>{}{}</div>" , prefix, output)
17821794}
17831795
1784- // Returns true iff s1 and s2 match, ignoring whitespace.
1785- fn match_non_whitespace ( s1 : & str , s2 : & str ) -> bool {
1786- let s1 = s1. trim ( ) ;
1787- let s2 = s2. trim ( ) ;
1788- let mut cs1 = s1. chars ( ) ;
1789- let mut cs2 = s2. chars ( ) ;
1790- while let Some ( c1) = cs1. next ( ) {
1791- if c1. is_whitespace ( ) {
1792- continue ;
1793- }
1794-
1795- loop {
1796- if let Some ( c2) = cs2. next ( ) {
1797- if !c2. is_whitespace ( ) {
1798- if c1 != c2 {
1799- return false ;
1800- }
1801- break ;
1802- }
1803- } else {
1804- return false ;
1805- }
1806- }
1807- }
1808-
1809- while let Some ( c2) = cs2. next ( ) {
1810- if !c2. is_whitespace ( ) {
1811- return false ;
1812- }
1813- }
1814-
1815- true
1816- }
1817-
18181796fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ,
18191797 cx : & Context , prefix : & str ) -> fmt:: Result {
18201798 if let Some ( s) = item. doc_value ( ) {
@@ -3791,35 +3769,3 @@ fn test_name_sorting() {
37913769 sorted. sort_by_key ( |& s| name_key ( s) ) ;
37923770 assert_eq ! ( names, sorted) ;
37933771}
3794-
3795- #[ cfg( test) ]
3796- #[ test]
3797- fn test_match_non_whitespace ( ) {
3798- assert ! ( match_non_whitespace( "" , "" ) ) ;
3799- assert ! ( match_non_whitespace( " " , "" ) ) ;
3800- assert ! ( match_non_whitespace( "" , " " ) ) ;
3801-
3802- assert ! ( match_non_whitespace( "a" , "a" ) ) ;
3803- assert ! ( match_non_whitespace( " a " , "a" ) ) ;
3804- assert ! ( match_non_whitespace( "a" , " a" ) ) ;
3805- assert ! ( match_non_whitespace( "abc" , "abc" ) ) ;
3806- assert ! ( match_non_whitespace( "abc" , " abc " ) ) ;
3807- assert ! ( match_non_whitespace( "abc " , "abc" ) ) ;
3808- assert ! ( match_non_whitespace( "abc xyz" , "abc xyz" ) ) ;
3809- assert ! ( match_non_whitespace( "abc xyz" , "abc\n xyz" ) ) ;
3810- assert ! ( match_non_whitespace( "abc xyz" , "abcxyz" ) ) ;
3811- assert ! ( match_non_whitespace( "abcxyz" , "abc xyz" ) ) ;
3812- assert ! ( match_non_whitespace( "abc xyz " , " abc xyz\n " ) ) ;
3813-
3814- assert ! ( !match_non_whitespace( "a" , "b" ) ) ;
3815- assert ! ( !match_non_whitespace( " a " , "c" ) ) ;
3816- assert ! ( !match_non_whitespace( "a" , " aa" ) ) ;
3817- assert ! ( !match_non_whitespace( "abc" , "ac" ) ) ;
3818- assert ! ( !match_non_whitespace( "abc" , " adc " ) ) ;
3819- assert ! ( !match_non_whitespace( "abc " , "abca" ) ) ;
3820- assert ! ( !match_non_whitespace( "abc xyz" , "abc xy" ) ) ;
3821- assert ! ( !match_non_whitespace( "abc xyz" , "bc\n xyz" ) ) ;
3822- assert ! ( !match_non_whitespace( "abc xyz" , "abc.xyz" ) ) ;
3823- assert ! ( !match_non_whitespace( "abcxyz" , "abc.xyz" ) ) ;
3824- assert ! ( !match_non_whitespace( "abc xyz " , " abc xyz w" ) ) ;
3825- }
0 commit comments