symbolassert

package module
v0.0.0-...-235cd3c Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

README

symbolassert

A package that can assert if independent defined values are equal.

This package was born to use a test to verify the definition of OS dependent constants and types being equal while not referring to some shared package.

inspiration

The strconv package has it's own implementation that determines if a charachter is printable and does not import the package that can provide the canonical answer, the unicode package. However there is a test that verifies that the function in strconv agrees with the canonical one in the unicode package. By doing this there is no need to import all the unicode tables if a program wants to use the strconv package.

Documentation

Overview

Package symbolassert asserts that symbols are defined in a package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(m ObjectMap, cfg *Config) error

Compare asserts that locally defined symbols are defined the same as the package that authoritatively defines them. Currently the configuration parameter is ignored and may be ni.

Types

type Config

type Config struct {
	SortByKey bool
}

Config configures the Compare function.

type Errors

type Errors struct {
	Errs []error
}

Errors is returned from SymbolMap.Resolve and Compare.

func (*Errors) Error

func (e *Errors) Error() string

type ObjectMap

type ObjectMap map[types.Object]types.Object

A ObjectMap maps from the locally defined symbol value to a value that is authoritative.

type PackageProvider

type PackageProvider struct {
	GOOS      string   // target operating system
	GOARCH    string   // target architecture
	BuildTags []string // build tags

	// Package is used to resolve an unqualified identifier,
	// an identifier without a package name. The caller is
	// responsible to Load this package.
	Package string
	// contains filtered or unexported fields
}

func (*PackageProvider) Load

func (p *PackageProvider) Load(path string) error

Load implements the Provider interface.

func (*PackageProvider) Lookup

func (p *PackageProvider) Lookup(symbol string) types.Object

Lookup implements the Provider interface.

type Provider

type Provider interface {
	// Load loads the package at the given import path
	// and makes the symbols available for lookup.
	Load(importPath string) error

	// Lookup looks up a symbol.
	// It must return nil if not found.
	Lookup(symbol string) types.Object
}

Provider looks up symbol names.

func FileProvider

func FileProvider(importPath string, files []string) (Provider, error)

FileProvider returns a Provider that resolves symbols based on a set of Go source files.

type SymbolMap

type SymbolMap map[string]string

A SymbolMap maps from a locally defined identifier to an identifier that is authoritative. The package name may be omitted.

func (SymbolMap) Resolve

func (m SymbolMap) Resolve(from, to Provider) (ObjectMap, error)

Resolve resolves the symbol map to an ObjectMap.

type UnresolvedError

type UnresolvedError struct {
	Provider Provider
	Symbol   string
}

UnresolvedError is returned if Resolve can't lookup a symbol.

func (*UnresolvedError) Error

func (e *UnresolvedError) Error() string

Directories

Path Synopsis
internal
packageloader
Package packageloader provides helpers for loading packages.
Package packageloader provides helpers for loading packages.

Jump to

Keyboard shortcuts

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