Add Map version `ProcessWords`
Signed-off-by: Yuichiro Kaneko <spiketeika@gmail.com>docker-18.09
parent
97b3652136
commit
75118c8a82
|
@ -51,6 +51,11 @@ func (s *Lex) ProcessWordWithMap(word string, env map[string]string) (string, er
|
|||
return word, err
|
||||
}
|
||||
|
||||
func (s *Lex) ProcessWordsWithMap(word string, env map[string]string) ([]string, error) {
|
||||
_, words, err := s.process(word, env)
|
||||
return words, err
|
||||
}
|
||||
|
||||
func (s *Lex) process(word string, env map[string]string) (string, []string, error) {
|
||||
sw := &shellWord{
|
||||
envs: env,
|
||||
|
|
|
@ -103,6 +103,7 @@ func TestShellParser4Words(t *testing.T) {
|
|||
test := strings.TrimSpace(words[0])
|
||||
expected := strings.Split(strings.TrimLeft(words[1], " "), ",")
|
||||
|
||||
// test for ProcessWords
|
||||
result, err := shlex.ProcessWords(test, envs)
|
||||
|
||||
if err != nil {
|
||||
|
@ -117,6 +118,22 @@ func TestShellParser4Words(t *testing.T) {
|
|||
t.Fatalf("Error on line %d. %q was suppose to result in %q, but got %q instead", lineNum, test, expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
// test for ProcessWordsWithMap
|
||||
result, err = shlex.ProcessWordsWithMap(test, buildEnvs(envs))
|
||||
|
||||
if err != nil {
|
||||
result = []string{"error"}
|
||||
}
|
||||
|
||||
if len(result) != len(expected) {
|
||||
t.Fatalf("Error on line %d. %q was suppose to result in %q, but got %q instead", lineNum, test, expected, result)
|
||||
}
|
||||
for i, w := range expected {
|
||||
if w != result[i] {
|
||||
t.Fatalf("Error on line %d. %q was suppose to result in %q, but got %q instead", lineNum, test, expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue