From baef46c4b08c2c74788e2cd8128534069a83a3e4 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Thu, 21 Mar 2019 15:52:32 -0600 Subject: [PATCH] Added tests for Text --- go.mod | 2 ++ go.sum | 2 ++ hatmill_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 go.sum create mode 100644 hatmill_test.go 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) +}