github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/x/pkgx/__tests__/func.go (about) 1 package main 2 3 import ( 4 "strings" 5 6 "github.com/machinefi/w3bstream/pkg/depends/x/pkgx/__tests__/sub" 7 ) 8 9 func Example() { 10 11 } 12 13 type String string 14 15 func (String) Method() string { 16 return strings.Join(strings.Split("1", ","), ",") 17 } 18 19 func FuncSingleReturn() interface{} { 20 // should skip 21 _ = func() string { 22 return "" 23 }() 24 25 var a interface{} 26 a = "" + "1" 27 a = 2 28 29 return a 30 } 31 32 func FuncSelectExprReturn() string { 33 s := "2" 34 return (struct{ s string }{s: s}).s 35 } 36 37 func FuncWillCall() (a interface{}, s String) { 38 return FuncSingleReturn(), String(FuncSelectExprReturn()) 39 } 40 41 func FuncReturnWithCallDirectly() (a interface{}, b String) { 42 return FuncWillCall() 43 } 44 45 func FuncWithNamedReturn() (a interface{}, b String) { 46 a, b = FuncWillCall() 47 return 48 } 49 50 func FuncSingleNamedReturnByAssign() (a interface{}, s String) { 51 a = "" + "1" 52 s = "2" 53 return 54 } 55 56 func FuncWithSwitch() (a interface{}, b String) { 57 switch a { 58 case "1": 59 a = "a1" 60 b = "b1" 61 return 62 case "2": 63 a = "a2" 64 b = "b2" 65 return 66 default: 67 a = "a3" 68 b = "b3" 69 } 70 return 71 } 72 73 func str(a string, b string) string { 74 return a + b 75 } 76 77 func FuncWithIf() (a interface{}) { 78 if true { 79 a = "a0" 80 return 81 } else if true { 82 a = "a1" 83 return 84 } else { 85 a = str("a", "b") 86 return 87 } 88 } 89 90 func FuncCallReturnAssign() (a interface{}, b String) { 91 return FuncSingleReturn(), String(FuncSelectExprReturn()) 92 } 93 94 func FuncCallWithFuncLit() (a interface{}, b String) { 95 call := func() interface{} { 96 return 1 97 } 98 99 return call(), "1" 100 } 101 102 func FuncWithCurryCall() interface{} { 103 return sub.CurryCall()()() 104 }