testcases

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

testcases contains files with recorded or phantasized inputs / expected outputs.

Index

Constants

This section is empty.

Variables

View Source
var CommentAfterPostcondition = Case{
	ID: "comment_after_postcondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}();  // some comment here

	return
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}();  // some comment here

	return
}
`}
View Source
var CurlyBracketsOnSameLine = Case{
	ID: "curly_brackets_on_same_line",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}()
}
`}
View Source
var DoubleNegation = Case{
	ID: "double_negation",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * !strings.HasPrefix(x, "something")
//
// SomeFunc ensures:
// * !strings.HasSuffix(result, "smth else")
func SomeFunc(x string) (result string, err error) {}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * !strings.HasPrefix(x, "something")
//
// SomeFunc ensures:
// * !strings.HasSuffix(result, "smth else")
func SomeFunc(x string) (result string, err error) {
	// Pre-condition
	if strings.HasPrefix(x, "something") {
		panic("Violated: !strings.HasPrefix(x, \"something\")")
	}

	// Post-condition
	defer func() {
		if strings.HasSuffix(result, "smth else") {
			panic("Violated: !strings.HasSuffix(result, \"smth else\")")
		}
	}()
}
`}
View Source
var DoubleNegations = Case{
	ID: "double_negations",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * !strings.HasPrefix(x, "something")
// * !strings.HasPrefix(x, "another")
//
// SomeFunc ensures:
// * !strings.HasSuffix(result, "smth else")
// * !strings.HasSuffix(result, "yet another")
func SomeFunc(x string) (result string, err error) {}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * !strings.HasPrefix(x, "something")
// * !strings.HasPrefix(x, "another")
//
// SomeFunc ensures:
// * !strings.HasSuffix(result, "smth else")
// * !strings.HasSuffix(result, "yet another")
func SomeFunc(x string) (result string, err error) {
	// Pre-conditions
	switch {
	case strings.HasPrefix(x, "something"):
		panic("Violated: !strings.HasPrefix(x, \"something\")")
	case strings.HasPrefix(x, "another"):
		panic("Violated: !strings.HasPrefix(x, \"another\")")
	default:
		// Pass
	}

	// Post-conditions
	defer func() {
		switch {
		case strings.HasSuffix(result, "smth else"):
			panic("Violated: !strings.HasSuffix(result, \"smth else\")")
		case strings.HasSuffix(result, "yet another"):
			panic("Violated: !strings.HasSuffix(result, \"yet another\")")
		default:
			// Pass
		}
	}()
}
`}
View Source
var FailureNoDeferInPostcondition = Failure{
	ID: "no_defer_in_postcondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
	if !(x > 0) {
		panic("Violated: x > 0")
	}
	
	// Post-condition
	panic("hello")

	return
}
`,
	Error: "expected a defer statement after the comment \"Post-condition\" in function SomeFunc on line 19"}
View Source
var FailureNoIfInPrecondition = Failure{
	ID: "no_if_in_precondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
	panic("hello")

	return
}
`,
	Error: "expected an 'if' statement after the comment \"Pre-condition\" in function SomeFunc on line 14"}
View Source
var FailureNoStatementAfterPostcondtion = Failure{
	ID: "no_statement_after_postcondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
	if !(x > 0) {
		panic("Violated: x > 0")
	}

	// Post-condition
}
`,
	Error: "found no statement after the comment \"Post-condition\" in function SomeFunc on line 18"}
View Source
var FailureNoStatementAfterPrecondtion = Failure{
	ID: "no_statement_after_precondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
}
`,
	Error: "found no statement after the comment Pre-condition in function SomeFunc on line 13"}
View Source
var FailureNoSwitchInPrecondition = Failure{
	ID: "no_switch_in_preconditions",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	panic("hello")

	return
}
`,
	Error: "expected a 'switch' statement after the comment \"Pre-conditions\" in function SomeFunc on line 14"}
View Source
var FailureStatementBefore = Failure{
	ID: "statement_before",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	panic("hello")

	// Pre-condition
	if !(x > 0) {
		panic("Violated: x > 0")
	}

	// Post-condition
	defer func() {
		if !(result == "oi") {
			panic("Violated: result == \"oi\"")
		}
	}();

	return
}
`,
	Error: "unexpected statement before the comment \"Pre-condition\" in function SomeFunc on line 13"}
View Source
var FailureStatementInbetween = Failure{
	ID: "statement_inbetween",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// SomeFunc ensures:
// * result == "oi"
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
	if !(x > 0) {
		panic("Violated: x > 0")
	}

	panic("hello")

	// Post-condition
	defer func() {
		if !(result == "oi") {
			panic("Violated: result == \"oi\"")
		}
	}();

	return
}
`,
	Error: "unexpected statement between the pre- and post-condition blocks in function SomeFunc on line 18"}
View Source
var HasOnlyComment = Case{
	ID: "has_only_comment",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Some comment
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}()

	// Some comment
}
`}
View Source
var HasPostcondition = Case{
	ID: "has_postcondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}()

	// do something
	return
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}()

	// do something
	return
}
`}
View Source
var HasPrecondition = Case{
	ID: "has_precondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
	if !(y > 4) {
		panic("Violated: y > 4")
	}

	// do something
	return
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}()

	// do something
	return
}
`}
View Source
var MultipleFunctions = Case{
	ID: "multiple_functions",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// do something
	return
}

// AnotherFunc does something.
//
// AnotherFunc requires:
// * x > 0
//
// Some text here.
func AnotherFunc(x int, y int) (result string, err error) {
	// do something
	return
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-condition
	if !(x > 0) {
		panic("Violated: x > 0")
	}

	// do something
	return
}

// AnotherFunc does something.
//
// AnotherFunc requires:
// * x > 0
//
// Some text here.
func AnotherFunc(x int, y int) (result string, err error) {
	// Pre-condition
	if !(x > 0) {
		panic("Violated: x > 0")
	}

	// do something
	return
}
`}
View Source
var NoConditions = Case{
	ID: "no_conditions",
	Text: `package somepkg

// SomeFunc does something.
func SomeFunc(x int, y int) (result string, err error) {
	// do something
	return
}
`,
	Expected: `package somepkg

// SomeFunc does something.
func SomeFunc(x int, y int) (result string, err error) {
	// do something
	return
}
`}
View Source
var NoPreviousConditions = Case{
	ID: "no_previous_conditions",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// do something
	return
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}()

	// do something
	return
}
`}
View Source
var SemicolonAfterPostcondition = Case{
	ID: "semicolon_after_postcondition",
	Text: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}(); return  // return here
}
`,
	Expected: `package somepkg

// SomeFunc does something.
//
// SomeFunc requires:
// * x > 0
// * x < 100
// * some condition: y > 3
//
// SomeFunc ensures:
// * strings.HasPrefix(result, "hello")
//
// Some text here.
func SomeFunc(x int, y int) (result string, err error) {
	// Pre-conditions
	switch {
	case !(x > 0):
		panic("Violated: x > 0")
	case !(x < 100):
		panic("Violated: x < 100")
	case !(y > 3):
		panic("Violated: some condition: y > 3")
	default:
		// Pass
	}

	// Post-condition
	defer func() {
		if !(strings.HasPrefix(result, "hello")) {
			panic("Violated: strings.HasPrefix(result, \"hello\")")
		}
	}(); return  // return here
}
`}

Functions

This section is empty.

Types

type Case

type Case struct {
	ID       string
	Text     string
	Expected string
}

type Failure

type Failure struct {
	ID    string
	Text  string
	Error string
}

Jump to

Keyboard shortcuts

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