MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / TestTable_AddRow

Function TestTable_AddRow

internal/table/table_test.go:143–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestTable_AddRow(t *testing.T) {
144 t.Parallel()
145
146 buf := bytes.Buffer{}
147 tbl := New("foo", "bar").WithWriter(&buf).AddRow("fizz", "buzz")
148 tbl.Print()
149 out := buf.String()
150 assert.Contains(t, out, "fizz")
151 assert.Contains(t, out, "buzz")
152 lines := strings.Count(out, "\n")
153
154 // empty should add empty line
155 buf.Reset()
156 tbl.AddRow().Print()
157 assert.Equal(t, lines+1, strings.Count(buf.String(), "\n"))
158
159 // less than one will fill left-to-right
160 buf.Reset()
161 tbl.AddRow("cat").Print()
162 assert.Contains(t, buf.String(), "\ncat")
163
164 // more than initial length are truncated
165 buf.Reset()
166 tbl.AddRow("bippity", "boppity", "boo").Print()
167 assert.NotContains(t, buf.String(), "boo")
168
169 // check the full table
170 buf.Reset()
171 tbl.Print()
172 expected := `foo bar
173fizz buzz
174
175cat
176bippity boppity
177`
178 if diff := cmp.Diff(expected, buf.String()); diff != "" {
179 t.Fatalf("table mismatch (-expected +got):\n%s\nout=%#v", diff, buf.String())
180 }
181}
182
183func TestTable_AddRow_WithNewLines(t *testing.T) {
184 t.Parallel()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
AddRowMethod · 0.65
WithWriterMethod · 0.65
PrintMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected