180 | 180 |
pf1, err := Parse(base, data, nil)
|
181 | 181 |
if err != nil {
|
182 | 182 |
switch base {
|
183 | |
case "testdata/replace2.in", "testdata/gopkg.in.golden":
|
|
183 |
case "testdata/block.golden",
|
|
184 |
"testdata/block.in",
|
|
185 |
"testdata/comment.golden",
|
|
186 |
"testdata/comment.in",
|
|
187 |
"testdata/rule1.golden":
|
|
188 |
// ignore
|
|
189 |
default:
|
184 | 190 |
t.Errorf("should parse %v: %v", base, err)
|
185 | 191 |
}
|
186 | 192 |
}
|
|
424 | 430 |
}
|
425 | 431 |
}
|
426 | 432 |
|
427 | |
func TestGoVersion(t *testing.T) {
|
|
433 |
func TestParseVersions(t *testing.T) {
|
428 | 434 |
tests := []struct {
|
429 | 435 |
desc, input string
|
430 | 436 |
ok bool
|
431 | 437 |
laxOK bool // ok=true implies laxOK=true; only set if ok=false
|
432 | 438 |
}{
|
|
439 |
// go lines
|
433 | 440 |
{desc: "empty", input: "module m\ngo \n", ok: false},
|
434 | 441 |
{desc: "one", input: "module m\ngo 1\n", ok: false},
|
435 | 442 |
{desc: "two", input: "module m\ngo 1.22\n", ok: true},
|
|
437 | 444 |
{desc: "before", input: "module m\ngo v1.2\n", ok: false},
|
438 | 445 |
{desc: "after", input: "module m\ngo 1.2rc1\n", ok: true},
|
439 | 446 |
{desc: "space", input: "module m\ngo 1.2 3.4\n", ok: false},
|
440 | |
{desc: "alt1", input: "module m\ngo 1.2.3\n", ok: true, laxOK: true},
|
441 | |
{desc: "alt2", input: "module m\ngo 1.2rc1\n", ok: true, laxOK: true},
|
442 | |
{desc: "alt3", input: "module m\ngo 1.2beta1\n", ok: true, laxOK: true},
|
|
447 |
{desc: "alt1", input: "module m\ngo 1.2.3\n", ok: true},
|
|
448 |
{desc: "alt2", input: "module m\ngo 1.2rc1\n", ok: true},
|
|
449 |
{desc: "alt3", input: "module m\ngo 1.2beta1\n", ok: true},
|
443 | 450 |
{desc: "alt4", input: "module m\ngo 1.2.beta1\n", ok: false, laxOK: true},
|
444 | 451 |
{desc: "alt1", input: "module m\ngo v1.2.3\n", ok: false, laxOK: true},
|
445 | 452 |
{desc: "alt2", input: "module m\ngo v1.2rc1\n", ok: false, laxOK: true},
|
446 | 453 |
{desc: "alt3", input: "module m\ngo v1.2beta1\n", ok: false, laxOK: true},
|
447 | 454 |
{desc: "alt4", input: "module m\ngo v1.2.beta1\n", ok: false, laxOK: true},
|
448 | 455 |
{desc: "alt1", input: "module m\ngo v1.2\n", ok: false, laxOK: true},
|
|
456 |
|
|
457 |
// toolchain lines
|
|
458 |
{desc: "tool", input: "module m\ntoolchain go1.2\n", ok: true},
|
|
459 |
{desc: "tool1", input: "module m\ntoolchain go1.2.3\n", ok: true},
|
|
460 |
{desc: "tool2", input: "module m\ntoolchain go1.2rc1\n", ok: true},
|
|
461 |
{desc: "tool3", input: "module m\ntoolchain gccgo-go1.2rc1\n", ok: true},
|
|
462 |
{desc: "tool4", input: "module m\ntoolchain local\n", ok: true},
|
|
463 |
{desc: "tool5", input: "module m\ntoolchain inconceivable!\n", ok: false, laxOK: true},
|
449 | 464 |
}
|
450 | 465 |
t.Run("Strict", func(t *testing.T) {
|
451 | 466 |
for _, test := range tests {
|
|
461 | 476 |
t.Run("Lax", func(t *testing.T) {
|
462 | 477 |
for _, test := range tests {
|
463 | 478 |
t.Run(test.desc, func(t *testing.T) {
|
464 | |
if _, err := Parse("go.mod", []byte(test.input), nil); err == nil && !(test.ok || test.laxOK) {
|
|
479 |
if _, err := ParseLax("go.mod", []byte(test.input), nil); err == nil && !(test.ok || test.laxOK) {
|
465 | 480 |
t.Error("unexpected success")
|
466 | 481 |
} else if err != nil && test.ok {
|
467 | 482 |
t.Errorf("unexpected error: %v", err)
|