(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func 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 |
| 173 | fizz buzz |
| 174 | |
| 175 | cat |
| 176 | bippity 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 | |
| 183 | func TestTable_AddRow_WithNewLines(t *testing.T) { |
| 184 | t.Parallel() |
nothing calls this directly
no test coverage detected