@@ -181,7 +181,13 @@ func TestPrintParse(t *testing.T) {
181181 pf1 , err := Parse (base , data , nil )
182182 if err != nil {
183183 switch base {
184- case "testdata/replace2.in" , "testdata/gopkg.in.golden" :
184+ case "testdata/block.golden" ,
185+ "testdata/block.in" ,
186+ "testdata/comment.golden" ,
187+ "testdata/comment.in" ,
188+ "testdata/rule1.golden" :
189+ // ignore
190+ default :
185191 t .Errorf ("should parse %v: %v" , base , err )
186192 }
187193 }
@@ -425,28 +431,37 @@ func TestModulePath(t *testing.T) {
425431 }
426432}
427433
428- func TestGoVersion (t * testing.T ) {
434+ func TestParseVersions (t * testing.T ) {
429435 tests := []struct {
430436 desc , input string
431437 ok bool
432438 laxOK bool // ok=true implies laxOK=true; only set if ok=false
433439 }{
440+ // go lines
434441 {desc : "empty" , input : "module m\n go \n " , ok : false },
435442 {desc : "one" , input : "module m\n go 1\n " , ok : false },
436443 {desc : "two" , input : "module m\n go 1.22\n " , ok : true },
437444 {desc : "three" , input : "module m\n go 1.22.333" , ok : true },
438445 {desc : "before" , input : "module m\n go v1.2\n " , ok : false },
439446 {desc : "after" , input : "module m\n go 1.2rc1\n " , ok : true },
440447 {desc : "space" , input : "module m\n go 1.2 3.4\n " , ok : false },
441- {desc : "alt1" , input : "module m\n go 1.2.3\n " , ok : true , laxOK : true },
442- {desc : "alt2" , input : "module m\n go 1.2rc1\n " , ok : true , laxOK : true },
443- {desc : "alt3" , input : "module m\n go 1.2beta1\n " , ok : true , laxOK : true },
448+ {desc : "alt1" , input : "module m\n go 1.2.3\n " , ok : true },
449+ {desc : "alt2" , input : "module m\n go 1.2rc1\n " , ok : true },
450+ {desc : "alt3" , input : "module m\n go 1.2beta1\n " , ok : true },
444451 {desc : "alt4" , input : "module m\n go 1.2.beta1\n " , ok : false , laxOK : true },
445452 {desc : "alt1" , input : "module m\n go v1.2.3\n " , ok : false , laxOK : true },
446453 {desc : "alt2" , input : "module m\n go v1.2rc1\n " , ok : false , laxOK : true },
447454 {desc : "alt3" , input : "module m\n go v1.2beta1\n " , ok : false , laxOK : true },
448455 {desc : "alt4" , input : "module m\n go v1.2.beta1\n " , ok : false , laxOK : true },
449456 {desc : "alt1" , input : "module m\n go v1.2\n " , ok : false , laxOK : true },
457+
458+ // toolchain lines
459+ {desc : "tool" , input : "module m\n toolchain go1.2\n " , ok : true },
460+ {desc : "tool1" , input : "module m\n toolchain go1.2.3\n " , ok : true },
461+ {desc : "tool2" , input : "module m\n toolchain go1.2rc1\n " , ok : true },
462+ {desc : "tool3" , input : "module m\n toolchain gccgo-go1.2rc1\n " , ok : true },
463+ {desc : "tool4" , input : "module m\n toolchain local\n " , ok : true },
464+ {desc : "tool5" , input : "module m\n toolchain inconceivable!\n " , ok : false , laxOK : true },
450465 }
451466 t .Run ("Strict" , func (t * testing.T ) {
452467 for _ , test := range tests {
@@ -462,7 +477,7 @@ func TestGoVersion(t *testing.T) {
462477 t .Run ("Lax" , func (t * testing.T ) {
463478 for _ , test := range tests {
464479 t .Run (test .desc , func (t * testing.T ) {
465- if _ , err := Parse ("go.mod" , []byte (test .input ), nil ); err == nil && ! (test .ok || test .laxOK ) {
480+ if _ , err := ParseLax ("go.mod" , []byte (test .input ), nil ); err == nil && ! (test .ok || test .laxOK ) {
466481 t .Error ("unexpected success" )
467482 } else if err != nil && test .ok {
468483 t .Errorf ("unexpected error: %v" , err )
0 commit comments