@@ -304,7 +304,7 @@ impl GoSumEditor {
304304 . strip_prefix ( module)
305305 . is_some_and ( |rest| rest. starts_with ( char:: is_whitespace) )
306306 } )
307- . flat_map ( go_sum_lines )
307+ . filter_map ( parse_go_sum_line )
308308 . filter_map ( |l| l. zip_version_of ( module) . map ( str:: to_string) )
309309 . collect ( )
310310 }
@@ -397,20 +397,24 @@ impl<'a> GoSumLine<'a> {
397397/// lines are skipped. Each caller keeps its own token rule
398398/// ([`GoSumLine::extra_tokens`]) and hash filter.
399399pub ( crate ) fn go_sum_lines ( text : & str ) -> impl Iterator < Item = GoSumLine < ' _ > > {
400- text. lines ( ) . filter_map ( |line| {
401- let mut tokens = line. split_whitespace ( ) ;
402- let ( module, version, hash) = ( tokens. next ( ) ?, tokens. next ( ) ?, tokens. next ( ) ?) ;
403- let ( version, go_mod) = match version. strip_suffix ( "/go.mod" ) {
404- Some ( version) => ( version, true ) ,
405- None => ( version, false ) ,
406- } ;
407- Some ( GoSumLine {
408- module,
409- version,
410- go_mod,
411- hash,
412- extra_tokens : tokens. next ( ) . is_some ( ) ,
413- } )
400+ text. lines ( ) . filter_map ( parse_go_sum_line)
401+ }
402+
403+ /// One line of [`go_sum_lines`], or `None` when it has fewer than three
404+ /// tokens.
405+ fn parse_go_sum_line ( line : & str ) -> Option < GoSumLine < ' _ > > {
406+ let mut tokens = line. split_whitespace ( ) ;
407+ let ( module, version, hash) = ( tokens. next ( ) ?, tokens. next ( ) ?, tokens. next ( ) ?) ;
408+ let ( version, go_mod) = match version. strip_suffix ( "/go.mod" ) {
409+ Some ( version) => ( version, true ) ,
410+ None => ( version, false ) ,
411+ } ;
412+ Some ( GoSumLine {
413+ module,
414+ version,
415+ go_mod,
416+ hash,
417+ extra_tokens : tokens. next ( ) . is_some ( ) ,
414418 } )
415419}
416420
@@ -859,12 +863,20 @@ mod tests {
859863 // line (#1424): compare against `go_sum_lines` over odd spacing.
860864 let content =
861865 "m v1 h1:a\n m v2 h\n \u{a0} m v3 h\n m\u{a0} v4 h\n mm v5 h\n m v6/go.mod h\n m\t v7\t h\n " ;
862- let editor = GoSumEditor :: new ( content. to_string ( ) ) ;
866+ let text = GoSumEditor :: new ( content. to_string ( ) ) ;
867+ // An edit leaves the editor holding split lines; ask both forms.
868+ let mut lines = GoSumEditor :: new ( content. to_string ( ) ) ;
869+ assert ! ( lines. upsert_module_lines( MOD , VER , ZIP_H1 , GOMOD_H1 ) ) ;
863870 for module in [ "m" , "mm" , "m\u{a0} v4" , "" ] {
864871 let reference: Vec < String > = go_sum_lines ( content)
865872 . filter_map ( |l| l. zip_version_of ( module) . map ( str:: to_string) )
866873 . collect ( ) ;
867- assert_eq ! ( editor. zip_versions( module) , reference, "module {module:?}" ) ;
874+ assert_eq ! ( text. zip_versions( module) , reference, "module {module:?}" ) ;
875+ assert_eq ! (
876+ lines. zip_versions( module) ,
877+ reference,
878+ "lines, module {module:?}"
879+ ) ;
868880 }
869881 }
870882}
0 commit comments