rulestest

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package rulestest provides test helpers for validating Telescope rules. It works with both built-in Go rules and SDK plugin rules.

Usage:

func TestMyRule(t *testing.T) {
    rulestest.Run(t, "my-rule-id", rulestest.Case{
        Name: "catches missing field",
        Spec: `openapi: "3.1.0"
info:
  title: Test
  version: "1.0"`,
        Expect: []rulestest.Diag{
            {Line: 1, Code: "my-rule-id", Severity: rulestest.Warn},
        },
    })
}

Index

Constants

Severity constants for test expectations.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, analyzer treesitter.Analyzer, cases ...Case)

Run executes a rule's analyzer against the given test cases. The analyzer should be obtained from rules.Define(...).Build().

func RunCustom

func RunCustom(t *testing.T, analyzer treesitter.Analyzer, cases ...Case)

RunCustom executes a custom analyzer function against test cases. Useful for testing SDK plugin rules without the registry.

func RunVisitors

func RunVisitors(t *testing.T, ruleID string, severity ctypes.Severity, v rules.Visitors, cases ...Case)

RunVisitors executes a rule's visitors directly against test cases. This is useful for testing rules by their visitor functions.

Types

type Case

type Case struct {
	Name   string
	Spec   string // YAML content
	Expect []Diag // expected diagnostics
}

Case is a single test scenario for a rule.

type Diag

type Diag struct {
	Line     uint32          // 0-based line
	Col      uint32          // 0-based character (optional, 0 means any)
	Code     string          // rule ID
	Severity ctypes.Severity // expected severity
	Message  string          // optional substring match
}

Diag describes an expected diagnostic.

Jump to

Keyboard shortcuts

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