Added tests for Text
This commit is contained in:
parent
22959004c4
commit
baef46c4b0
2
go.mod
2
go.mod
@ -1 +1,3 @@
|
||||
module gitlab.codemonkeysoftware.com/b/hatmill
|
||||
|
||||
require github.com/leanovate/gopter v0.2.4
|
||||
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -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=
|
47
hatmill_test.go
Normal file
47
hatmill_test.go
Normal file
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user