@@ -207,6 +207,29 @@ func TestNewCmdBrowse(t *testing.T) {
207207 cli : "de07febc26e19000f8c9e821207f3bc34a3c8038 --commit=12a4" ,
208208 wantsErr : true ,
209209 },
210+ {
211+ name : "blame flag" ,
212+ cli : "main.go --blame" ,
213+ wants : BrowseOptions {
214+ BlameFlag : true ,
215+ SelectorArg : "main.go" ,
216+ },
217+ wantsErr : false ,
218+ },
219+ {
220+ name : "blame flag without file argument" ,
221+ cli : "--blame" ,
222+ wantsErr : true ,
223+ },
224+ {
225+ name : "blame flag with line number" ,
226+ cli : "main.go:312 --blame" ,
227+ wants : BrowseOptions {
228+ BlameFlag : true ,
229+ SelectorArg : "main.go:312" ,
230+ },
231+ wantsErr : false ,
232+ },
210233 }
211234 for _ , tt := range tests {
212235 t .Run (tt .name , func (t * testing.T ) {
@@ -239,6 +262,7 @@ func TestNewCmdBrowse(t *testing.T) {
239262 assert .Equal (t , tt .wants .SettingsFlag , opts .SettingsFlag )
240263 assert .Equal (t , tt .wants .ActionsFlag , opts .ActionsFlag )
241264 assert .Equal (t , tt .wants .Commit , opts .Commit )
265+ assert .Equal (t , tt .wants .BlameFlag , opts .BlameFlag )
242266 })
243267 }
244268}
@@ -595,6 +619,61 @@ func Test_runBrowse(t *testing.T) {
595619 expectedURL : "https://github.com/bchadwic/test/tree/trunk/77507cd94ccafcf568f8560cfecde965fcfa63e7.txt" ,
596620 wantsErr : false ,
597621 },
622+ {
623+ name : "file with blame flag" ,
624+ opts : BrowseOptions {
625+ SelectorArg : "path/to/file.txt" ,
626+ BlameFlag : true ,
627+ },
628+ baseRepo : ghrepo .New ("owner" , "repo" ),
629+ defaultBranch : "main" ,
630+ expectedURL : "https://github.com/owner/repo/blame/main/path/to/file.txt" ,
631+ wantsErr : false ,
632+ },
633+ {
634+ name : "file with blame flag and line number" ,
635+ opts : BrowseOptions {
636+ SelectorArg : "path/to/file.txt:42" ,
637+ BlameFlag : true ,
638+ },
639+ baseRepo : ghrepo .New ("owner" , "repo" ),
640+ defaultBranch : "main" ,
641+ expectedURL : "https://github.com/owner/repo/blame/main/path/to/file.txt#L42" ,
642+ wantsErr : false ,
643+ },
644+ {
645+ name : "file with blame flag and line range" ,
646+ opts : BrowseOptions {
647+ SelectorArg : "path/to/file.txt:10-20" ,
648+ BlameFlag : true ,
649+ },
650+ baseRepo : ghrepo .New ("owner" , "repo" ),
651+ defaultBranch : "main" ,
652+ expectedURL : "https://github.com/owner/repo/blame/main/path/to/file.txt#L10-L20" ,
653+ wantsErr : false ,
654+ },
655+ {
656+ name : "file with blame flag and branch" ,
657+ opts : BrowseOptions {
658+ SelectorArg : "main.go:100" ,
659+ BlameFlag : true ,
660+ Branch : "feature-branch" ,
661+ },
662+ baseRepo : ghrepo .New ("owner" , "repo" ),
663+ expectedURL : "https://github.com/owner/repo/blame/feature-branch/main.go#L100" ,
664+ wantsErr : false ,
665+ },
666+ {
667+ name : "file with blame flag and commit" ,
668+ opts : BrowseOptions {
669+ SelectorArg : "src/app.js:50" ,
670+ BlameFlag : true ,
671+ Commit : "abc123" ,
672+ },
673+ baseRepo : ghrepo .New ("owner" , "repo" ),
674+ expectedURL : "https://github.com/owner/repo/blame/abc123/src/app.js#L50" ,
675+ wantsErr : false ,
676+ },
598677 }
599678
600679 for _ , tt := range tests {
0 commit comments