diff --git a/go.mod b/go.mod index eee059b..0274e76 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,3 @@ module gitlab.codemonkeysoftware.com/b/hatmill + +require github.com/leanovate/gopter v0.2.4 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c19f72b --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/leanovate/gopter v0.2.4 h1:U4YLBggDFhJdqQsG4Na2zX7joVTky9vHaj/AGEwSuXU= +github.com/leanovate/gopter v0.2.4/go.mod h1:gNcbPWNEWRe4lm+bycKqxUYoH5uoVje5SkOJ3uoLer8= diff --git a/hatmill_test.go b/hatmill_test.go new file mode 100644 index 0000000..4a0b82e --- /dev/null +++ b/hatmill_test.go @@ -0,0 +1,47 @@ +package hatmill_test + +import ( + "bytes" + "github.com/leanovate/gopter" + "github.com/leanovate/gopter/gen" + "github.com/leanovate/gopter/prop" + "gitlab.codemonkeysoftware.com/b/hatmill" + "testing" +) + +type NopWriter struct{} + +func (NopWriter) Write(p []byte) (n int, err error) { + return len(p), nil +} + +func TestText(t *testing.T) { + properties := gopter.NewProperties(nil) + + properties.Property("writing to string is identity", prop.ForAll( + func(s string) bool { + var buf bytes.Buffer + hatmill.Text(s).WriteTo(&buf) + return buf.String() == s + }, + gen.AnyString(), + )) + + properties.Property("WriteTo returns correct n", prop.ForAll( + func(s string) bool { + n, _ := hatmill.Text(s).WriteTo(NopWriter{}) + return n == int64(len(s)) + }, + gen.AnyString(), + )) + + properties.Property("WriteTo does not generate error", prop.ForAll( + func(s string) bool { + _, err := hatmill.Text(s).WriteTo(NopWriter{}) + return err == nil + }, + gen.AnyString(), + )) + + properties.TestingRun(t) +}