| 1 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"reflect" |
| 10 |
"testing" |
| 11 |
) |
| 12 |
|
| 13 |
var buildParserTests = []struct { |
| 14 |
x string |
| 15 |
matched bool |
| 16 |
err error |
| 17 |
}{ |
| 18 |
{"gc", true, nil}, |
| 19 |
{"gccgo", false, nil}, |
| 20 |
{"!gc", false, nil}, |
| 21 |
{"gc && gccgo", false, nil}, |
| 22 |
{"gc || gccgo", true, nil}, |
| 23 |
{"gc || (gccgo && !gccgo)", true, nil}, |
| 24 |
{"gc && (gccgo || !gccgo)", true, nil}, |
| 25 |
{"!(gc && (gccgo || !gccgo))", false, nil}, |
| 26 |
{"gccgo || gc", true, nil}, |
| 27 |
{"!(!(!(gccgo || gc)))", false, nil}, |
| 28 |
{"compiler_bootstrap", false, nil}, |
| 29 |
{"cmd_go_bootstrap", true, nil}, |
| 30 |
{"syntax(error", false, fmt.Errorf("parsing //go:build line: unexpected (")}, |
| 31 |
{"(gc", false, fmt.Errorf("parsing //go:build line: missing )")}, |
| 32 |
{"gc gc", false, fmt.Errorf("parsing //go:build line: unexpected tag")}, |
| 33 |
{"(gc))", false, fmt.Errorf("parsing //go:build line: unexpected )")}, |
| 34 |
} |
| 35 |
|
| 36 |
func TestBuildParser(t *testing.T) { |
| 37 |
for _, tt := range buildParserTests { |
| 38 |
matched, err := matchexpr(tt.x) |
| 39 |
if matched != tt.matched || !reflect.DeepEqual(err, tt.err) { |
| 40 |
t.Errorf("matchexpr(%q) = %v, %v; want %v, %v", tt.x, matched, err, tt.matched, tt.err) |
| 41 |
} |
| 42 |
} |
| 43 |
} |