overdue
This commit is contained in:
45
enc_test.go
Executable file
45
enc_test.go
Executable file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"local/cloudly/capture"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_EncDec(t *testing.T) {
|
||||
os.Setenv("KEY", "123")
|
||||
defer os.Setenv("KEY", "")
|
||||
cases := []struct {
|
||||
in string
|
||||
}{
|
||||
{in: "hello world"},
|
||||
{in: "h"},
|
||||
{in: ""},
|
||||
{in: "hello world my name is charl" + strings.Repeat("i", 100) + "e!"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
encoded := capture.Stdout(func() {
|
||||
capture.Stdin(c.in, func() {
|
||||
if err := Enc(); err != nil {
|
||||
t.Fatalf("cannot encode: %v", err)
|
||||
}
|
||||
})
|
||||
})
|
||||
if encoded == "" || encoded == c.in {
|
||||
t.Errorf("failed to encode (%v): got (%v)", len(c.in), len(encoded))
|
||||
}
|
||||
t.Logf("%v => %v => ?", len(c.in), len(encoded))
|
||||
decoded := capture.Stdout(func() {
|
||||
capture.Stdin(encoded, func() {
|
||||
if err := Dec(); err != nil {
|
||||
t.Fatalf("cannot decode: %v", err)
|
||||
}
|
||||
})
|
||||
})
|
||||
if decoded != c.in {
|
||||
t.Errorf("failed to encode-decode (%v): got (%v)", len(c.in), len(encoded))
|
||||
t.Logf("%q => (%v) => %q", c.in, len(encoded), decoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user