go-pathman/envpath/parse_test.go

56 lines
832 B
Go
Raw Permalink Normal View History

2019-07-22 05:21:47 +00:00
package envpath
import (
"fmt"
"strings"
"testing"
)
const file = `# Generated for envman. Do not edit.
PATH="/foo"
# ignore
# ignore
PATH="/foo"
PATH="/foo:$PATH"
PATH="/foo:$PATH"
PATH="/foo:"$PATH"
PATH="/foo:""$PATH"
PATH=""
PATH=
JUNK=""
JUNK=
=""
=
whatever
PATH="/boo:$PATH"
PATH=""
`
func TestParse(t *testing.T) {
2019-07-28 10:04:53 +00:00
exppaths := []string{
`PATH="/foo"`,
`PATH="/foo:$PATH"`,
`PATH=""`,
`PATH="/boo:$PATH"`,
}
2019-07-28 08:32:57 +00:00
newlines, warnings := Parse([]byte(file), "PATH")
2019-07-22 05:21:47 +00:00
newfile := `PATH="` + strings.Join(newlines, "\"\n\tPATH=\"") + `"`
2019-07-28 10:04:53 +00:00
expfile := strings.Join(exppaths, "\n\t")
2019-07-22 05:21:47 +00:00
if newfile != expfile {
t.Errorf("\nExpected:\n\t%s\nGot:\n\t%s", expfile, newfile)
}
for i := range warnings {
w := warnings[i]
fmt.Printf("warning dropping %q from line %d: %s\n", w.Message, w.LineNumber, w.Line)
}
}