| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package internal |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "fmt" |
||
| 5 | "os" |
||
| 6 | "testing" |
||
| 7 | ) |
||
| 8 | |||
| 9 | func TestEach(t *testing.T) { |
||
| 10 | testData := getEachTestData() |
||
| 11 | for key, test := range testData { |
||
| 12 | erra := test.err |
||
| 13 | errb := Each(test.inputValue, test.mapFunction) |
||
| 14 | if erra == nil { |
||
| 15 | if errb != nil { |
||
| 16 | t.Errorf("Convert.ToUint64 does not works expected\ncase %s: error: %s", key, errb.Error()) |
||
| 17 | } |
||
| 18 | } |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | func ExampleEach() { |
||
| 23 | data := []int64{10, 20, 30} |
||
| 24 | _ = Each(data, func(val interface{}, i int) { |
||
| 25 | fmt.Printf("%d apples", val) |
||
| 26 | }) |
||
| 27 | // Output: 10 apples20 apples30 apples |
||
| 28 | } |
||
| 29 | func printTestLine(val interface{}, i int) { |
||
| 30 | fmt.Fprintln(os.Stdout, val) |
||
| 31 | } |
||
| 32 | |||
| 33 | func getEachTestData() map[string]struct { |
||
| 34 | inputValue interface{} |
||
| 35 | mapFunction func(a interface{}, i int) |
||
| 36 | err error |
||
| 37 | } { |
||
| 38 | |||
| 39 | testData := map[string]struct { |
||
| 40 | inputValue interface{} |
||
| 41 | mapFunction func(a interface{}, i int) |
||
| 42 | err error |
||
| 43 | }{ |
||
| 44 | "string": { |
||
| 45 | inputValue: []string{"gotilty", "gotil"}, |
||
| 46 | mapFunction: printTestLine, |
||
| 47 | err: nil, |
||
| 48 | }, |
||
| 49 | } |
||
| 50 | return testData |
||
| 51 | } |
||
| 52 |