@@ -11,12 +11,12 @@ import (
1111
1212var (
1313 _ , b , _ , _ = runtime .Caller (0 )
14- basepath = filepath .Dir (b )
14+ basePath = filepath .Dir (b )
1515)
1616
17- func doMainTest (t * testing.T , from [] string , to [] string , input string , expected string ) {
18- // TODO: Support multiple from-to pairs
19- cmd := exec .Command ("go" , "run" , basepath , from [ 0 ], to [ 0 ] )
17+ func doMainTest (t * testing.T , input string , expected string , mainArgs [] string ) {
18+ execArgs := append ([] string { "run" , basePath }, mainArgs ... )
19+ cmd := exec .Command ("go" , execArgs ... )
2020
2121 cmd .Stdin = strings .NewReader (input )
2222 var out bytes.Buffer
@@ -33,17 +33,54 @@ func doMainTest(t *testing.T, from []string, to []string, input string, expected
3333}
3434
3535func TestSimpleReplaceWithNewlineAtEOF (t * testing.T ) {
36- from := []string {"uss-enterprise.com" }
37- to := []string {"ncc-1701-d.space" }
38- input := "Space, the final frontier!\n Check out: https://uss-enterprise.com/decks/10/sections/forward\n "
36+ mainArgs := []string {
37+ "http://uss-enterprise.com" ,
38+ "https://ncc-1701-d.space" ,
39+ }
40+
41+ input := "Space, the final frontier!\n Check out: http://uss-enterprise.com/decks/10/sections/forward\n "
3942 expected := "Space, the final frontier!\n Check out: https://ncc-1701-d.space/decks/10/sections/forward\n "
40- doMainTest (t , from , to , input , expected )
43+ doMainTest (t , input , expected , mainArgs )
4144}
4245
4346func TestSimpleReplaceWithoutNewlineAtEOF (t * testing.T ) {
44- from := []string {"uss-enterprise.com" }
45- to := []string {"ncc-1701-d.space" }
46- input := "I tend bar, and I listen.\n https://uss-enterprise.com/personnel/guinan"
47+ mainArgs := []string {
48+ "http://uss-enterprise.com" ,
49+ "https://ncc-1701-d.space" ,
50+ }
51+ input := "I tend bar, and I listen.\n http://uss-enterprise.com/personnel/guinan"
4752 expected := "I tend bar, and I listen.\n https://ncc-1701-d.space/personnel/guinan"
48- doMainTest (t , from , to , input , expected )
53+ doMainTest (t , input , expected , mainArgs )
54+ }
55+
56+ func TestMultipleReplaceWithNewlineAtEOF (t * testing.T ) {
57+ mainArgs := []string {
58+ "http://uss-enterprise.com" ,
59+ "https://ncc-1701-d.space" ,
60+
61+ "sections" ,
62+ "areas" ,
63+
64+ "https" ,
65+ "warp" ,
66+ }
67+ input := "Space, the final frontier!\n Check out: http://uss-enterprise.com/decks/10/sections/forward\n "
68+ expected := "Space, the final frontier!\n Check out: warp://ncc-1701-d.space/decks/10/areas/forward\n "
69+ doMainTest (t , input , expected , mainArgs )
4970}
71+
72+ func TestMultipleReplaceWithoutNewlineAtEOF (t * testing.T ) {
73+ mainArgs := []string {
74+ "http://uss-enterprise.com" ,
75+ "https://ncc-1701-d.space" ,
76+
77+ "sections" ,
78+ "areas" ,
79+
80+ "https" ,
81+ "warp" ,
82+ }
83+ input := "Space, the final frontier!\n Check out: http://uss-enterprise.com/decks/10/sections/forward"
84+ expected := "Space, the final frontier!\n Check out: warp://ncc-1701-d.space/decks/10/areas/forward"
85+ doMainTest (t , input , expected , mainArgs )
86+ }
0 commit comments