2024-09-10 22:50:14 +00:00
|
|
|
package bytes_test
|
|
|
|
|
2024-09-18 02:48:38 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.codemonkeysoftware.net/b/gigaparsec"
|
|
|
|
"git.codemonkeysoftware.net/b/gigaparsec/bytes"
|
|
|
|
"git.codemonkeysoftware.net/b/gigaparsec/cursor"
|
|
|
|
"github.com/shoenig/test"
|
|
|
|
"github.com/shoenig/test/must"
|
|
|
|
"pgregory.net/rapid"
|
|
|
|
)
|
2024-09-10 22:50:14 +00:00
|
|
|
|
|
|
|
func Todo(t *testing.T) {
|
|
|
|
t.Fatalf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegexp(t *testing.T) {
|
2024-09-11 00:45:08 +00:00
|
|
|
t.Run("only searches the beginning of input", Todo)
|
|
|
|
t.Run("position is correct after match", Todo)
|
|
|
|
t.Run("fails on unexpected error", Todo)
|
2024-09-18 02:48:38 +00:00
|
|
|
t.Run("returns a useful Got value", rapid.MakeCheck(func(t *rapid.T) {
|
|
|
|
|
|
|
|
}))
|
|
|
|
t.Run("basically works", func(t *testing.T) {
|
|
|
|
result, err := bytes.Regexp("a")(gigaparsec.MakeState(cursor.NewSlice([]byte("a"))))
|
|
|
|
must.NoError(t, err)
|
|
|
|
failed, _, msg := result.Failed()
|
|
|
|
must.False(t, failed, must.Sprint(msg))
|
|
|
|
succeeded, consumed, value, _, _ := result.Succeeded()
|
|
|
|
test.True(t, succeeded)
|
|
|
|
test.True(t, consumed)
|
|
|
|
test.EqOp(t, "a", value)
|
|
|
|
})
|
2024-09-10 22:50:14 +00:00
|
|
|
}
|
2024-09-10 22:52:08 +00:00
|
|
|
|
|
|
|
func TestRuneReader(t *testing.T) {
|
2024-09-18 02:48:38 +00:00
|
|
|
var s = []byte("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
rr := bytes.NewRuneReader(cursor.NewSlice(s))
|
|
|
|
for i, b := range s {
|
|
|
|
r, n, err := rr.ReadRune()
|
|
|
|
test.NoError(t, err)
|
|
|
|
test.EqOp(t, 1, n)
|
|
|
|
test.EqOp(t, r, rune(b))
|
|
|
|
if t.Failed() {
|
|
|
|
t.Fatalf("failed at %d", i)
|
|
|
|
}
|
|
|
|
}
|
2024-09-10 22:52:08 +00:00
|
|
|
}
|