spec

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package spec provides the test specifications for the CountLines function.

Alternate implementations of CountLines function must pass the test as well.

Index

Constants

This section is empty.

Variables

View Source
var DataCountLines = []struct {
	Reason    string // Reason on failure
	Input     string // Input data
	ExpectOut int    // Expected output
}{
	{
		Reason:    "'<EOF>' --> empty file should be zero",
		Input:     "",
		ExpectOut: 0,
	},
	{
		Reason:    "'Hello<EOF>' --> single line without line break should be one",
		Input:     "Hello",
		ExpectOut: 1,
	},
	{
		Reason:    "'Hello\\n<EOF>' --> single line with line break should be one",
		Input:     "Hello\n",
		ExpectOut: 1,
	},
	{
		Reason:    "'\\n<EOF>' --> single line break should be one",
		Input:     "\n",
		ExpectOut: 1,
	},
	{
		Reason:    "'\\n\\n<EOF>' --> two line breaks should be two",
		Input:     "\n\n",
		ExpectOut: 2,
	},
	{
		Reason:    "'\\nHello<EOF>' --> one line break and one line without line break should be two",
		Input:     "\nHello",
		ExpectOut: 2,
	},
	{
		Reason:    "'\\nHello\\n<EOF>' --> one line break and one line with line break should be two",
		Input:     "\nHello\n",
		ExpectOut: 2,
	},
	{
		Reason:    "'\\n\\nHello<EOF>' --> two line breaks and one line without line break should be three",
		Input:     "\n\nHello",
		ExpectOut: 3,
	},
	{
		Reason:    "'\\n\\nHello\\n<EOF>' --> two line breaks and one line with line break should be three",
		Input:     "\n\nHello\n",
		ExpectOut: 3,
	},
	{
		Reason:    "'<large line>\\n<EOF>' --> long string with a line break should be onw",
		Input:     GetStrDummyLines(bufio.MaxScanTokenSize*2, 1),
		ExpectOut: 1,
	},
	{
		Reason:    "'<large line>\\n<large line>\\n<EOF>' --> long string but two lines should be two",
		Input:     GetStrDummyLines(bufio.MaxScanTokenSize*2, 2),
		ExpectOut: 2,
	},
}

DataCountLines is the data provider for the CountLines function to check if the specifications are covered. Alternate functions must pass the test with this data as well.

Functions

func GetStrDummyLines

func GetStrDummyLines(sizeLine, numLine int64) string

GetStrDummyLines returns a string with the given size and number of lines. 'sizeLine' is the size of each line. 'numLines' is the number of lines.

func RunSpecTest

func RunSpecTest(t *testing.T, nameFn string, fn func(io.Reader) (int, error))

RunSpecTest is a helper function to run the specifcations of LineCount function. Alternate implementations (_alt.*) must pass this test as well.

Types

This section is empty.

Jump to

Keyboard shortcuts

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