diff --git a/dbg/BUILD.bazel b/dbg/BUILD.bazel index c55279b..113b53e 100644 --- a/dbg/BUILD.bazel +++ b/dbg/BUILD.bazel @@ -9,11 +9,11 @@ go_library( go_test( name = "dbg_test", + size = "small", srcs = ["dbg_test.go"], embed = [":dbg"], deps = [ "//testio", "@com_github_stretchr_testify//require", ], - size = "small", ) diff --git a/lib/BUILD.bazel b/lib/BUILD.bazel index 1ce1a39..3497e70 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -110,8 +110,8 @@ go_library( go_test( name = "lib_test", + size = "small", srcs = ["lib_test.go"], embed = [":lib"], deps = ["//assert"], - size = "small", ) diff --git a/logging/BUILD.bazel b/logging/BUILD.bazel index af733f8..af16f4b 100644 --- a/logging/BUILD.bazel +++ b/logging/BUILD.bazel @@ -15,10 +15,10 @@ go_library( go_test( name = "logging_test", + size = "small", srcs = [ "example_test.go", "log_test.go", ], embed = [":logging"], - size = "small", ) diff --git a/mwc/BUILD.bazel b/mwc/BUILD.bazel index b5fe655..a50e044 100644 --- a/mwc/BUILD.bazel +++ b/mwc/BUILD.bazel @@ -9,11 +9,11 @@ go_library( go_test( name = "mwc_test", + size = "small", srcs = ["mwc_test.go"], embed = [":mwc"], deps = [ "//assert", "//testio", ], - size = "small", ) diff --git a/rand/BUILD.bazel b/rand/BUILD.bazel index 159728b..1115ae9 100644 --- a/rand/BUILD.bazel +++ b/rand/BUILD.bazel @@ -9,7 +9,7 @@ go_library( go_test( name = "rand_test", + size = "small", srcs = ["rand_test.go"], embed = [":rand"], - size = "small", ) diff --git a/sbuf/BUILD.bazel b/sbuf/BUILD.bazel index f605a2c..141d0c8 100644 --- a/sbuf/BUILD.bazel +++ b/sbuf/BUILD.bazel @@ -9,8 +9,8 @@ go_library( go_test( name = "sbuf_test", + size = "small", srcs = ["sbuf_test.go"], embed = [":sbuf"], deps = ["@org_golang_x_crypto//nacl/box"], - size = "small", ) diff --git a/seekbuf/BUILD.bazel b/seekbuf/BUILD.bazel index cd5d55f..925a0da 100644 --- a/seekbuf/BUILD.bazel +++ b/seekbuf/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "seekbuf", @@ -6,3 +6,11 @@ go_library( importpath = "git.wntrmute.dev/kyle/goutils/seekbuf", visibility = ["//visibility:public"], ) + +go_test( + name = "seekbuf_test", + srcs = ["seekbuf_test.go"], + embed = [":seekbuf"], + deps = ["//assert"], + size = "small" +) diff --git a/seekbuf/seekbuf.go b/seekbuf/seekbuf.go index be10e25..253f988 100644 --- a/seekbuf/seekbuf.go +++ b/seekbuf/seekbuf.go @@ -1,3 +1,4 @@ +// seekbuf implements a read-seekable buffer. package seekbuf import "io" @@ -40,7 +41,7 @@ func (b *Buffer) Seek(pos int) { // Rewind resets the read pointer to 0. func (b *Buffer) Rewind() { - b.pos = 0 + b.Seek(0) } // Close clears all the data out of the buffer and sets the read position to 0. @@ -49,3 +50,8 @@ func (b *Buffer) Close() error { b.pos = 0 return nil } + +// Len returns the length of data remaining to be read. +func (b *Buffer) Len() int { + return len(b.data[b.pos:]) +} diff --git a/testio/BUILD.bazel b/testio/BUILD.bazel index ce53aec..64167e7 100644 --- a/testio/BUILD.bazel +++ b/testio/BUILD.bazel @@ -9,7 +9,7 @@ go_library( go_test( name = "testio_test", + size = "small", srcs = ["testio_test.go"], embed = [":testio"], - size = "small", )