Skip to content

Commit dbe7734

Browse files
committed
Updated test for Alignment #272
1 parent 3f6d202 commit dbe7734

File tree

13 files changed

+107
-105
lines changed

13 files changed

+107
-105
lines changed

tablewriter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func TestMergeCellConfig(t *testing.T) {
419419
Build().Header, // Src AutoFormat = tw.On (1) from defaultConfig().Header
420420
expectedConfig: func() tw.CellConfig {
421421
cfg := getTestSectionDefaultConfig("row")
422-
cfg.Formatting.Alignment = tw.AlignCenter
422+
cfg.Alignment.Global = tw.AlignCenter
423423
cfg.Formatting.AutoWrap = tw.WrapTruncate // from defaultConfig().Header
424424
cfg.Formatting.AutoFormat = tw.On // from src (Builder's Header)
425425
cfg.Formatting.MergeMode = tw.MergeHorizontal

tests/basic_test.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -418,23 +418,23 @@ func TestLongValues(t *testing.T) {
418418
c := tablewriter.Config{
419419
Header: tw.CellConfig{
420420
Formatting: tw.CellFormatting{
421-
Alignment: tw.AlignCenter,
422421
AutoFormat: tw.On,
423422
},
423+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
424424
ColMaxWidths: tw.CellWidth{Global: 30},
425425
},
426426
Row: tw.CellConfig{
427427
Formatting: tw.CellFormatting{
428-
AutoWrap: tw.WrapNormal,
429-
Alignment: tw.AlignLeft,
428+
AutoWrap: tw.WrapNormal,
430429
},
430+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
431431
ColMaxWidths: tw.CellWidth{Global: 30},
432432
},
433433
Footer: tw.CellConfig{
434-
Formatting: tw.CellFormatting{
435-
Alignment: tw.AlignRight,
434+
Alignment: tw.CellAlignment{
435+
Global: tw.AlignRight,
436+
PerColumn: []tw.Align{tw.Skip, tw.Skip, tw.Skip, tw.AlignLeft},
436437
},
437-
ColumnAligns: []tw.Align{tw.Skip, tw.Skip, tw.Skip, tw.AlignLeft},
438438
},
439439
}
440440

@@ -487,21 +487,19 @@ func TestWrapping(t *testing.T) {
487487
c := tablewriter.Config{
488488
Header: tw.CellConfig{
489489
Formatting: tw.CellFormatting{
490-
Alignment: tw.AlignCenter,
491490
AutoFormat: tw.On,
492491
},
492+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
493493
},
494494
Row: tw.CellConfig{
495495
Formatting: tw.CellFormatting{
496-
AutoWrap: tw.WrapBreak,
497-
Alignment: tw.AlignLeft,
496+
AutoWrap: tw.WrapBreak,
498497
},
498+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
499499
ColMaxWidths: tw.CellWidth{Global: 33},
500500
},
501501
Footer: tw.CellConfig{
502-
Formatting: tw.CellFormatting{
503-
Alignment: tw.AlignRight,
504-
},
502+
Alignment: tw.CellAlignment{Global: tw.AlignRight},
505503
ColMaxWidths: tw.CellWidth{Global: 30},
506504
},
507505
}
@@ -537,26 +535,24 @@ func TestTableWithCustomPadding(t *testing.T) {
537535
c := tablewriter.Config{
538536
Header: tw.CellConfig{
539537
Formatting: tw.CellFormatting{
540-
Alignment: tw.AlignCenter,
541538
AutoFormat: tw.On,
542539
},
540+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
543541
Padding: tw.CellPadding{
544542
Global: tw.Padding{Left: " ", Right: " ", Top: "^", Bottom: "^"},
545543
},
546544
},
547545
Row: tw.CellConfig{
548-
Formatting: tw.CellFormatting{
549-
Alignment: tw.AlignCenter,
550-
},
546+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
551547
Padding: tw.CellPadding{
552548
Global: tw.Padding{Left: "L", Right: "R", Top: "T", Bottom: "B"},
553549
},
554550
},
555551
Footer: tw.CellConfig{
556552
Formatting: tw.CellFormatting{
557-
Alignment: tw.AlignCenter,
558553
AutoFormat: tw.On,
559554
},
555+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
560556
Padding: tw.CellPadding{
561557
Global: tw.Padding{Left: "*", Right: "*", Top: "", Bottom: ""},
562558
},
@@ -653,7 +649,11 @@ C │ D
653649
},
654650
)
655651
st := tablewriter.NewTable(&buf,
656-
tablewriter.WithConfig(tablewriter.Config{Row: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignLeft}}, Widths: tw.CellWidth{PerColumn: widths}}),
652+
tablewriter.WithConfig(tablewriter.Config{
653+
Row: tw.CellConfig{
654+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
655+
},
656+
Widths: tw.CellWidth{PerColumn: widths}}),
657657
tablewriter.WithRenderer(r),
658658
tablewriter.WithDebug(false),
659659
tablewriter.WithStreaming(tw.StreamConfig{Enable: true}),
@@ -784,7 +784,7 @@ func TestAlignmentMigration(t *testing.T) {
784784
buf.Reset()
785785
table := tablewriter.NewTable(buf)
786786
table.Configure(func(cfg *tablewriter.Config) {
787-
cfg.Footer.Formatting.Alignment = tw.AlignRight
787+
cfg.Footer.Alignment.Global = tw.AlignRight
788788
cfg.Stream.Enable = true
789789
})
790790
table.Start()
@@ -809,5 +809,4 @@ func TestAlignmentMigration(t *testing.T) {
809809
t.Fatal("StreamBasic rendering failed")
810810
}
811811
})
812-
813812
}

tests/bug_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func TestBug271(t *testing.T) {
314314
Formatting: tw.CellFormatting{
315315
MergeMode: tw.MergeHorizontal,
316316
},
317-
ColumnAligns: []tw.Align{tw.Skip, tw.Skip, tw.AlignRight, tw.AlignLeft},
317+
Alignment: tw.CellAlignment{PerColumn: []tw.Align{tw.Skip, tw.Skip, tw.AlignRight, tw.AlignLeft}},
318318
},
319319
}),
320320
tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{

tests/colorized_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestColorizedCustomColors(t *testing.T) {
8888
},
8989
})),
9090
tablewriter.WithFooterConfig(tw.CellConfig{
91-
ColumnAligns: []tw.Align{tw.AlignRight, tw.AlignCenter}, // Align "1" to center
91+
Alignment: tw.CellAlignment{PerColumn: []tw.Align{tw.AlignRight, tw.AlignCenter}},
9292
}),
9393
)
9494
table.Header([]string{"Name", "Age"})
@@ -116,9 +116,9 @@ func TestColorizedLongValues(t *testing.T) {
116116
c := tablewriter.Config{
117117
Row: tw.CellConfig{
118118
Formatting: tw.CellFormatting{
119-
AutoWrap: tw.WrapNormal,
120-
Alignment: tw.AlignLeft,
119+
AutoWrap: tw.WrapNormal,
121120
},
121+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
122122
ColMaxWidths: tw.CellWidth{Global: 20},
123123
},
124124
}

tests/csv_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ func TestTable_Configure_Basic(t *testing.T) {
4141
}
4242

4343
table.Configure(func(cfg *tablewriter.Config) {
44-
cfg.Header.Formatting.Alignment = tw.AlignLeft
45-
cfg.Row.Formatting.Alignment = tw.AlignRight
44+
cfg.Header.Alignment.Global = tw.AlignLeft
45+
cfg.Row.Alignment.Global = tw.AlignRight
4646
cfg.Behavior.TrimSpace = tw.Off
4747
cfg.Debug = true // This should enable the logger
4848
})
4949

5050
// Check that Table.config was updated
51-
if table.Config().Header.Formatting.Alignment != tw.AlignLeft {
52-
t.Errorf("Expected configured header alignment to be Left, got %s", table.Config().Header.Formatting.Alignment)
51+
if table.Config().Header.Alignment.Global != tw.AlignLeft {
52+
t.Errorf("Expected configured header alignment to be Left, got %s", table.Config().Header.Alignment.Global)
5353
}
54-
if table.Config().Row.Formatting.Alignment != tw.AlignRight {
55-
t.Errorf("Expected configured row alignment to be Right, got %s", table.Config().Row.Formatting.Alignment)
54+
if table.Config().Row.Alignment.Global != tw.AlignRight {
55+
t.Errorf("Expected configured row alignment to be Right, got %s", table.Config().Row.Alignment.Global)
5656
}
5757
if table.Config().Behavior.TrimSpace != tw.Off {
5858
t.Errorf("Expected configured TrimSpace to be Off, got %s", table.Config().Behavior.TrimSpace)

tests/extra_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ func TestFilterMasking(t *testing.T) {
7070
var buf bytes.Buffer
7171
table := tablewriter.NewTable(&buf, tablewriter.WithConfig(tablewriter.Config{
7272
Header: tw.CellConfig{
73-
Formatting: tw.CellFormatting{Alignment: tw.AlignCenter, AutoFormat: tw.On},
73+
Formatting: tw.CellFormatting{AutoFormat: tw.On},
74+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
7475
Padding: tw.CellPadding{Global: tw.Padding{Left: " ", Right: " "}},
7576
},
7677
Row: tw.CellConfig{
77-
Formatting: tw.CellFormatting{Alignment: tw.AlignLeft},
78-
Padding: tw.CellPadding{Global: tw.Padding{Left: " ", Right: " "}},
78+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
79+
Padding: tw.CellPadding{Global: tw.Padding{Left: " ", Right: " "}},
7980
Filter: tw.CellFilter{
8081
Global: tt.filter,
8182
},
@@ -102,9 +103,7 @@ func TestMasterClass(t *testing.T) {
102103
littleConfig := tablewriter.Config{
103104
MaxWidth: 30,
104105
Row: tw.CellConfig{
105-
Formatting: tw.CellFormatting{
106-
Alignment: tw.AlignCenter,
107-
},
106+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
108107
Padding: tw.CellPadding{
109108
Global: tw.Padding{Left: tw.Skip, Right: tw.Skip, Top: tw.Skip, Bottom: tw.Skip},
110109
},
@@ -117,9 +116,7 @@ func TestMasterClass(t *testing.T) {
117116
AutoWrap: tw.WrapTruncate,
118117
}},
119118
Row: tw.CellConfig{
120-
Formatting: tw.CellFormatting{
121-
Alignment: tw.AlignCenter,
122-
},
119+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
123120
Padding: tw.CellPadding{
124121
Global: tw.Padding{Left: tw.Skip, Right: tw.Skip, Top: tw.Skip, Bottom: tw.Skip},
125122
},
@@ -353,8 +350,8 @@ func TestEmojiTable(t *testing.T) {
353350
table.Bulk(data)
354351
table.Footer([]string{"", "Total 👥", "3"})
355352
table.Configure(func(config *tablewriter.Config) {
356-
config.Row.Formatting.Alignment = tw.AlignLeft
357-
config.Footer.Formatting.Alignment = tw.AlignRight
353+
config.Row.Alignment.Global = tw.AlignLeft
354+
config.Footer.Alignment.Global = tw.AlignRight
358355
})
359356
table.Render()
360357

tests/html_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ func TestHTMLWithFooterAndAlignment(t *testing.T) {
4242
tablewriter.WithRenderer(renderer.NewHTML()),
4343
tablewriter.WithHeaderConfig(tw.CellConfig{
4444
Formatting: tw.CellFormatting{
45-
Alignment: tw.AlignCenter,
4645
AutoFormat: tw.Off,
4746
},
47+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
4848
}),
4949
tablewriter.WithRowConfig(tw.CellConfig{
50-
ColumnAligns: []tw.Align{tw.AlignLeft, tw.AlignRight, tw.AlignCenter},
50+
Alignment: tw.CellAlignment{PerColumn: []tw.Align{tw.AlignLeft, tw.AlignRight, tw.AlignCenter}},
5151
}),
5252
tablewriter.WithFooterConfig(tw.CellConfig{
53-
Formatting: tw.CellFormatting{Alignment: tw.AlignRight},
53+
Alignment: tw.CellAlignment{Global: tw.AlignRight},
5454
}),
5555
)
5656
table.Header([]string{"Item", "Qty", "Price"})
@@ -289,8 +289,8 @@ func TestHTMLHierarchicalMerge(t *testing.T) {
289289
tablewriter.WithHeaderConfig(tw.CellConfig{
290290
Formatting: tw.CellFormatting{
291291
AutoFormat: tw.Off,
292-
Alignment: tw.AlignCenter,
293292
},
293+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
294294
}),
295295
)
296296
table.Header([]string{"L1", "L2", "L3"})
@@ -364,7 +364,8 @@ func TestHTMLCSSClasses(t *testing.T) {
364364
table := tablewriter.NewTable(&buf,
365365
tablewriter.WithRenderer(renderer.NewHTML(htmlCfg)),
366366
tablewriter.WithHeaderConfig(tw.CellConfig{
367-
Formatting: tw.CellFormatting{AutoFormat: tw.Off, Alignment: tw.AlignCenter},
367+
Formatting: tw.CellFormatting{AutoFormat: tw.Off},
368+
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
368369
}),
369370
)
370371
table.Header([]string{"H1"})

tests/markdown_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestMarkdownAlignment(t *testing.T) {
3535
table := tablewriter.NewTable(&buf,
3636
tablewriter.WithRenderer(renderer.NewMarkdown()),
3737
tablewriter.WithConfig(tablewriter.Config{Header: tw.CellConfig{
38-
ColumnAligns: []tw.Align{tw.AlignLeft, tw.AlignRight, tw.AlignRight, tw.AlignCenter}},
38+
Alignment: tw.CellAlignment{PerColumn: []tw.Align{tw.AlignLeft, tw.AlignRight, tw.AlignRight, tw.AlignCenter}}},
3939
}),
4040
)
4141
table.Header([]string{"Name", "Age", "City", "Status"})
@@ -61,7 +61,7 @@ func TestMarkdownNoBorders(t *testing.T) {
6161
Borders: tw.Border{Left: tw.Off, Right: tw.Off, Top: tw.Off, Bottom: tw.Off},
6262
})),
6363
tablewriter.WithConfig(tablewriter.Config{Header: tw.CellConfig{
64-
ColumnAligns: []tw.Align{tw.AlignLeft}},
64+
Alignment: tw.CellAlignment{PerColumn: []tw.Align{tw.AlignLeft}}},
6565
}),
6666
)
6767

@@ -134,9 +134,9 @@ func TestMarkdownLongValues(t *testing.T) {
134134
c := tablewriter.Config{
135135
Row: tw.CellConfig{
136136
Formatting: tw.CellFormatting{
137-
AutoWrap: tw.WrapNormal,
138-
Alignment: tw.AlignLeft,
137+
AutoWrap: tw.WrapNormal,
139138
},
139+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
140140
ColMaxWidths: tw.CellWidth{Global: 20},
141141
},
142142
}
@@ -238,9 +238,7 @@ func TestMarkdownWithFooter(t *testing.T) {
238238
var buf bytes.Buffer
239239
c := tablewriter.Config{
240240
Footer: tw.CellConfig{
241-
Formatting: tw.CellFormatting{
242-
Alignment: tw.AlignRight,
243-
},
241+
Alignment: tw.CellAlignment{Global: tw.AlignRight},
244242
},
245243
}
246244
table := tablewriter.NewTable(&buf,

0 commit comments

Comments
 (0)