Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted clean-up tasks #265

Merged
merged 7 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions capnpc-go/capnpc-go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ func TestBuildNodeMap(t *testing.T) {
n := nodes[k]
if n == nil {
t.Errorf("%s: missing @%#x from node map", test.name, k)
}
if n.Id() != k {
} else if n.Id() != k {
t.Errorf("%s: node map has ID @%#x for lookup of @%#x", test.name, n.Id(), k)
}
}
Expand Down
9 changes: 0 additions & 9 deletions encoding/text/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ func (enc *Encoder) marshalText(t []byte) {
enc.w.Write(enc.tmp)
}

func needsEscape(b byte) bool {
return b < 0x20 || b >= 0x7f
}

func hexDigit(b byte) byte {
const digits = "0123456789abcdef"
return digits[b]
}

func (enc *Encoder) marshalStruct(typeID uint64, s capnp.Struct) error {
n, err := enc.nodes.Find(typeID)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
)

func TestNewMessage(t *testing.T) {
t.Parallel()

tests := []struct {
arena Arena
fails bool
Expand Down Expand Up @@ -53,6 +55,8 @@ func TestNewMessage(t *testing.T) {
}

func TestAlloc(t *testing.T) {
t.Parallel()

type allocTest struct {
name string

Expand Down Expand Up @@ -166,6 +170,8 @@ func TestAlloc(t *testing.T) {
}

func TestSingleSegment(t *testing.T) {
t.Parallel()

// fresh arena
{
arena := SingleSegment(nil)
Expand Down Expand Up @@ -206,6 +212,8 @@ func TestSingleSegment(t *testing.T) {
}

func TestSingleSegmentAllocate(t *testing.T) {
t.Parallel()

tests := []arenaAllocTest{
{
name: "empty arena",
Expand Down Expand Up @@ -273,6 +281,8 @@ func TestSingleSegmentAllocate(t *testing.T) {
}

func TestMultiSegment(t *testing.T) {
t.Parallel()

// fresh arena
{
arena := MultiSegment(nil)
Expand Down Expand Up @@ -313,6 +323,8 @@ func TestMultiSegment(t *testing.T) {
}

func TestMultiSegmentAllocate(t *testing.T) {
t.Parallel()

tests := []arenaAllocTest{
{
name: "empty arena",
Expand Down Expand Up @@ -514,6 +526,8 @@ var serializeTests = []serializeTest{
}

func TestMarshal(t *testing.T) {
t.Parallel()

for i, test := range serializeTests {
if test.decodeFails {
continue
Expand All @@ -537,6 +551,8 @@ func TestMarshal(t *testing.T) {
}

func TestUnmarshal(t *testing.T) {
t.Parallel()

for i, test := range serializeTests {
if test.encodeFails {
continue
Expand Down Expand Up @@ -573,6 +589,8 @@ func TestUnmarshal(t *testing.T) {
}

func TestEncoder(t *testing.T) {
t.Parallel()

for i, test := range serializeTests {
if test.decodeFails {
continue
Expand All @@ -599,6 +617,8 @@ func TestEncoder(t *testing.T) {
}

func TestDecoder(t *testing.T) {
t.Parallel()

for i, test := range serializeTests {
if test.encodeFails {
continue
Expand Down Expand Up @@ -636,6 +656,7 @@ func TestDecoder(t *testing.T) {

func TestDecoder_MaxMessageSize(t *testing.T) {
t.Parallel()

zeroWord := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
tests := []struct {
name string
Expand Down Expand Up @@ -720,6 +741,8 @@ func TestDecoder_MaxMessageSize(t *testing.T) {
// zeroed. This was not done in previous versions and
// resulted in the padding being garbage.
func TestStreamHeaderPadding(t *testing.T) {
t.Parallel()

msg := &Message{
Arena: MultiSegment([][]byte{
incrementingData(8),
Expand Down Expand Up @@ -761,6 +784,8 @@ func TestStreamHeaderPadding(t *testing.T) {
}

func TestAddCap(t *testing.T) {
t.Parallel()

hook1 := new(dummyHook)
hook2 := new(dummyHook)
client1 := NewClient(hook1)
Expand Down Expand Up @@ -830,6 +855,8 @@ func TestAddCap(t *testing.T) {
}

func TestFirstSegmentMessage_SingleSegment(t *testing.T) {
t.Parallel()

msg, seg, err := NewMessage(SingleSegment(nil))
if err != nil {
t.Fatal(err)
Expand All @@ -851,6 +878,8 @@ func TestFirstSegmentMessage_SingleSegment(t *testing.T) {
}

func TestFirstSegmentMessage_MultiSegment(t *testing.T) {
t.Parallel()

msg, seg, err := NewMessage(MultiSegment(nil))
if err != nil {
t.Fatal(err)
Expand All @@ -872,6 +901,8 @@ func TestFirstSegmentMessage_MultiSegment(t *testing.T) {
}

func TestNextAlloc(t *testing.T) {
t.Parallel()

const max32 = 1<<31 - 8
const max64 = 1<<63 - 8
const is64bit = int64(maxInt) == math.MaxInt64
Expand Down Expand Up @@ -931,6 +962,8 @@ func TestNextAlloc(t *testing.T) {

// Make sure Message.TotalSize() returns a value consistent with Message.Marshal()
func TestTotalSize(t *testing.T) {
t.Parallel()

var emptyWord [8]byte
err := quick.Check(func(segs [][]byte) bool {
// Make sure there is at least one segment, and that all segments
Expand Down
6 changes: 6 additions & 0 deletions packed/packed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ var badDecompressionTests = []struct {

func TestPack(t *testing.T) {
t.Parallel()
t.Helper()

for _, test := range compressionTests {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -278,6 +279,7 @@ func TestPack_wordsize(t *testing.T) {

func TestUnpack(t *testing.T) {
t.Parallel()
t.Helper()

var tests []testCase
tests = append(tests, compressionTests...)
Expand All @@ -301,6 +303,7 @@ func TestUnpack(t *testing.T) {

func TestUnpack_Fail(t *testing.T) {
t.Parallel()
t.Helper()

for _, test := range badDecompressionTests {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -314,6 +317,7 @@ func TestUnpack_Fail(t *testing.T) {

func TestReader(t *testing.T) {
t.Parallel()
t.Helper()

var tests []testCase
tests = append(tests, compressionTests...)
Expand Down Expand Up @@ -344,6 +348,7 @@ func TestReader(t *testing.T) {

func TestReader_DataErr(t *testing.T) {
t.Parallel()
t.Helper()

const readSize = 3
var tests []testCase
Expand Down Expand Up @@ -371,6 +376,7 @@ func TestReader_DataErr(t *testing.T) {

func TestReader_Fail(t *testing.T) {
t.Parallel()
t.Helper()

for _, test := range badDecompressionTests {
t.Run(test.name, func(t *testing.T) {
Expand Down