adds some tests too · Entire

adds some tests too

f872ee4→main·

Soph·1mo ago·1 file·+68 added/-0 removed

Sessions

11c16f0c4d1fView transcript

Changes

1

3 unmodified lines

4
5
6
7
8
9
10
87 unmodified lines

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

3 unmodified lines

"bytes"
    "strings"
    "testing"
    "unicode/utf8"
)

func TestLabsCmd_PrintsExperimentalCommandList(t *testing.T) {
87 unmodified lines

}
}

// summaryColumns returns, for each non-empty rendered row, the rune offset at
// which the summary begins (i.e. the column after the padded invocation).
func summaryColumns(t *testing.T, commands []experimentalCommandInfo) []int {
    t.Helper()
    var cols []int
    for _, line := range strings.Split(renderExperimentalCommands(commands), "\n") {
        if line == "" {
            continue
        }
        info := indexOfSummary(t, line, commands)
        cols = append(cols, info)
    }
    return cols
}

// indexOfSummary finds the rune offset of a row's summary text within the line.
func indexOfSummary(t *testing.T, line string, commands []experimentalCommandInfo) int {
    t.Helper()
    for _, info := range commands {
        if idx := strings.Index(line, info.Summary); idx >= 0 {
            return utf8.RuneCountInString(line[:idx])
        }
    }
    t.Fatalf("no known summary found in rendered line %q", line)
    return -1
}

func TestRenderExperimentalCommands_SummariesAlign(t *testing.T) {
    t.Parallel()

cols := summaryColumns(t, experimentalCommands)
    if len(cols) < 2 {
        t.Fatalf("expected multiple experimental commands, got %d", len(cols))
    }
    for i, col := range cols {
        if col != cols[0] {
            t.Fatalf("summary column %d (%d) does not match first column (%d); descriptions are misaligned", i, col, cols[0])
        }
    }
}

func TestRenderExperimentalCommands_ColumnWidthAdjustsToLongest(t *testing.T) {
    t.Parallel()

short := []experimentalCommandInfo{
        {Name: "a", Invocation: "entire a", Summary: "first"},
        {Name: "b", Invocation: "entire b", Summary: "second"},
    }
    long := []experimentalCommandInfo{
        {Name: "a", Invocation: "entire a", Summary: "first"},
        {Name: "verylongcommand", Invocation: "entire verylongcommand", Summary: "second"},
    }

shortCol := summaryColumns(t, short)[0]
    longCol := summaryColumns(t, long)[0]

if longCol <= shortCol {
        t.Fatalf("column should widen for a longer invocation: short=%d long=%d", shortCol, longCol)
    }
    // All rows in the long set must still align despite differing invocation lengths.
    for i, col := range summaryColumns(t, long) {
        if col != longCol {
            t.Fatalf("row %d column %d does not match %d", i, col, longCol)
        }
    }
}

func TestLabsRegistryCommandsExistAtCanonicalPaths(t *testing.T) {
    t.Parallel()