@@ -696,6 +696,137 @@ var addGoTests = []struct {
696696 },
697697}
698698
699+ var dropGoTests = []struct {
700+ desc string
701+ in string
702+ out string
703+ }{
704+ {
705+ `module_only` ,
706+ `module m
707+ go 1.14
708+ ` ,
709+ `module m
710+ ` ,
711+ },
712+ {
713+ `module_before_require` ,
714+ `module m
715+ go 1.14
716+ require x.y/a v1.2.3
717+ ` ,
718+ `module m
719+ require x.y/a v1.2.3
720+ ` ,
721+ },
722+ {
723+ `require_before_module` ,
724+ `require x.y/a v1.2.3
725+ module example.com/inverted
726+ go 1.14
727+ ` ,
728+ `require x.y/a v1.2.3
729+ module example.com/inverted
730+ ` ,
731+ },
732+ {
733+ `require_only` ,
734+ `require x.y/a v1.2.3
735+ go 1.14
736+ ` ,
737+ `require x.y/a v1.2.3
738+ ` ,
739+ },
740+ }
741+
742+ var addToolchainTests = []struct {
743+ desc string
744+ in string
745+ version string
746+ out string
747+ }{
748+ {
749+ `empty` ,
750+ `` ,
751+ `go1.17` ,
752+ `toolchain go1.17
753+ ` ,
754+ },
755+ {
756+ `aftergo` ,
757+ `// this is a comment
758+ require x v1.0.0
759+
760+ go 1.17
761+
762+ require y v1.0.0
763+ ` ,
764+ `go1.17` ,
765+ `// this is a comment
766+ require x v1.0.0
767+
768+ go 1.17
769+
770+ toolchain go1.17
771+
772+ require y v1.0.0
773+ ` ,
774+ },
775+ {
776+ `already_have_toolchain` ,
777+ `go 1.17
778+
779+ toolchain go1.18
780+ ` ,
781+ `go1.19` ,
782+ `go 1.17
783+
784+ toolchain go1.19
785+ ` ,
786+ },
787+ }
788+
789+ var dropToolchainTests = []struct {
790+ desc string
791+ in string
792+ out string
793+ }{
794+ {
795+ `empty` ,
796+ `toolchain go1.17
797+ ` ,
798+ `` ,
799+ },
800+ {
801+ `aftergo` ,
802+ `// this is a comment
803+ require x v1.0.0
804+
805+ go 1.17
806+
807+ toolchain go1.17
808+
809+ require y v1.0.0
810+ ` ,
811+ `// this is a comment
812+ require x v1.0.0
813+
814+ go 1.17
815+
816+ require y v1.0.0
817+ ` ,
818+ },
819+ {
820+ `already_have_toolchain` ,
821+ `go 1.17
822+
823+ toolchain go1.18
824+ ` ,
825+ `go 1.17
826+ ` ,
827+ },
828+ }
829+
699830var addExcludeTests = []struct {
700831 desc string
701832 in string
@@ -948,7 +1079,7 @@ var retractRationaleTests = []struct {
9481079 `prefix_one` ,
9491080 `module m
9501081 // prefix
951- retract v1.0.0
1082+ retract v1.0.0
9521083 ` ,
9531084 `prefix` ,
9541085 },
@@ -959,7 +1090,7 @@ var retractRationaleTests = []struct {
9591090 //
9601091 // two
9611092 //
962- // three
1093+ // three
9631094 retract v1.0.0` ,
9641095 `one
9651096
@@ -1083,7 +1214,7 @@ var moduleDeprecatedTests = []struct {
10831214 {
10841215 `deprecated_paragraph_space` ,
10851216 `// Deprecated: the next line has a space
1086- //
1217+ //
10871218 // c
10881219 module m` ,
10891220 "the next line has a space" ,
@@ -1501,6 +1632,38 @@ func TestAddGo(t *testing.T) {
15011632 }
15021633}
15031634
1635+ func TestDropGo (t * testing.T ) {
1636+ for _ , tt := range dropGoTests {
1637+ t .Run (tt .desc , func (t * testing.T ) {
1638+ testEdit (t , tt .in , tt .out , true , func (f * File ) error {
1639+ f .DropGoStmt ()
1640+ return nil
1641+ })
1642+ })
1643+ }
1644+ }
1645+
1646+ func TestAddToolchain (t * testing.T ) {
1647+ for _ , tt := range addToolchainTests {
1648+ t .Run (tt .desc , func (t * testing.T ) {
1649+ testEdit (t , tt .in , tt .out , true , func (f * File ) error {
1650+ return f .AddToolchainStmt (tt .version )
1651+ })
1652+ })
1653+ }
1654+ }
1655+
1656+ func TestDropToolchain (t * testing.T ) {
1657+ for _ , tt := range dropToolchainTests {
1658+ t .Run (tt .desc , func (t * testing.T ) {
1659+ testEdit (t , tt .in , tt .out , true , func (f * File ) error {
1660+ f .DropToolchainStmt ()
1661+ return nil
1662+ })
1663+ })
1664+ }
1665+ }
1666+
15041667func TestAddExclude (t * testing.T ) {
15051668 for _ , tt := range addExcludeTests {
15061669 t .Run (tt .desc , func (t * testing.T ) {
0 commit comments