Documentation
¶
Index ¶
- Variables
- func Write(doc *Document, wr io.Writer) (int, error)
- func WriteFile(doc *Document, filename string) error
- func WriteFileWithPatches(doc *Document, filename string, patches ...Hunk) error
- func WriteWithPatches(doc *Document, wr io.Writer, patches ...Hunk) (int, error)
- type DirEnt
- type DocHunk
- type Document
- type Hunk
- type PatchAccumulator
- func (pa *PatchAccumulator) AppendPatch(hunk Hunk)
- func (pa *PatchAccumulator) AppendPatchIfBodyDiffers(hunk Hunk, newBody []byte)
- func (pa PatchAccumulator) WriteFileWithPatches(doc *Document, filename string) error
- func (pa PatchAccumulator) WriteWithPatches(doc *Document, wr io.Writer) (int, error)
Constants ¶
This section is empty.
Variables ¶
var Regen = flag.Bool("testmark.regen", false, "Setting this flag hints to systems using testmark tests that fixtures should be regenerated.")
Functions ¶
func WriteFileWithPatches ¶ added in v0.5.0
Types ¶
type DirEnt ¶ added in v0.2.0
type DirEnt struct {
// The name of just this path segment.
// (Note that if there's a Hunk in this DirEnt, its name may be different -- it still has the *full* path name.)
Name string
// A hunk, or nil.
Hunk *Hunk
// Children, recursively.
Children map[string]*DirEnt
ChildrenList []DirEnt
}
DirEnt describes an index over hunks in a document that acts much like a filesystem. See Document.BuildDirIndex for details.
type DocHunk ¶
type DocHunk struct {
// Index into Document.OriginalLines where the comment block is found.
// The code block indicator is necessarily is the following line,
// and the code block body one line after that.
// N.B. zero-indexed. You probably want to +1 before printing to a human.
LineStart int
// Index into Document.OriginalLines that contains the closing code block indicator.
LineEnd int
Hunk
}
DocHunk is the Document's internal idea of where hunks are.
type Document ¶
type Document struct {
// The whole thing, complete, but split into lines.
// We always save this, because if we are going to write this document back out,
// it's going to be by patching this. (We don't try to understand, much less normalize, a full markdown AST!)
// May be nil if this document is the result of Patch operations rather than Parse.
Original []byte
// The document, sliced into lines. Shares backing memory with Original, if Original is non-nil.
// Useful because we made it during parse anyway, and it can save us a lot of work during edits.
Lines [][]byte
// Each data hunk.
// Contains just offset information, and the parsed name header.
// Is in order of hunk appearance.
DataHunks []DocHunk
// Like it says on the tin.
HunksByName map[string]DocHunk
// An index over the hunks, which treats their names as if they were unix-style paths --
// meaning they're split by slashes, and each segment is considered a directory.
// You must call the `BuildDirIndex()` function to cause this to be populated.
DirEnt *DirEnt
}
func (*Document) BuildDirIndex ¶ added in v0.2.0
func (doc *Document) BuildDirIndex()
BuildDirIndex mutates the Document to set the DirEnt field.
The order of ChildrenList in the DirEnt is determined by the order in which things are first seen in the Document's Hunk list. The "directories" can be implied, e.g. a Hunk with name="foo/bar" will cause the creation of a DirEnt with name "foo".
No concept of path "cleaning" is applied. Paths like "." and ".." are not treated specially. A path containing repeated slashes is a fairly deranged thing to do, but also won't be rejected.
type Hunk ¶
type Hunk struct {
// The hunk name (e.g. whatever comes after `[testmark]:# ` and before any more whitespace).
// Cannot be empty.
Name string
// The code block syntax hint (or more literally: anything that comes after the triple-tick that starts the code block).
// Usually we don't encourage use of this much in testmark, but it's here. Can be empty.
InfoString string
// The full body of the hunk, as bytes.
// (This is *still* a subslice of Document.Original, if this hunk was created by Parse, but probably a unique slice otherwise.)
//
// When produced by Parse, the Body has been normalized to have '\n' linebreaks if it originally contained '\r\n'.
// This is meant as a practical conceit to the fact some systems in the Windows ecosystem tend to mutate documents when checking them out of version control,
// and thus testmark finds it practical to pave that back out that again rather than making it an application-level problem.
// (If such a normalization had to be applied, the earlier coment about subslicing of Document.Original probably no longer applies.)
Body []byte
}
Hunk is a simple tuple of hunk name string and body bytes. Optionally, it may also have a BlockTag (which is whatever markdown has in the code block; usually, in practice, this is used to state a syntax for highlighting, which does not have much to do with testmark.)
type PatchAccumulator ¶ added in v0.5.0
type PatchAccumulator struct {
Patches []Hunk
}
func (*PatchAccumulator) AppendPatch ¶ added in v0.5.0
func (pa *PatchAccumulator) AppendPatch(hunk Hunk)
func (*PatchAccumulator) AppendPatchIfBodyDiffers ¶ added in v0.5.0
func (pa *PatchAccumulator) AppendPatchIfBodyDiffers(hunk Hunk, newBody []byte)
func (PatchAccumulator) WriteFileWithPatches ¶ added in v0.5.0
func (pa PatchAccumulator) WriteFileWithPatches(doc *Document, filename string) error
func (PatchAccumulator) WriteWithPatches ¶ added in v0.5.0
Directories
¶
| Path | Synopsis |
|---|---|
|
testexec is a package that offers some helper functions for testing execution of commands (either with actual os.Exec, or a callback of your defining), and tests them using certain conventions of testmark dir+filename names for the fixture data.
|
testexec is a package that offers some helper functions for testing execution of commands (either with actual os.Exec, or a callback of your defining), and tests them using certain conventions of testmark dir+filename names for the fixture data. |