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.
13 type splitTest
struct {
18 var splitTests
= []splitTest
{
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 {"/$DOLLAR/", []string{"/$/"}},
30 {"yacc -o $GOARCH/yacc_$GOFILE", []string{"go", "tool", "yacc", "-o", runtime
.GOARCH
+ "/yacc_proc.go"}},
33 func TestGenerateCommandParse(t
*testing
.T
) {
35 r
: nil, // Unused here.
36 path
: "/usr/ken/sys/proc.go",
40 commands
: make(map[string][]string),
43 g
.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"})
44 for _
, test
:= range splitTests
{
45 // First with newlines.
46 got
:= g
.split("//go:generate " + test
.in
+ "\n")
47 if !reflect
.DeepEqual(got
, test
.out
) {
48 t
.Errorf("split(%q): got %q expected %q", test
.in
, got
, test
.out
)
50 // Then with CRLFs, thank you Windows.
51 got
= g
.split("//go:generate " + test
.in
+ "\r\n")
52 if !reflect
.DeepEqual(got
, test
.out
) {
53 t
.Errorf("split(%q): got %q expected %q", test
.in
, got
, test
.out
)