Skip to content

Commit

Permalink
Merge pull request #265 from capnproto/cleanup/dead-code
Browse files Browse the repository at this point in the history
Assorted clean-up tasks
  • Loading branch information
zenhack authored Jul 15, 2022
2 parents 80012bc + e22199f commit ed853e6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
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 @@ -14,6 +14,8 @@ import (
)

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

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

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

type allocTest struct {
name string

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

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

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

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

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

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

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

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

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

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

for i, test := range serializeTests {
if test.decodeFails {
continue
Expand All @@ -538,6 +552,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 @@ -598,6 +614,8 @@ func TestWriteTo(t *testing.T) {
}

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

for i, test := range serializeTests {
if test.decodeFails {
continue
Expand All @@ -624,6 +642,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 @@ -661,6 +681,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 @@ -745,6 +766,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 @@ -786,6 +809,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 @@ -855,6 +880,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 @@ -876,6 +903,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 @@ -897,6 +926,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 @@ -956,6 +987,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

0 comments on commit ed853e6

Please sign in to comment.