@@ -601,101 +601,191 @@ func TestCommitLoader_extractCommitFromLine(t *testing.T) {
601601 testName string
602602 line string
603603 showDivergence bool
604- expectedNil bool
604+ expectedCommit * models. Commit
605605 }{
606606 {
607607 testName : "normal commit line with all fields" ,
608608 line :
"0eea75e8c631fba6b58135697835d58ba4c18dbc\x00 1640826609\x00 Jesse Duffield\x00 [email protected] \x00 b21997d6b4cbdf84b149\x00 >\x00 HEAD -> better-tests\x00 better typing for rebase mode" ,
609- showDivergence : true ,
610- expectedNil : false ,
609+ showDivergence : false ,
610+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
611+ Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
612+ Name : "better typing for rebase mode" ,
613+ Tags : nil ,
614+ ExtraInfo : "(HEAD -> better-tests)" ,
615+ UnixTimestamp : 1640826609 ,
616+ AuthorName : "Jesse Duffield" ,
617+ 618+ Parents : []string {"b21997d6b4cbdf84b149" },
619+ Divergence : models .DivergenceNone ,
620+ }),
611621 },
612622 {
613623 testName : "normal commit line with left divergence" ,
614624 line :
"hash123\x00 1234567890\x00 John Doe\x00 [email protected] \x00 parent1 parent2\x00 <\x00 origin/main\x00 commit message" ,
615625 showDivergence : true ,
616- expectedNil : false ,
626+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
627+ Hash : "hash123" ,
628+ Name : "commit message" ,
629+ Tags : nil ,
630+ ExtraInfo : "(origin/main)" ,
631+ UnixTimestamp : 1234567890 ,
632+ AuthorName : "John Doe" ,
633+ 634+ Parents : []string {"parent1" , "parent2" },
635+ Divergence : models .DivergenceLeft ,
636+ }),
617637 },
618638 {
619639 testName : "commit line with tags in extraInfo" ,
620640 line :
"abc123\x00 1640000000\x00 Jane Smith\x00 [email protected] \x00 parenthash\x00 >\x00 tag: v1.0, tag: release\x00 tagged release" ,
621641 showDivergence : true ,
622- expectedNil : false ,
642+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
643+ Hash : "abc123" ,
644+ Name : "tagged release" ,
645+ Tags : []string {"v1.0" , "release" },
646+ ExtraInfo : "(tag: v1.0, tag: release)" ,
647+ UnixTimestamp : 1640000000 ,
648+ AuthorName : "Jane Smith" ,
649+ 650+ Parents : []string {"parenthash" },
651+ Divergence : models .DivergenceRight ,
652+ }),
623653 },
624654 {
625655 testName : "commit line with empty extraInfo" ,
626656 line :
"def456\x00 1640000000\x00 Bob Wilson\x00 [email protected] \x00 parenthash\x00 >\x00 \x00 simple commit" ,
627657 showDivergence : true ,
628- expectedNil : false ,
658+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
659+ Hash : "def456" ,
660+ Name : "simple commit" ,
661+ Tags : nil ,
662+ ExtraInfo : "" ,
663+ UnixTimestamp : 1640000000 ,
664+ AuthorName : "Bob Wilson" ,
665+ 666+ Parents : []string {"parenthash" },
667+ Divergence : models .DivergenceRight ,
668+ }),
629669 },
630670 {
631671 testName : "commit line with no parents (root commit)" ,
632672 line :
"root123\x00 1640000000\x00 Alice Cooper\x00 [email protected] \x00 \x00 >\x00 \x00 initial commit" ,
633673 showDivergence : true ,
634- expectedNil : false ,
674+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
675+ Hash : "root123" ,
676+ Name : "initial commit" ,
677+ Tags : nil ,
678+ ExtraInfo : "" ,
679+ UnixTimestamp : 1640000000 ,
680+ AuthorName : "Alice Cooper" ,
681+ 682+ Parents : nil ,
683+ Divergence : models .DivergenceRight ,
684+ }),
635685 },
636686 {
637687 testName : "malformed line with only 3 fields" ,
638688 line : "hash\x00 timestamp\x00 author" ,
639689 showDivergence : false ,
640- expectedNil : true ,
690+ expectedCommit : nil ,
641691 },
642692 {
643693 testName : "malformed line with only 4 fields" ,
644694 line : "hash\x00 timestamp\x00 author\x00 email" ,
645695 showDivergence : false ,
646- expectedNil : true ,
696+ expectedCommit : nil ,
647697 },
648698 {
649699 testName : "malformed line with only 5 fields" ,
650700 line : "hash\x00 timestamp\x00 author\x00 email\x00 parents" ,
651701 showDivergence : false ,
652- expectedNil : true ,
702+ expectedCommit : nil ,
653703 },
654704 {
655705 testName : "malformed line with only 6 fields" ,
656706 line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 <" ,
657707 showDivergence : true ,
658- expectedNil : true ,
708+ expectedCommit : nil ,
659709 },
660710 {
661711 testName : "minimal valid line with 7 fields (no message)" ,
662712 line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 >\x00 extraInfo" ,
663713 showDivergence : true ,
664- expectedNil : false ,
714+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
715+ Hash : "hash" ,
716+ Name : "" ,
717+ Tags : nil ,
718+ ExtraInfo : "(extraInfo)" ,
719+ UnixTimestamp : 0 ,
720+ AuthorName : "author" ,
721+ AuthorEmail : "email" ,
722+ Parents : []string {"parents" },
723+ Divergence : models .DivergenceRight ,
724+ }),
665725 },
666726 {
667727 testName : "minimal valid line with 7 fields (empty extraInfo)" ,
668728 line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 >\x00 " ,
669729 showDivergence : true ,
670- expectedNil : false ,
730+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
731+ Hash : "hash" ,
732+ Name : "" ,
733+ Tags : nil ,
734+ ExtraInfo : "" ,
735+ UnixTimestamp : 0 ,
736+ AuthorName : "author" ,
737+ AuthorEmail : "email" ,
738+ Parents : []string {"parents" },
739+ Divergence : models .DivergenceRight ,
740+ }),
671741 },
672742 {
673743 testName : "valid line with 8 fields (complete)" ,
674744 line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 <\x00 extraInfo\x00 message" ,
675745 showDivergence : true ,
676- expectedNil : false ,
746+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
747+ Hash : "hash" ,
748+ Name : "message" ,
749+ Tags : nil ,
750+ ExtraInfo : "(extraInfo)" ,
751+ UnixTimestamp : 0 ,
752+ AuthorName : "author" ,
753+ AuthorEmail : "email" ,
754+ Parents : []string {"parents" },
755+ Divergence : models .DivergenceLeft ,
756+ }),
677757 },
678758 {
679759 testName : "empty line" ,
680760 line : "" ,
681761 showDivergence : false ,
682- expectedNil : true ,
762+ expectedCommit : nil ,
683763 },
684764 {
685765 testName : "line with special characters in commit message" ,
686766 line :
"special123\x00 1640000000\x00 Dev User\x00 [email protected] \x00 parenthash\x00 >\x00 \x00 fix: handle \x00 null bytes and 'quotes'" ,
687767 showDivergence : true ,
688- expectedNil : false ,
768+ expectedCommit : models .NewCommit (hashPool , models.NewCommitOpts {
769+ Hash : "special123" ,
770+ Name : "fix: handle \x00 null bytes and 'quotes'" ,
771+ Tags : nil ,
772+ ExtraInfo : "" ,
773+ UnixTimestamp : 1640000000 ,
774+ AuthorName : "Dev User" ,
775+ 776+ Parents : []string {"parenthash" },
777+ Divergence : models .DivergenceRight ,
778+ }),
689779 },
690780 }
691781
692782 for _ , scenario := range scenarios {
693783 t .Run (scenario .testName , func (t * testing.T ) {
694784 result := loader .extractCommitFromLine (hashPool , scenario .line , scenario .showDivergence )
695- if scenario .expectedNil {
785+ if scenario .expectedCommit == nil {
696786 assert .Nil (t , result )
697787 } else {
698- assert .NotNil ( t , result )
788+ assert .Equal ( t , scenario . expectedCommit , result )
699789 }
700790 })
701791 }
0 commit comments