MCPcopy Index your code
hub / github.com/voidint/g / Test_render

Function Test_render

cli/cli_test.go:61–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func Test_render(t *testing.T) {
62 t.Run("渲染go版本列表(text)", func(t *testing.T) {
63 var got strings.Builder
64 items := []*version.Version{
65 version.MustNew("1.19beta1"),
66 version.MustNew("1.10beta2"),
67 version.MustNew("1.7"),
68 version.MustNew("1.8.1"),
69 version.MustNew("1.21.0"),
70 version.MustNew("1.21rc4"),
71 }
72 sort.Sort(version.Collection(items))
73
74 render(textMode, map[string]bool{"1.8.1": true}, items, &got)
75 assert.Equal(t, " 1.7\n* 1.8.1\n 1.10beta2\n 1.19beta1\n 1.21rc4\n 1.21.0\n", got.String())
76 })
77
78 t.Run("渲染go版本列表(json)", func(t *testing.T) {
79 var actual strings.Builder
80 items := []*version.Version{
81 version.MustNew("1.19beta1"),
82 version.MustNew("1.10beta2"),
83 version.MustNew("1.7"),
84 version.MustNew("1.8.1"),
85 version.MustNew("1.21.0"),
86 version.MustNew("1.21rc4"),
87 }
88 sort.Sort(version.Collection(items))
89
90 installed := map[string]bool{"1.8.1": true}
91 render(jsonMode, installed, items, &actual)
92
93 vs := make([]versionOut, 0, len(items))
94 for _, item := range items {
95 vo := versionOut{
96 Version: item.Name(),
97 Packages: item.Packages(),
98 }
99 if inuse, found := installed[item.Name()]; found {
100 vo.InUse = inuse
101 vo.Installed = found
102 }
103 vs = append(vs, vo)
104 }
105
106 var expected strings.Builder
107 enc := json.NewEncoder(&expected)
108 enc.SetIndent("", " ")
109 _ = enc.Encode(&vs)
110 assert.Equal(t, expected.String(), actual.String())
111 })
112}
113
114func Test_wrapstring(t *testing.T) {
115 t.Run("包装字符串", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

MustNewFunction · 0.92
CollectionTypeAlias · 0.92
renderFunction · 0.85
PackagesMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…