github.com/go-playground/pkg/v5@v5.29.1/runtime/stack_test.go (about) 1 package runtimeext 2 3 import ( 4 "testing" 5 ) 6 7 func nested(level int) Frame { 8 return StackLevel(level) 9 } 10 11 func TestStack(t *testing.T) { 12 tests := []struct { 13 name string 14 frame Frame 15 file string 16 line int 17 function string 18 }{ 19 { 20 name: "stack", 21 frame: Stack(), 22 file: "stack_test.go", 23 line: 21, 24 function: "TestStack", 25 }, 26 { 27 name: "stack-level1", 28 frame: nested(1), 29 file: "stack_test.go", 30 line: 28, 31 function: "TestStack", 32 }, 33 { 34 name: "stack-level0", 35 frame: nested(0), 36 file: "stack_test.go", 37 line: 8, 38 function: "nested", 39 }, 40 } 41 for _, tt := range tests { 42 t.Run(tt.name, func(t *testing.T) { 43 if tt.frame.File() != tt.file { 44 t.Errorf("TestStack File() = %s, want %s", tt.frame.File(), tt.file) 45 } 46 if tt.frame.Line() != tt.line { 47 t.Errorf("TestStack Line() = %d, want %d", tt.frame.Line(), tt.line) 48 } 49 if tt.frame.Function() != tt.function { 50 t.Errorf("TestStack Function() = %s, want %s", tt.frame.Function(), tt.function) 51 } 52 }) 53 } 54 }