@@ -2,6 +2,7 @@ package terminal_test
2
2
3
3
import (
4
4
"bytes"
5
+ "strings"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/assert"
@@ -92,3 +93,47 @@ func TestNotEnoughRowEntiresJson(t *testing.T) {
92
93
assert .Contains (t , buf .String (), "\" column_1\" : \" row1\" " )
93
94
assert .Contains (t , buf .String (), "\" column_1\" : \" \" " )
94
95
}
96
+
97
+ func TestPrintCsvSimple (t * testing.T ) {
98
+ buf := bytes.Buffer {}
99
+ testTable := NewTable (& buf , []string {"col1" , "col2" })
100
+ testTable .Add ("row1-col1" , "row1-col2" )
101
+ testTable .Add ("row2-col1" , "row2-col2" )
102
+ err := testTable .PrintCsv ()
103
+ assert .Equal (t , err , nil )
104
+ assert .Contains (t , buf .String (), "col1,col2" )
105
+ assert .Contains (t , buf .String (), "row1-col1,row1-col2" )
106
+ assert .Contains (t , buf .String (), "row2-col1,row2-col2" )
107
+ }
108
+
109
+ func TestNotEnoughColPrintCsv (t * testing.T ) {
110
+ buf := bytes.Buffer {}
111
+ testTable := NewTable (& buf , []string {"" , "col2" })
112
+ testTable .Add ("row1-col1" , "row1-col2" )
113
+ testTable .Add ("row2-col1" , "row2-col2" )
114
+ err := testTable .PrintCsv ()
115
+ assert .Equal (t , err , nil )
116
+ assert .Contains (t , buf .String (), ",col2" )
117
+ assert .Contains (t , buf .String (), "row1-col1,row1-col2" )
118
+ assert .Contains (t , buf .String (), "row2-col1,row2-col2" )
119
+ }
120
+
121
+ func TestNotEnoughRowPrintCsv (t * testing.T ) {
122
+ buf := bytes.Buffer {}
123
+ testTable := NewTable (& buf , []string {"col1" , "col2" })
124
+ testTable .Add ("row1-col1" , "row1-col2" )
125
+ testTable .Add ("row2-col1" , "" )
126
+ err := testTable .PrintCsv ()
127
+ assert .Equal (t , err , nil )
128
+ assert .Contains (t , buf .String (), "col1,col2" )
129
+ assert .Contains (t , buf .String (), "row1-col1,row1-col2" )
130
+ assert .Contains (t , buf .String (), "row2-col1," )
131
+ }
132
+
133
+ func TestEmptyTable (t * testing.T ) {
134
+ buf := bytes.Buffer {}
135
+ testTable := NewTable (& buf , []string {})
136
+ err := testTable .PrintCsv ()
137
+ assert .Equal (t , err , nil )
138
+ assert .Equal (t , len (strings .TrimSpace (buf .String ())), 0 )
139
+ }
0 commit comments