@@ -105,26 +105,43 @@ suite("TableStringWriter tests", () => {
105105 assert . throws ( ( ) => writer . writeTable ( input ) ) ;
106106 } ) ;
107107
108- test ( "writeTable() table with null rows throws exception" , ( ) => {
108+ test ( "writeTable() table with empty header and separator columns throws exception" , ( ) => {
109109 const input : TableViewModel = new TableViewModel ( ) ;
110110 input . header = makeRowViewModel ( [ ] ) ;
111111 input . separator = makeRowViewModel ( [ ] ) ;
112+ input . rows = [ ] ;
112113
113114 const writer = createSut ( ) ;
114115
115116 assert . throws ( ( ) => writer . writeTable ( input ) ) ;
116117 } ) ;
117118
118- test ( "writeTable() table with no rows throws exception" , ( ) => {
119+ test ( "writeTable() table with null rows array throws exception" , ( ) => {
119120 const input : TableViewModel = new TableViewModel ( ) ;
120- input . header = makeRowViewModel ( [ ] ) ;
121- input . rows = [ ] ;
121+ input . header = makeRowViewModel ( [ "c1" , "c2" ] ) ;
122+ input . separator = makeRowViewModel ( [ "--" , "--" ] ) ;
123+ input . rows = null ;
122124
123125 const writer = createSut ( ) ;
124126
125127 assert . throws ( ( ) => writer . writeTable ( input ) ) ;
126128 } ) ;
127129
130+ test ( "writeTable() table with no rows is allowed" , ( ) => {
131+ const input : TableViewModel = new TableViewModel ( ) ;
132+ input . header = makeRowViewModel ( [ "c1" , "c2" ] ) ;
133+ input . separator = makeRowViewModel ( [ "--" , "--" ] ) ;
134+ input . rows = [ ] ;
135+
136+ const tableText : string = createSut ( ) . writeTable ( input ) ;
137+
138+ assertExt . isNotNull ( tableText ) ;
139+ const lines = tableText . split ( / \r \n | \r | \n / ) ;
140+ assert . strictEqual ( lines . length , 2 ) ;
141+ assert . strictEqual ( lines [ 0 ] , "c1|c2" ) ;
142+ assert . strictEqual ( lines [ 1 ] , "--|--" ) ;
143+ } ) ;
144+
128145 test ( "writeTable() writes left borders on all rows for viewModel having hasLeftBorderSet" , ( ) => {
129146 const input : TableViewModel = new TableViewModel ( ) ;
130147 input . hasLeftBorder = true ;
0 commit comments