Documentation
¶
Overview ¶
Package tokftest provides the `tokman verify` command.
Package tokftest provides declarative filter testing based on tokf's framework. Test Format Specification (TOML):
name = "Test name" description = "What this test checks" filter = "filter_name" # or filter_file = "path.toml" [[input]] name = "case1" source = "input text" [[input.file]] path = "test.txt" content = "file content" [[expect]] name = "case1" output = "expected output" contains = ["must", "contain"] excludes = ["must", "not have"] tokens.lt = 100 # less than 100 tokens saved.pct = 50 # 50% savings [[expect.match]] pattern = "regex" count = 2 # exactly 2 matches
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI provides the verify command interface.
func (*CLI) GenerateFixture ¶
GenerateFixture generates a fixture file from a test.
func (*CLI) RunTestsByTag ¶
RunTestsByTag runs tests matching a tag.
type CaseResult ¶
type CaseResult struct {
Name string
Passed bool
Input string
Output string
Tokens int
Saved int
Errors []string
Duration int64 // milliseconds
}
CaseResult represents the result of a single test case.
type ErrorExpect ¶
type ErrorExpect struct {
ShouldError bool `toml:"should_error,omitempty"`
Contains string `toml:"contains,omitempty"`
}
ErrorExpect represents error expectations.
type ExpectCase ¶
type ExpectCase struct {
Name string `toml:"name"`
Output string `toml:"output,omitempty"`
Contains []string `toml:"contains,omitempty"`
Excludes []string `toml:"excludes,omitempty"`
Tokens *TokenExpect `toml:"tokens,omitempty"`
Saved *SavedExpect `toml:"saved,omitempty"`
Matches []MatchExpect `toml:"match,omitempty"`
Error *ErrorExpect `toml:"error,omitempty"`
Quality *QualityExpect `toml:"quality,omitempty"`
}
ExpectCase represents expected output for a test case.
type FilterLoader ¶
type FilterLoader interface {
Load(name string) (*filter.Engine, error)
LoadFromFile(path string) (*filter.Engine, error)
}
FilterLoader loads filter configurations.
type Fixture ¶
type Fixture struct {
Name string `toml:"name"`
Content string `toml:"content"`
File string `toml:"file,omitempty"`
}
Fixture represents a reusable test fixture.
type InputCase ¶
type InputCase struct {
Name string `toml:"name"`
Source string `toml:"source,omitempty"`
Files []TestFile `toml:"file,omitempty"`
Command string `toml:"command,omitempty"`
}
InputCase represents a test input case.
type MatchExpect ¶
type MatchExpect struct {
Pattern string `toml:"pattern"`
Count *int `toml:"count,omitempty"`
Min *int `toml:"min,omitempty"`
Max *int `toml:"max,omitempty"`
}
MatchExpect represents regex match expectations.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses test specifications.
type QualityExpect ¶
type QualityExpect struct {
MinScore *float64 `toml:"min_score,omitempty"`
PreserveErrors bool `toml:"preserve_errors,omitempty"`
PreserveURLs bool `toml:"preserve_urls,omitempty"`
}
QualityExpect represents quality expectations.
type Report ¶
type Report struct {
TotalTests int
Passed int
Failed int
Skipped int
TotalCases int
TotalTokens int
TotalSaved int
Duration time.Duration
TestResults []*TestResult
}
Report generates a test report.
func GenerateReport ¶
func GenerateReport(results []*TestResult) *Report
GenerateReport generates a comprehensive report.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes test specifications.
func (*Runner) Run ¶
func (r *Runner) Run(spec *TestSpec) *TestResult
Run executes a test specification.
type SavedExpect ¶
type SavedExpect struct {
Count *int `toml:"count,omitempty"`
Pct *float64 `toml:"pct,omitempty"` // percentage
Ratio *float64 `toml:"ratio,omitempty"` // compression ratio
}
SavedExpect represents savings expectations.
type TestResult ¶
type TestResult struct {
Spec *TestSpec
Passed bool
Duration int64 // milliseconds
Cases []CaseResult
Errors []string
Skipped bool
}
TestResult represents the result of running a test.
type TestSpec ¶
type TestSpec struct {
Name string `toml:"name"`
Description string `toml:"description"`
Filter string `toml:"filter,omitempty"`
FilterFile string `toml:"filter_file,omitempty"`
Mode string `toml:"mode,omitempty"`
Config map[string]interface{} `toml:"config,omitempty"`
Inputs []InputCase `toml:"input"`
Expects []ExpectCase `toml:"expect"`
Fixtures []Fixture `toml:"fixture,omitempty"`
Skip bool `toml:"skip,omitempty"`
Only bool `toml:"only,omitempty"`
Tags []string `toml:"tags,omitempty"`
}
TestSpec represents a declarative filter test specification.
type TokenExpect ¶
type TokenExpect struct {
LT *int `toml:"lt,omitempty"` // less than
LTE *int `toml:"lte,omitempty"` // less than or equal
GT *int `toml:"gt,omitempty"` // greater than
GTE *int `toml:"gte,omitempty"` // greater than or equal
EQ *int `toml:"eq,omitempty"` // equal
}
TokenExpect represents token count expectations.