File: examples_test.go

package info (click to toggle)
golang-github-approvals-go-approval-tests 0.0~git20180620.6ae1ec6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 296 kB
  • sloc: xml: 16; makefile: 3
file content (70 lines) | stat: -rw-r--r-- 2,183 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package approvaltests_test

import (
	"github.com/approvals/go-approval-tests"
)

func ExampleVerifyString() {
	approvaltests.VerifyString(t, "Hello World!")
	printFileContent("examples_test.ExampleVerifyString.received.txt")

	// Output:
	// This produced the file examples_test.ExampleVerifyString.received.txt
	// It will be compared against the examples_test.ExampleVerifyString.approved.txt file
	// and contains the text:
	//
	// Hello World!
}

func ExampleVerifyAllCombinationsFor2() {
	letters := []string{"aaaaa", "bbbbb", "ccccc"}
	numbers := []int{2, 3}

	functionToTest := func(text interface{}, length interface{}) string {
		return text.(string)[:length.(int)]
	}

	approvaltests.VerifyAllCombinationsFor2(t, "substring", functionToTest, letters, numbers)
	printFileContent("examples_test.ExampleVerifyAllCombinationsFor2.received.txt")
	// Output:
	// This produced the file examples_test.ExampleVerifyAllCombinationsFor2.received.txt
	// It will be compared against the examples_test.ExampleVerifyAllCombinationsFor2.approved.txt file
	// and contains the text:
	//
	// substring
	//
	//
	// [aaaaa,2] => aa
	// [aaaaa,3] => aaa
	// [bbbbb,2] => bb
	// [bbbbb,3] => bbb
	// [ccccc,2] => cc
	// [ccccc,3] => ccc
}

func ExampleVerifyAllCombinationsFor2WithSkip() {
	words := []string{"stack", "fold"}
	otherWords := []string{"overflow", "trickle"}

	functionToTest := func(firstWord interface{}, secondWord interface{}) string {
		first := firstWord.(string)
		second := secondWord.(string)
		if first+second == "stackoverflow" {
			return approvaltests.SkipThisCombination
		}
		return first + second
	}

	approvaltests.VerifyAllCombinationsFor2(t, "combineWords", functionToTest, words, otherWords)
	printFileContent("examples_test.ExampleVerifyAllCombinationsFor2WithSkip.received.txt")
	// Output:
	// 	This produced the file examples_test.ExampleVerifyAllCombinationsFor2WithSkip.received.txt
	// It will be compared against the examples_test.ExampleVerifyAllCombinationsFor2WithSkip.approved.txt file
	// and contains the text:
	//
	// combineWords
	//
	// [stack,trickle] => stacktrickle
	// [fold,overflow] => foldoverflow
	// [fold,trickle] => foldtrickle
}