hatmill/hatmill_test.go

48 lines
992 B
Go

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)
}