| 1 |
package location |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/maxatome/go-testdeep/internal/test" |
| 7 |
) |
| 8 |
|
| 9 |
func TestNew(t *testing.T) { |
| 10 |
for _, curTest := range []struct { |
| 11 |
callDepth int |
| 12 |
expectOK bool |
| 13 |
}{ |
| 14 |
{callDepth: 0, expectOK: true}, |
| 15 |
{callDepth: 1, expectOK: true}, |
| 16 |
{callDepth: 100, expectOK: false}, |
| 17 |
} { |
| 18 |
loc, ok := New(curTest.callDepth) |
| 19 |
test.EqualBool(t, ok, curTest.expectOK, "callDepth=%d", curTest.callDepth) |
| 20 |
if ok { |
| 21 |
test.IsTrue(t, loc.File != "", "File should not be empty for callDepth=%d", curTest.callDepth) |
| 22 |
test.IsTrue(t, loc.Func != "", "Func should not be empty for callDepth=%d", curTest.callDepth) |
| 23 |
test.IsTrue(t, loc.Line > 0, "Line should be >0 for callDepth=%d", curTest.callDepth) |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
func TestIsInitialized(t *testing.T) { |
| 29 |
for _, curTest := range []struct { |
| 30 |
loc Location |
| 31 |
expected bool |
| 32 |
}{ |
| 33 |
{loc: Location{}, expected: false}, |
| 34 |
{loc: Location{File: ""}, expected: false}, |
| 35 |
{loc: Location{File: "test.go"}, expected: true}, |
| 36 |
{loc: Location{File: "test.go", Func: "Test", Line: 10}, expected: true}, |
| 37 |
} { |
| 38 |
test.EqualBool(t, curTest.loc.IsInitialized(), curTest.expected, "loc=%+v", curTest.loc) |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
func TestString(t *testing.T) { |
| 43 |
for _, curTest := range []struct { |
| 44 |
loc Location |
| 45 |
expected string |
| 46 |
}{ |
| 47 |
{ |
| 48 |
loc: Location{File: "test.go", Func: "TestFunc", Line: 10}, |
| 49 |
expected: "TestFunc at test.go:10", |
| 50 |
}, |
| 51 |
{ |
| 52 |
loc: Location{File: "main.go", Func: "main", Line: 5, Inside: "inside something "}, |
| 53 |
expected: "main inside something at main.go:5", |
| 54 |
}, |
| 55 |
{ |
| 56 |
loc: Location{File: "pkg/utils.go", Func: "utils.Helper", Line: 42, Inside: "in map "}, |
| 57 |
expected: "utils.Helper in map at pkg/utils.go:42", |
| 58 |
}, |
| 59 |
} { |
| 60 |
test.EqualStr(t, curTest.loc.String(), curTest.expected, "loc=%+v", curTest.loc) |
| 61 |
} |
| 62 |
} |