MCPcopy
hub / github.com/spf13/cast / TestAlias

Function TestAlias

alias_test.go:13–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestAlias(t *testing.T) {
14 type MyStruct struct{}
15
16 type MyString string
17 type MyOtherString MyString
18 type MyAliasString = MyOtherString
19
20 type MyBool bool
21 type MyOtherBool MyBool
22 type MyAliasBool = MyOtherBool
23
24 type MyInt int
25 type MyInt8 int8
26 type MyInt16 int16
27 type MyInt32 int32
28 type MyInt64 int64
29 type MyUint uint
30 type MyUint8 uint8
31 type MyUint16 uint16
32 type MyUint32 uint32
33 type MyUint64 uint64
34 type MyFloat32 float32
35 type MyFloat64 float64
36
37 var myStruct *MyStruct
38
39 testCases := []struct {
40 input any
41 expectedValue any
42 expectedOk bool
43 }{
44 {"string", "string", false}, // Already resolved
45 {MyStruct{}, MyStruct{}, false}, // Non-resolvable
46 {nil, nil, false},
47 {&MyStruct{}, &MyStruct{}, false},
48 {myStruct, myStruct, false},
49
50 {MyString("string"), "string", true},
51 {MyOtherString("string"), "string", true},
52 {MyAliasString("string"), "string", true},
53
54 {MyBool(true), true, true},
55 {MyOtherBool(true), true, true},
56 {MyAliasBool(true), true, true},
57
58 {MyInt(1234), int(1234), true},
59 {MyInt8(123), int8(123), true},
60 {MyInt16(1234), int16(1234), true},
61 {MyInt32(1234), int32(1234), true},
62 {MyInt64(1234), int64(1234), true},
63
64 {MyUint(1234), uint(1234), true},
65 {MyUint8(123), uint8(123), true},
66 {MyUint16(1234), uint16(1234), true},
67 {MyUint32(1234), uint32(1234), true},
68 {MyUint64(1234), uint64(1234), true},
69
70 {MyFloat32(1.0), float32(1.0), true},

Callers

nothing calls this directly

Calls 15

MyOtherStringTypeAlias · 0.85
MyOtherBoolTypeAlias · 0.85
resolveAliasFunction · 0.85
MyStringTypeAlias · 0.70
MyBoolTypeAlias · 0.70
MyIntTypeAlias · 0.70
MyInt8TypeAlias · 0.70
MyInt16TypeAlias · 0.70
MyInt32TypeAlias · 0.70
MyInt64TypeAlias · 0.70
MyUintTypeAlias · 0.70
MyUint8TypeAlias · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…