validation

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: GPL-3.0 Imports: 4 Imported by: 7

Documentation

Overview

Package validation is used to define entry validators and rules. It contains a few general rule types (see validation/rules/rules.go), and you can also create new rules using the Rule interface.

To create a validating rule suite, initialize the Validator struct using a slice of Rule instances. Use the Validator.Validate or ValidateEntry functions to have one or more entries validated. Implemented validators are found in sub package validation/validators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToString added in v0.4.1

func ToString(r Rule) string

Types

type Result

type Result struct {
	RuleName string
	Level    string
	Messages []string
}

Result is a validation result with the following fields:

RuleName - arbitrary string
Level - typically indicating severity (e.g. Info/Warning/Fatal/Format/Severe)
Messages - arbitrary strings representing validation messages to the user

func (Result) Strings

func (r Result) Strings() []string

Strings returns a slice of simple string representations of the messages in Result, including information on rule name and rule level

type Rule

type Rule interface {
	Validate(lex.Entry) (Result, error)
	ShouldAccept() []lex.Entry
	ShouldReject() []lex.Entry
	Name() string
	Level() string
}

Rule interface. To create a validation.Rule, make a struct implementing Validate, ShouldAccept and ShouldReject as defined in this interface.

type TestResult

type TestResult struct {
	RuleName string
	Level    string
	Messages []string
	Input    lex.Entry
}

TestResult holds the test result for a tested rule suite (accept, reject, or cross tests result)

func (TestResult) String added in v0.4.1

func (tr TestResult) String() string

type TestResultContainer

type TestResultContainer struct {
	AcceptErrors []TestResult
	RejectErrors []TestResult
	CrossErrors  []TestResult
}

TestResultContainer is a container class for accept/reject/crosscheck test result

func (TestResultContainer) AllErrors

func (tc TestResultContainer) AllErrors() []TestResult

AllErrors returns all errors in the TestResultContainer

func (TestResultContainer) Size

func (tc TestResultContainer) Size() int

Size returns the total number of errors in the TestResultContainer

type Validator

type Validator struct {
	Name  string
	Rules []Rule
}

Validator is a struct containing a slice of rules

func (Validator) AllTests added in v0.4.1

func (v Validator) AllTests() ([]lex.Entry, []lex.Entry)

func (Validator) IsDefined

func (v Validator) IsDefined() bool

IsDefined is used to check if the validator is initialized (by checking that the validator has a non-empty name).

func (Validator) NumberOfTests added in v0.4.1

func (v Validator) NumberOfTests() int

func (Validator) RunTests

func (v Validator) RunTests() (TestResultContainer, error)

RunTests runs accept/reject tests for all individual rules, and cross checks all accept tests against the other rules

func (Validator) String added in v0.4.1

func (v Validator) String() string

func (Validator) ValidateEntries

func (v Validator) ValidateEntries(entries []lex.Entry) ([]lex.Entry, bool)

ValidateEntries is used to validate a slice of entries. Any validation errors are added to each entry's EntryValidations field. The function returns true if the entry is valid (i.e., no validation issues are found), otherwise false.

func (Validator) ValidateEntry

func (v Validator) ValidateEntry(e *lex.Entry)

ValidateEntry is used to validate single entries. Any validation errors are added to the entry's EntryValidations field.

Directories

Path Synopsis
Package locale is meant to be used to validate a locale specified for a lexicon.
Package locale is meant to be used to validate a locale specified for a lexicon.
Package rules contains a few general validation rule types.
Package rules contains a few general validation rule types.
Package validators contains a validator service for caching loaded validators, and it contains language and project specific validators.
Package validators contains a validator service for caching loaded validators, and it contains language and project specific validators.

Jump to

Keyboard shortcuts

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