536df07f72
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 1st set of files. R=rsc CC=agl, golang-dev, iant, ken2, r https://golang.org/cl/180047
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package tls
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
"testing/iotest"
|
|
)
|
|
|
|
func matchRecord(r1, r2 *record) bool {
|
|
if (r1 == nil) != (r2 == nil) {
|
|
return false
|
|
}
|
|
if r1 == nil {
|
|
return true
|
|
}
|
|
return r1.contentType == r2.contentType &&
|
|
r1.major == r2.major &&
|
|
r1.minor == r2.minor &&
|
|
bytes.Compare(r1.payload, r2.payload) == 0
|
|
}
|
|
|
|
type recordReaderTest struct {
|
|
in []byte
|
|
out []*record
|
|
}
|
|
|
|
var recordReaderTests = []recordReaderTest{
|
|
recordReaderTest{nil, nil},
|
|
recordReaderTest{fromHex("01"), nil},
|
|
recordReaderTest{fromHex("0102"), nil},
|
|
recordReaderTest{fromHex("010203"), nil},
|
|
recordReaderTest{fromHex("01020300"), nil},
|
|
recordReaderTest{fromHex("0102030000"), []*record{&record{1, 2, 3, nil}}},
|
|
recordReaderTest{fromHex("01020300000102030000"), []*record{&record{1, 2, 3, nil}, &record{1, 2, 3, nil}}},
|
|
recordReaderTest{fromHex("0102030001fe0102030002feff"), []*record{&record{1, 2, 3, []byte{0xfe}}, &record{1, 2, 3, []byte{0xfe, 0xff}}}},
|
|
recordReaderTest{fromHex("010203000001020300"), []*record{&record{1, 2, 3, nil}}},
|
|
}
|
|
|
|
func TestRecordReader(t *testing.T) {
|
|
for i, test := range recordReaderTests {
|
|
buf := bytes.NewBuffer(test.in)
|
|
c := make(chan *record)
|
|
go recordReader(c, buf)
|
|
matchRecordReaderOutput(t, i, test, c)
|
|
|
|
buf = bytes.NewBuffer(test.in)
|
|
buf2 := iotest.OneByteReader(buf)
|
|
c = make(chan *record)
|
|
go recordReader(c, buf2)
|
|
matchRecordReaderOutput(t, i*2, test, c)
|
|
}
|
|
}
|
|
|
|
func matchRecordReaderOutput(t *testing.T, i int, test recordReaderTest, c <-chan *record) {
|
|
for j, r1 := range test.out {
|
|
r2 := <-c
|
|
if r2 == nil {
|
|
t.Errorf("#%d truncated after %d values", i, j)
|
|
break
|
|
}
|
|
if !matchRecord(r1, r2) {
|
|
t.Errorf("#%d (%d) got:%#v want:%#v", i, j, r2, r1)
|
|
}
|
|
}
|
|
<-c
|
|
if !closed(c) {
|
|
t.Errorf("#%d: channel didn't close", i)
|
|
}
|
|
}
|