@@ -112,20 +112,64 @@ A Song of Ice and Fire`)
112112}
113113
114114func TestTable_Render_Align (t * testing.T ) {
115- tw := NewWriter ()
116- tw .AppendHeader (testHeader )
117- tw .AppendRows (testRows )
118- tw .AppendRow (Row {500 , "Jamie" , "Lannister" , "Kingslayer" , "The things I do for love." })
119- tw .AppendRow (Row {1000 , "Tywin" , "Lannister" , nil })
120- tw .AppendFooter (testFooter )
121- tw .SetColumnConfigs ([]ColumnConfig {
122- {Name : "First Name" , Align : text .AlignLeft , AlignHeader : text .AlignLeft , AlignFooter : text .AlignLeft },
123- {Name : "Last Name" , Align : text .AlignRight , AlignHeader : text .AlignRight , AlignFooter : text .AlignRight },
124- {Name : "Salary" , Align : text .AlignAuto , AlignHeader : text .AlignRight , AlignFooter : text .AlignAuto },
125- {Number : 5 , Align : text .AlignJustify , AlignHeader : text .AlignJustify , AlignFooter : text .AlignJustify },
115+ t .Run ("defaults" , func (t * testing.T ) {
116+ tw := NewWriter ()
117+ tw .AppendHeader (Row {"#" , "First\n Name" , "Last\n Name" , "Final\n State" , "Misc.\n Multi-line\n Notes" })
118+ tw .AppendRows ([]Row {
119+ {1 , "Arya" , "Stark" , ":) 8)" },
120+ {20 , "Jon" , "Snow" , ":( :( :(" , "You know nothing, Jon Snow!" },
121+ {300 , "Tyrion" , "Lannister" , ":)" },
122+ })
123+ tw .AppendFooter (Row {"#" , "First\n Name" , "Last\n Name" , "Final\n State" , "Misc.\n Multi-line\n Notes" })
124+ tw .Style ().Format = FormatOptions {
125+ FooterAlign : text .AlignRight ,
126+ FooterVAlign : text .VAlignTop ,
127+ HeaderAlign : text .AlignLeft ,
128+ HeaderVAlign : text .VAlignBottom ,
129+ RowAlign : text .AlignCenter ,
130+ RowVAlign : text .VAlignMiddle ,
131+ }
132+ tw .SetColumnConfigs ([]ColumnConfig { // takes precedence
133+ {
134+ Name : "Final\n State" ,
135+ Align : text .AlignLeft , VAlign : text .VAlignTop ,
136+ AlignHeader : text .AlignLeft , VAlignHeader : text .VAlignTop ,
137+ AlignFooter : text .AlignLeft , VAlignFooter : text .VAlignBottom ,
138+ },
139+ })
140+
141+ compareOutput (t , tw .Render (), `
142+ +-----+--------+-----------+----------+-----------------------------+
143+ | | | | Final | Misc. |
144+ | | First | Last | State | Multi-line |
145+ | # | Name | Name | | Notes |
146+ +-----+--------+-----------+----------+-----------------------------+
147+ | 1 | Arya | Stark | :) 8) | |
148+ | 20 | Jon | Snow | :( :( :( | You know nothing, Jon Snow! |
149+ | 300 | Tyrion | Lannister | :) | |
150+ +-----+--------+-----------+----------+-----------------------------+
151+ | # | First | Last | | Misc. |
152+ | | Name | Name | Final | Multi-line |
153+ | | | | State | Notes |
154+ +-----+--------+-----------+----------+-----------------------------+` )
155+
126156 })
127157
128- compareOutput (t , tw .Render (), `
158+ t .Run ("column overrides" , func (t * testing.T ) {
159+ tw := NewWriter ()
160+ tw .AppendHeader (testHeader )
161+ tw .AppendRows (testRows )
162+ tw .AppendRow (Row {500 , "Jamie" , "Lannister" , "Kingslayer" , "The things I do for love." })
163+ tw .AppendRow (Row {1000 , "Tywin" , "Lannister" , nil })
164+ tw .AppendFooter (testFooter )
165+ tw .SetColumnConfigs ([]ColumnConfig {
166+ {Name : "First Name" , Align : text .AlignLeft , AlignHeader : text .AlignLeft , AlignFooter : text .AlignLeft },
167+ {Name : "Last Name" , Align : text .AlignRight , AlignHeader : text .AlignRight , AlignFooter : text .AlignRight },
168+ {Name : "Salary" , Align : text .AlignAuto , AlignHeader : text .AlignRight , AlignFooter : text .AlignAuto },
169+ {Number : 5 , Align : text .AlignJustify , AlignHeader : text .AlignJustify , AlignFooter : text .AlignJustify },
170+ })
171+
172+ compareOutput (t , tw .Render (), `
129173+------+------------+-----------+------------+-----------------------------+
130174| # | FIRST NAME | LAST NAME | SALARY | |
131175+------+------------+-----------+------------+-----------------------------+
@@ -137,6 +181,7 @@ func TestTable_Render_Align(t *testing.T) {
137181+------+------------+-----------+------------+-----------------------------+
138182| | | TOTAL | 10000 | |
139183+------+------------+-----------+------------+-----------------------------+` )
184+ })
140185}
141186
142187func TestTable_Render_AutoIndex (t * testing.T ) {
0 commit comments