| 1 |
package approvaltests_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/approvals/go-approval-tests" |
| 5 |
) |
| 6 |
|
| 7 |
func ExampleVerifyString() { |
| 8 |
approvaltests.VerifyString(t, "Hello World!") |
| 9 |
printFileContent("examples_test.ExampleVerifyString.received.txt") |
| 10 |
|
| 11 |
// Output: |
| 12 |
// This produced the file examples_test.ExampleVerifyString.received.txt |
| 13 |
// It will be compared against the examples_test.ExampleVerifyString.approved.txt file |
| 14 |
// and contains the text: |
| 15 |
// |
| 16 |
// Hello World! |
| 17 |
} |
| 18 |
|
| 19 |
func ExampleVerifyAllCombinationsFor2() { |
| 20 |
letters := []string{"aaaaa", "bbbbb", "ccccc"} |
| 21 |
numbers := []int{2, 3} |
| 22 |
|
| 23 |
functionToTest := func(text interface{}, length interface{}) string { |
| 24 |
return text.(string)[:length.(int)] |
| 25 |
} |
| 26 |
|
| 27 |
approvaltests.VerifyAllCombinationsFor2(t, "substring", functionToTest, letters, numbers) |
| 28 |
printFileContent("examples_test.ExampleVerifyAllCombinationsFor2.received.txt") |
| 29 |
// Output: |
| 30 |
// This produced the file examples_test.ExampleVerifyAllCombinationsFor2.received.txt |
| 31 |
// It will be compared against the examples_test.ExampleVerifyAllCombinationsFor2.approved.txt file |
| 32 |
// and contains the text: |
| 33 |
// |
| 34 |
// substring |
| 35 |
// |
| 36 |
// |
| 37 |
// [aaaaa,2] => aa |
| 38 |
// [aaaaa,3] => aaa |
| 39 |
// [bbbbb,2] => bb |
| 40 |
// [bbbbb,3] => bbb |
| 41 |
// [ccccc,2] => cc |
| 42 |
// [ccccc,3] => ccc |
| 43 |
} |
| 44 |
|
| 45 |
func ExampleVerifyAllCombinationsFor2WithSkip() { |
| 46 |
words := []string{"stack", "fold"} |
| 47 |
otherWords := []string{"overflow", "trickle"} |
| 48 |
|
| 49 |
functionToTest := func(firstWord interface{}, secondWord interface{}) string { |
| 50 |
first := firstWord.(string) |
| 51 |
second := secondWord.(string) |
| 52 |
if first+second == "stackoverflow" { |
| 53 |
return approvaltests.SkipThisCombination |
| 54 |
} |
| 55 |
return first + second |
| 56 |
} |
| 57 |
|
| 58 |
approvaltests.VerifyAllCombinationsFor2(t, "combineWords", functionToTest, words, otherWords) |
| 59 |
printFileContent("examples_test.ExampleVerifyAllCombinationsFor2WithSkip.received.txt") |
| 60 |
// Output: |
| 61 |
// This produced the file examples_test.ExampleVerifyAllCombinationsFor2WithSkip.received.txt |
| 62 |
// It will be compared against the examples_test.ExampleVerifyAllCombinationsFor2WithSkip.approved.txt file |
| 63 |
// and contains the text: |
| 64 |
// |
| 65 |
// combineWords |
| 66 |
// |
| 67 |
// [stack,trickle] => stacktrickle |
| 68 |
// [fold,overflow] => foldoverflow |
| 69 |
// [fold,trickle] => foldtrickle |
| 70 |
} |