Added some Regexp tests
This commit is contained in:
parent
9c5e8fff0e
commit
c22246b7de
@ -4,6 +4,7 @@ package bytes_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -21,20 +22,43 @@ func Todo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRegexp(t *testing.T) {
|
||||
t.Run("only searches the beginning of input", Todo)
|
||||
t.Run("position is correct after match", Todo)
|
||||
t.Run("fails on unexpected error", Todo)
|
||||
t.Run("returns a useful Got value", rapid.MakeCheck(func(t *rapid.T) {
|
||||
alpha := rapid.SliceOfBytesMatching(`[A-Za-z]{1,100}`)
|
||||
t.Run("position and value are correct after match", rapid.MakeCheck(func(t *rapid.T) {
|
||||
needle := alpha.Draw(t, "needle")
|
||||
input := rapid.Map(alpha, func(suffix []byte) []byte { return append(needle, suffix...) }).
|
||||
Draw(t, "input")
|
||||
|
||||
p := pbytes.Regexp(string(needle))
|
||||
result, err := p(gigaparsec.MakeState(bytes.NewReader(input)))
|
||||
succeeded, val, next := result.Status()
|
||||
|
||||
}))
|
||||
t.Run("basically works", func(t *testing.T) {
|
||||
result, err := pbytes.Regexp("a")(gigaparsec.MakeState(strings.NewReader("a")))
|
||||
must.NoError(t, err)
|
||||
success, value, _ := result.Status()
|
||||
test.True(t, success, test.Sprint(result.Message()))
|
||||
test.EqOp(t, "a", value)
|
||||
test.True(t, result.Consumed())
|
||||
test.True(t, succeeded)
|
||||
test.EqOp(t, string(needle), val)
|
||||
ptest.StateIsAt(t, next, uint64(len(needle)))
|
||||
}))
|
||||
t.Run("only searches the beginning of input", rapid.MakeCheck(func(t *rapid.T) {
|
||||
needle := alpha.Draw(t, "needle")
|
||||
input := rapid.Map(alpha, func(prefix []byte) []byte { return append(prefix, needle...) }).
|
||||
Filter(func(b []byte) bool { return !bytes.HasPrefix(b, needle) }).
|
||||
Draw(t, "input")
|
||||
|
||||
p := pbytes.Regexp(string(needle))
|
||||
result, err := p(gigaparsec.MakeState(bytes.NewReader(input)))
|
||||
succeeded, _, _ := result.Status()
|
||||
|
||||
must.NoError(t, err)
|
||||
test.False(t, succeeded)
|
||||
}))
|
||||
t.Run("fails on unexpected error", func(t *testing.T) {
|
||||
expectedErr := errors.New("it broke")
|
||||
p := pbytes.Regexp("nope")
|
||||
result, err := p(gigaparsec.MakeState(ptest.ErrReaderAt(expectedErr)))
|
||||
succeeded, _, _ := result.Status()
|
||||
test.ErrorIs(t, err, expectedErr)
|
||||
test.False(t, succeeded)
|
||||
})
|
||||
t.Run("returns a useful Got value", Todo)
|
||||
}
|
||||
|
||||
func TestRuneReader(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user