1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
package shell
import (
"os/exec"
"testing"
)
func TestEncode(t *testing.T) {
_, err := exec.LookPath("sh")
if err != nil {
t.Skip("not found sh")
}
for _, s := range []string{
"hello world",
"hello$world",
"hello\t\r\nworld",
"中文 english",
"`~!#$&*()|\\;'\"<>? ",
} {
r := Encode(s)
t.Log(r)
cmd := exec.Command("sh", "-c", "echo -n "+r)
output, err := cmd.Output()
if err != nil {
t.Fatal(err)
}
if s != string(output) {
t.Errorf("%q != %q", s, string(output))
}
}
}
|