File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed
Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -351,7 +351,42 @@ fn select_discussion_comment(
351351 return Ok ( selected) ;
352352 }
353353
354- Ok ( comments[ 0 ] . clone ( ) )
354+ comments
355+ . first ( )
356+ . cloned ( )
357+ . ok_or_else ( || anyhow:: anyhow!( "No comments available" ) )
358+ }
359+
360+ #[ cfg( test) ]
361+ mod tests {
362+ use super :: * ;
363+
364+ #[ test]
365+ fn test_select_discussion_comment_empty_comments ( ) {
366+ // Should return an error, not panic
367+ let result = select_discussion_comment ( & [ ] , None , None ) ;
368+ assert ! ( result. is_err( ) ) ;
369+ }
370+
371+ #[ test]
372+ fn test_select_discussion_comment_defaults_to_first ( ) {
373+ let comment = core:: Comment {
374+ id : "cmt_1" . to_string ( ) ,
375+ file_path : PathBuf :: from ( "test.rs" ) ,
376+ line_number : 1 ,
377+ content : "test" . to_string ( ) ,
378+ rule_id : None ,
379+ severity : core:: comment:: Severity :: Info ,
380+ category : core:: comment:: Category :: BestPractice ,
381+ suggestion : None ,
382+ confidence : 0.8 ,
383+ code_suggestion : None ,
384+ tags : vec ! [ ] ,
385+ fix_effort : core:: comment:: FixEffort :: Low ,
386+ } ;
387+ let result = select_discussion_comment ( & [ comment. clone ( ) ] , None , None ) . unwrap ( ) ;
388+ assert_eq ! ( result. id, "cmt_1" ) ;
389+ }
355390}
356391
357392fn load_discussion_thread ( path : Option < & std:: path:: Path > , comment_id : & str ) -> DiscussionThread {
You can’t perform that action at this time.
0 commit comments