@@ -588,3 +588,61 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
588588 })
589589 }
590590}
591+
592+ func TestCommitLoader_extractCommitFromLine (t * testing.T ) {
593+ common := common .NewDummyCommon ()
594+ hashPool := & utils.StringPool {}
595+
596+ loader := & CommitLoader {
597+ Common : common ,
598+ }
599+
600+ scenarios := []struct {
601+ testName string
602+ line string
603+ showDivergence bool
604+ expectedNil bool
605+ }{
606+ {
607+ testName : "normal commit line" ,
608+ line : "0eea75e8c631fba6b58135697835d58ba4c18dbc\x00 1640826609\x00 Jesse Duffield\x00 jessedduffield@gmail.com\x00 HEAD -> better-tests\x00 b21997d6b4cbdf84b149\x00 >\x00 better typing for rebase mode" ,
609+ showDivergence : true ,
610+ expectedNil : false ,
611+ },
612+ {
613+ testName : "malformed line with only 3 fields" ,
614+ line : "hash\x00 timestamp\x00 author" ,
615+ showDivergence : false ,
616+ expectedNil : true ,
617+ },
618+ {
619+ testName : "malformed line with only 4 fields" ,
620+ line : "hash\x00 timestamp\x00 author\x00 email" ,
621+ showDivergence : false ,
622+ expectedNil : true ,
623+ },
624+ {
625+ testName : "minimal valid line with 5 fields" ,
626+ line : "hash\x00 timestamp\x00 author\x00 email\x00 extraInfo" ,
627+ showDivergence : false ,
628+ expectedNil : false ,
629+ },
630+ {
631+ testName : "line missing divergence field when expected" ,
632+ line : "hash\x00 timestamp\x00 author\x00 email\x00 extraInfo\x00 parents" ,
633+ showDivergence : true ,
634+ expectedNil : false ,
635+ },
636+ }
637+
638+ for _ , scenario := range scenarios {
639+ t .Run (scenario .testName , func (t * testing.T ) {
640+ result := loader .extractCommitFromLine (hashPool , scenario .line , scenario .showDivergence )
641+ if scenario .expectedNil {
642+ assert .Nil (t , result )
643+ } else {
644+ assert .NotNil (t , result )
645+ }
646+ })
647+ }
648+ }
0 commit comments