markdownloader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package markdownloader loads test.Test values from Markdown files containing code blocks representing test inputs and expected outputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadContent

func LoadContent(info, code string) (loader.Content, bool, error)

LoadContent is the default ContentLoader implementation.

func ParseInfoString

func ParseInfoString(info string) (lang string, attrs map[string]string, err error)

ParseInfoString parses the "info string" of a fenced code block into a language and a map of attributes.

Types

type ContentLoader

type ContentLoader func(info, code string) (_ loader.Content, skip bool, _ error)

A ContentLoader is a function that returns content obtained from a fenced code block.

info is the "info string" of the code block, that is the line of text that contains the language and other loader-specific information.

See https://spec.commonmark.org/0.31.2/#fenced-code-blocks

type LoadOption

type LoadOption func(*loadOptions)

LoadOption is an option that changes the behavior of a Loader.

func WithContentLoader

func WithContentLoader(load ContentLoader) LoadOption

WithContentLoader is a LoadOption that configures an alternative ContentLoader used to load content from code blocks.

func WithFS

func WithFS(f fs.FS) LoadOption

WithFS is a LoadOption that configures an alternative filesystem to use when loading tests.

func WithParser

func WithParser(p parser.Parser) LoadOption

WithParser is a LoadOption that configures an alternative Markdown parser to use when loading tests.

func WithRecursion

func WithRecursion(on bool) LoadOption

WithRecursion if a LoadOption that enables or disables recursive scanning of sub-directories.

Recursion is enabled by default.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader loads test.Test values from Markdown files containing code blocks representing test inputs and expected outputs.

func NewLoader

func NewLoader(options ...LoadOption) *Loader

NewLoader returns a new Loader, which loads golden file tests from the filesystem.

func (*Loader) Load

func (l *Loader) Load(dir string, options ...LoadOption) (test.Test, error)

Load returns a test built from files in the given directory.

Any directory or file that begins with an underscore produces a test that is marked as skipped.

Jump to

Keyboard shortcuts

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