@@ -182,26 +182,55 @@ module.exports = function (runTest) {
182182 return [ makeTable , expected , 'multi-line-colors' ] ;
183183 } ) ;
184184
185- it ( 'Set `wordWrap` to true to make lines of text wrap instead of being truncated ' , function ( ) {
185+ it ( 'Set `wordWrap` to true to wrap text on word boundaries ' , function ( ) {
186186 function makeTable ( ) {
187187 let table = new Table ( {
188188 style : { border : [ ] , header : [ ] } ,
189- colWidths : [ 7 , 9 ] ,
189+ colWidths : [ 7 , 9 ] , // Requires fixed column widths
190190 wordWrap : true ,
191191 } ) ;
192192
193- table . push ( [ 'Hello how are you?' , 'I am fine thanks!' ] ) ;
193+ table . push ( [
194+ 'Hello how are you?' ,
195+ 'I am fine thanks! Looooooong' ,
196+ [ 'Words that exceed' , 'the colWidth will' , 'be truncated.' ] . join ( '\n' ) ,
197+ [ 'Text is only' , 'wrapped for' , 'fixed width' , 'columns.' ] . join ( '\n' ) ,
198+ ] ) ;
194199
195200 return table ;
196201 }
197202
198203 let expected = [
199- '┌───────┬─────────┐' ,
200- '│ Hello │ I am │' ,
201- '│ how │ fine │' ,
202- '│ are │ thanks! │' ,
203- '│ you? │ │' ,
204- '└───────┴─────────┘' ,
204+ '┌───────┬─────────┬───────────────────┬──────────────┐' ,
205+ '│ Hello │ I am │ Words that exceed │ Text is only │' ,
206+ '│ how │ fine │ the colWidth will │ wrapped for │' ,
207+ '│ are │ thanks! │ be truncated. │ fixed width │' ,
208+ '│ you? │ Looooo… │ │ columns. │' ,
209+ '└───────┴─────────┴───────────────────┴──────────────┘' ,
210+ ] ;
211+
212+ return [ makeTable , expected ] ;
213+ } ) ;
214+
215+ it ( 'Using `wordWrap`, set `wrapOnWordBoundary` to false to ignore word boundaries' , function ( ) {
216+ function makeTable ( ) {
217+ const table = new Table ( {
218+ style : { border : [ ] , header : [ ] } ,
219+ colWidths : [ 3 , 3 ] , // colWidths must all be greater than 2!!!!
220+ wordWrap : true ,
221+ wrapOnWordBoundary : false ,
222+ } ) ;
223+ table . push ( [ 'Wrap' , 'Text' ] ) ;
224+ return table ;
225+ }
226+
227+ let expected = [
228+ '┌───┬───┐' ,
229+ '│ W │ T │' ,
230+ '│ r │ e │' ,
231+ '│ a │ x │' ,
232+ '│ p │ t │' ,
233+ '└───┴───┘' ,
205234 ] ;
206235
207236 return [ makeTable , expected ] ;
0 commit comments