testencoding

package
v0.0.0-...-93088af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2013 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

The testencoding package is used in testing serialization and deserialization. It is particularly useful when some sub-sequences of bytes can acceptably be written in any order (e.g if they are generated from representations that do not provide order guarantees like maps).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Matches

func Matches(matcher IBytesMatcher, b []byte) error

Types

type BytesLiteral

type BytesLiteral struct {
	Bytes []byte
}

BytesLiteral matches a literal sequence of bytes.

func LiteralString

func LiteralString(s string) *BytesLiteral

func (*BytesLiteral) Match

func (bm *BytesLiteral) Match(b []byte) (n int, err error)

func (*BytesLiteral) String

func (bm *BytesLiteral) String() string

func (*BytesLiteral) Write

func (bm *BytesLiteral) Write(writer *bytes.Buffer)

type BytesMatcherAnyOrder

type BytesMatcherAnyOrder struct {
	Matchers []IBytesMatcher
}

BytesMatcherAnyOrder matches a set of BytesMatchers, but they do not have to match in any particular order.

func AnyOrder

func AnyOrder(matchers ...IBytesMatcher) *BytesMatcherAnyOrder

func (*BytesMatcherAnyOrder) Match

func (bm *BytesMatcherAnyOrder) Match(b []byte) (n int, err error)

func (*BytesMatcherAnyOrder) String

func (bm *BytesMatcherAnyOrder) String() string

func (*BytesMatcherAnyOrder) Write

func (bm *BytesMatcherAnyOrder) Write(writer *bytes.Buffer)

type BytesMatcherInOrder

type BytesMatcherInOrder struct {
	Matchers []IBytesMatcher
}

BytesMatcherInOrder matches a sequence of BytesMatchers that must match in the order given.

func InOrder

func InOrder(matchers ...IBytesMatcher) *BytesMatcherInOrder

func (*BytesMatcherInOrder) Match

func (bm *BytesMatcherInOrder) Match(b []byte) (n int, err error)

func (*BytesMatcherInOrder) String

func (bm *BytesMatcherInOrder) String() string

func (*BytesMatcherInOrder) Write

func (bm *BytesMatcherInOrder) Write(writer *bytes.Buffer)

type IBytesMatcher

type IBytesMatcher interface {
	// Match tests if the given sequence of bytes matches. It returns
	// matches=true if it matches correctly, and returns the number of bytes
	// matched as n.
	Match(b []byte) (n int, err error)

	// Write writes a sequence of bytes to the buffer that is an acceptable match
	// for the matcher..
	Write(writer *bytes.Buffer)

	String() string
}

IBytesMatcher is the interface that tests if a sequence of bytes matches expectations.

type MatchError

type MatchError struct {
	FailedMatcher IBytesMatcher
	NextBytes     []byte
}

func (*MatchError) Error

func (err *MatchError) Error() string

type TrailingBytesError

type TrailingBytesError struct {
	FailedMatcher IBytesMatcher
	TrailingBytes []byte
}

func (*TrailingBytesError) Error

func (err *TrailingBytesError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL