filterutil

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

filterutil

Shared utilities for filter resolution and path handling used by sync-test-cases.

Purpose

This package provides common functionality for:

  • Extracting stem names from file paths
  • Finding project roots (.git or tests/sources.json)
  • Loading and parsing refs.json files
  • Resolving filter strings (stem or path) to destination directories

Types

  • RefEntry - Represents a source file entry in refs.json
  • RefPart - Represents a destination part in refs.json

Functions

  • FindProjectRoot() - Searches for .git directory or tests/sources.json
  • ExtractStemFromFilter(filter) - Extracts stem from a filter (stem or path)
  • LoadRefs(dirPath) - Loads refs.json from a directory
  • FindDestinationForStem(baseDir, destinations, stem) - Finds unique destination for a stem
  • ResolveFilterToDestination(baseDir, destinations, filter, originalFilter) - Main resolver function

Usage

sync-test-cases uses this package to handle filter parameters that can be either:

  • Simple stem names: murder-mystery-june-2025
  • Full paths: tests/ipmt/files-md/murder-mystery-june-2025.ipmt

The package handles stem extraction, path validation, and destination resolution automatically.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractStemFromFilter

func ExtractStemFromFilter(filter string) (stem string, absPath string, err error)

ExtractStemFromFilter extracts the stem (base filename without extension) from a filter string. If the filter is a path, it resolves it and extracts the stem. Returns the stem and absolute path (if filter was a path), or error.

func FindDestinationForStem

func FindDestinationForStem(baseDir string, destinations []string, stem string) (string, error)

FindDestinationForStem searches for a stem in all destination directories and returns the unique destination directory path. Returns error if stem is not found or is ambiguous.

func FindProjectRoot

func FindProjectRoot() (string, error)

FindProjectRoot searches for .git directory or tests/sources.json starting from current directory

func ResolveFilterToDestination

func ResolveFilterToDestination(baseDir string, destinations []string, filter string, originalFilter string) (destDir string, stem string, err error)

ResolveFilterToDestination resolves a filter (stem or path) to a destination directory and normalized stem. It handles both simple stem names and full file paths.

Types

type ParserMeta

type ParserMeta struct {
	ItemType    string `json:"item_type"`
	ItemSubtype string `json:"item_subtype"`
}

ParserMeta contains metadata about the parser

type RefEntry

type RefEntry struct {
	Source     string                 `json:"source"`
	SourceSHA1 string                 `json:"source_sha1"`
	Name       string                 `json:"name,omitempty"`
	Method     string                 `json:"method,omitempty"`
	ParserName string                 `json:"parser_name,omitempty"`
	ParserMeta map[string]interface{} `json:"parser_meta,omitempty"`
	Items      []RefItem              `json:"items"`
}

RefEntry represents a source file entry in _refs.json

func LoadRefs

func LoadRefs(dirPath string) ([]RefEntry, error)

LoadRefs loads _refs.json from the given directory

type RefItem

type RefItem struct {
	Destination string            `json:"destination"`
	Line        int               `json:"line,omitempty"`
	Anchor      string            `json:"anchor,omitempty"`
	ContentSHA1 string            `json:"content_sha1"`
	Outputs     map[string]string `json:"outputs,omitempty"`
	Heading     string            `json:"heading,omitempty"` // ### heading where test is defined
	Section     string            `json:"section,omitempty"` // ## section where test is defined
	Tags        []string          `json:"tags,omitempty"`    // Test tags from @test-tags comment
}

RefItem represents a destination item in _refs.json

Jump to

Keyboard shortcuts

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