tv

package
v0.0.0-...-d191b88 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: BSD-3-Clause, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package tv generates test vectors for trunnel types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteCorpus

func WriteCorpus(c *Corpus, dir string) error

WriteCorpus writes the corpus of vectors in a standard structure under dir.

Types

type Constraints

type Constraints map[string]map[string]int64

Constraints records fixed values for struct/context fields.

func NewConstraints

func NewConstraints() Constraints

NewConstraints builds an empty set of constraints.

func (Constraints) ClearLocal

func (c Constraints) ClearLocal()

ClearLocal deletes all constraints in the local scope.

func (Constraints) ClearScope

func (c Constraints) ClearScope(s string)

ClearScope deletes all constraints in scope s.

func (Constraints) Clone

func (c Constraints) Clone() Constraints

Clone returns a deep copy of c.

func (Constraints) CloneGlobal

func (c Constraints) CloneGlobal() Constraints

CloneGlobal clones all constraints apart from the local ones. It is a convenience for Clone followed by ClearLocal.

func (Constraints) Lookup

func (c Constraints) Lookup(s, k string) (int64, bool)

Lookup returns the value of the constraint on s.k.

func (Constraints) LookupLocal

func (c Constraints) LookupLocal(k string) (int64, bool)

LookupLocal is a convenience for looking up in the local scope "".

func (Constraints) LookupOrCreate

func (c Constraints) LookupOrCreate(s, k string, v int64) int64

LookupOrCreate looks up s.k and returns the value if it exists. Otherwise the constraint is set to v and returned.

func (Constraints) LookupOrCreateRef

func (c Constraints) LookupOrCreateRef(r *ast.IDRef, v int64) int64

LookupOrCreateRef is a convenience for LookupOrCreate with an AST IDRef.

func (Constraints) LookupRef

func (c Constraints) LookupRef(r *ast.IDRef) (int64, bool)

LookupRef is a convenience for looking up an AST IDRef.

func (Constraints) Merge

func (c Constraints) Merge(other Constraints) (Constraints, error)

Merge builds a new set of constraints by merging c and other. Errors on conflict.

func (Constraints) Set

func (c Constraints) Set(s, k string, v int64) error

Set sets the value of s.k.

func (Constraints) SetRef

func (c Constraints) SetRef(r *ast.IDRef, v int64) error

SetRef is a convenience for setting the value of an AST IDRef.

func (Constraints) Update

func (c Constraints) Update(d Constraints) error

Update applies all constraints in d to c.

type Corpus

type Corpus struct {
	Suites []Suite
}

Corpus is a collection of test vectors for multiple types.

func Generate

func Generate(f *ast.File, opts ...Option) (*Corpus, error)

Generate generates a set of test vectors for the types defined in f.

func GenerateFiles

func GenerateFiles(fs []*ast.File, opts ...Option) (*Corpus, error)

GenerateFiles generates test vectors for the types in the given files.

func (*Corpus) AddSuite

func (c *Corpus) AddSuite(s Suite)

AddSuite appends a suite to the corpus.

func (*Corpus) AddVectors

func (c *Corpus) AddVectors(n string, vs []Vector)

AddVectors adds vectors to the corpus for type n. Convenience wrapper around AddSuite.

func (Corpus) Vectors

func (c Corpus) Vectors(n string) []Vector

Vectors looks up test vectors for the given type. Returns nil if none found.

type Option

type Option func(*generator)

Option is an option to control test vector generation.

func WithRandom

func WithRandom(r random.Interface) Option

WithRandom sets the random source for test vector generation.

func WithSelector

func WithSelector(s Selector) Option

WithSelector sets the method for cutting down the number of vectors we have.

type Selector

type Selector interface {
	SelectVectors([]Vector) []Vector
}

Selector selects which vectors to keep from a given list.

var Exhaustive Selector = SelectorFunc(func(vs []Vector) []Vector { return vs })

Exhaustive selects all vectors.

func RandomSampleSelector

func RandomSampleSelector(n int) Selector

RandomSampleSelector selects a random sample of up to n vectors.

type SelectorFunc

type SelectorFunc func([]Vector) []Vector

SelectorFunc implements Selector interface with a plain function.

func (SelectorFunc) SelectVectors

func (f SelectorFunc) SelectVectors(vs []Vector) []Vector

SelectVectors calls f.

type Suite

type Suite struct {
	Type    string
	Vectors []Vector
}

Suite contains test vectors for one type.

type Vector

type Vector struct {
	Data        []byte
	Constraints Constraints
}

Vector is a test vector.

func NewVector

func NewVector(b []byte) Vector

NewVector builds a test vector with empty constraints.

Jump to

Keyboard shortcuts

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