github.com/urso/go-structform@v0.0.2/cborl/cborl_test.go (about) 1 package cborl 2 3 import ( 4 "bytes" 5 "testing" 6 7 structform "github.com/urso/go-structform" 8 "github.com/urso/go-structform/sftest" 9 ) 10 11 func TestEncParseConsistent(t *testing.T) { 12 testEncParseConsistent(t, Parse) 13 } 14 15 func TestEncDecoderConsistent(t *testing.T) { 16 testEncParseConsistent(t, func(content []byte, to structform.Visitor) error { 17 dec := NewBytesDecoder(content, to) 18 return dec.Next() 19 }) 20 } 21 22 func TestEncParseBytesConsistent(t *testing.T) { 23 testEncParseConsistent(t, func(content []byte, to structform.Visitor) error { 24 p := NewParser(to) 25 for _, b := range content { 26 err := p.feed([]byte{b}) 27 if err != nil { 28 return err 29 } 30 } 31 return nil 32 }) 33 } 34 35 func testEncParseConsistent( 36 t *testing.T, 37 parse func([]byte, structform.Visitor) error, 38 ) { 39 sftest.TestEncodeParseConsistent(t, sftest.Samples, 40 func() (structform.Visitor, func(structform.Visitor) error) { 41 buf := bytes.NewBuffer(nil) 42 vs := NewVisitor(buf) 43 44 return vs, func(to structform.Visitor) error { 45 return parse(buf.Bytes(), to) 46 } 47 }) 48 }