stringtest

package module
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Input

func Input(s string) string

Input is a helper to normalize test input strings.

It dedents the string by removing the common leading whitespace from all lines, allowing test inputs to be indented for readability while producing clean output.

At most one leading newline and one trailing newline are stripped.

func JoinCRLF

func JoinCRLF(ss ...string) string

JoinCRLF joins strings with CRLF (\r\n) line endings.

Use this to construct expected test output with explicit Windows-style line endings. See also JoinLF for Unix-style line endings.

Example:

want := stringtest.JoinCRLF(
	"line1",
	"line2",
	"line3",
) // -> "line1\r\nline2\r\nline3"

func JoinLF

func JoinLF(ss ...string) string

JoinLF joins strings with LF (\n) line endings.

Use this to construct expected test output with explicit line endings. See also JoinCRLF for Windows-style line endings. See also LinesLF for newline-terminated output.

Example:

want := stringtest.JoinLF(
	"line1",
	"line2",
	"line3",
) // -> "line1\nline2\nline3"

func LinesCRLF added in v0.2.0

func LinesCRLF(ss ...string) string

LinesCRLF joins strings as newline-terminated lines using CRLF (\r\n) line endings.

Each argument is treated as one complete line; every line, including the last, is terminated with "\r\n". LinesCRLF("a", "b") == "a\r\nb\r\n". LinesCRLF() == "".

This differs from JoinCRLF, which uses "\r\n" as a separator and does not terminate the final element. See also JoinCRLF when the output does not end in a newline. See also LinesLF for Unix-style line endings.

Example:

want := stringtest.LinesCRLF(
	"line1",
	"line2",
	"line3",
) // -> "line1\r\nline2\r\nline3\r\n"

func LinesLF added in v0.2.0

func LinesLF(ss ...string) string

LinesLF joins strings as newline-terminated lines using LF (\n) line endings.

Each argument is treated as one complete line; every line, including the last, is terminated with "\n". LinesLF("a", "b") == "a\nb\n". LinesLF() == "".

This differs from JoinLF, which uses "\n" as a separator and does not terminate the final element. See also JoinLF when the output does not end in a newline. See also LinesCRLF for Windows-style line endings.

Example:

want := stringtest.LinesLF(
	"line1",
	"line2",
	"line3",
) // -> "line1\nline2\nline3\n"

func Margin added in v0.2.0

func Margin(s string) string

Margin normalizes a test string using margin markers, preserving significant leading whitespace. Each line is written with a '|' marker; everything before and including the first '|' (which must be preceded only by spaces and tabs) is removed, and everything after it is kept verbatim. Lines without a marker are left unchanged.

At most one leading newline is stripped (so the block can start on the line after the opening backtick), and a final whitespace-only line without a marker is dropped along with the newline that precedes it (so the closing backtick can be indented and the result carries no trailing newline). Unlike Input, trailing whitespace on marked lines is preserved. Pair with LinesLF semantics by appending "\n" when a newline-terminated want is needed.

Example:

want := stringtest.Margin(`
    |   1 | first line with leading spaces
    |   2 | second line
    |   3 |
`)
// -> "   1 | first line with leading spaces\n   2 | second line\n   3 |"

func TrimLineEnds added in v0.2.0

func TrimLineEnds(s string) string

TrimLineEnds trims trailing spaces and tabs from every line of s, preserving line structure and any final newline. CRLF line endings are preserved: whitespace before a trailing \r is trimmed and the \r kept.

Use this to normalize rendered output before comparing it against expected strings built with JoinLF; terminal renderers such as lipgloss pad lines with trailing spaces to the render width.

Types

This section is empty.

Jump to

Keyboard shortcuts

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