github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/cmd/go/generate_test.go (about)

     1  // Copyright 2011 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  	"reflect"
     9  	"runtime"
    10  	"testing"
    11  )
    12  
    13  type splitTest struct {
    14  	in  string
    15  	out []string
    16  }
    17  
    18  var splitTests = []splitTest{
    19  	{"", nil},
    20  	{"x", []string{"x"}},
    21  	{" a b\tc ", []string{"a", "b", "c"}},
    22  	{` " a " `, []string{" a "}},
    23  	{"$GOARCH", []string{runtime.GOARCH}},
    24  	{"$GOOS", []string{runtime.GOOS}},
    25  	{"$GOFILE", []string{"proc.go"}},
    26  	{"$GOPACKAGE", []string{"sys"}},
    27  	{"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
    28  	{"/$XXNOTDEFINED/", []string{"//"}},
    29  	{"yacc -o $GOARCH/yacc_$GOFILE", []string{"go", "tool", "yacc", "-o", runtime.GOARCH + "/yacc_proc.go"}},
    30  }
    31  
    32  func TestGenerateCommandParse(t *testing.T) {
    33  	g := &Generator{
    34  		r:        nil, // Unused here.
    35  		path:     "/usr/ken/sys/proc.go",
    36  		dir:      "/usr/ken/sys",
    37  		file:     "proc.go",
    38  		pkg:      "sys",
    39  		commands: make(map[string][]string),
    40  	}
    41  	g.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"})
    42  	for _, test := range splitTests {
    43  		got := g.split("//go:generate " + test.in)
    44  		if !reflect.DeepEqual(got, test.out) {
    45  			t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
    46  		}
    47  	}
    48  }