Debian Codegraph @

tests/blueprint_test.go

raw
1 package tests
2
3 import (
4 "testing"
5
6 "github.com/olekukonko/tablewriter/renderer"
7 "github.com/olekukonko/tablewriter/tw"
8 )
9
10 func TestDefaultConfigMerging(t *testing.T) {
11 tests := []struct {
12 name string
13 config tw.Rendition
14 expected tw.Rendition
15 }{
16 {
17 name: "EmptyConfig",
18 config: tw.Rendition{},
19 expected: tw.Rendition{
20 Borders: tw.Border{Left: tw.On, Right: tw.On, Top: tw.On, Bottom: tw.On},
21 Settings: tw.Settings{
22 Separators: tw.Separators{
23 ShowHeader: tw.On,
24 ShowFooter: tw.On,
25 BetweenRows: tw.Off,
26 BetweenColumns: tw.On,
27 },
28 Lines: tw.Lines{
29 ShowTop: tw.On,
30 ShowBottom: tw.On,
31 ShowHeaderLine: tw.On,
32 ShowFooterLine: tw.On,
33 },
34 // TrimWhitespace: tw.On,
35 CompactMode: tw.Off,
36 },
37 Symbols: tw.NewSymbols(tw.StyleLight),
38 },
39 },
40 {
41 name: "PartialBorders",
42 config: tw.Rendition{
43 Borders: tw.Border{Top: tw.Off},
44 },
45 expected: tw.Rendition{
46 Borders: tw.Border{Left: tw.On, Right: tw.On, Top: tw.Off, Bottom: tw.On},
47 Settings: tw.Settings{
48 Separators: tw.Separators{
49 ShowHeader: tw.On,
50 ShowFooter: tw.On,
51 BetweenRows: tw.Off,
52 BetweenColumns: tw.On,
53 },
54 Lines: tw.Lines{
55 ShowTop: tw.On,
56 ShowBottom: tw.On,
57 ShowHeaderLine: tw.On,
58 ShowFooterLine: tw.On,
59 },
60 // TrimWhitespace: tw.On,
61 CompactMode: tw.Off,
62 },
63 Symbols: tw.NewSymbols(tw.StyleLight),
64 },
65 },
66 {
67 name: "PartialSettingsLines",
68 config: tw.Rendition{
69 Settings: tw.Settings{
70 Lines: tw.Lines{ShowFooterLine: tw.Off},
71 },
72 },
73 expected: tw.Rendition{
74 Borders: tw.Border{Left: tw.On, Right: tw.On, Top: tw.On, Bottom: tw.On},
75 Settings: tw.Settings{
76 Separators: tw.Separators{
77 ShowHeader: tw.On,
78 ShowFooter: tw.On,
79 BetweenRows: tw.Off,
80 BetweenColumns: tw.On,
81 },
82 Lines: tw.Lines{
83 ShowTop: tw.On,
84 ShowBottom: tw.On,
85 ShowHeaderLine: tw.On,
86 ShowFooterLine: tw.Off,
87 },
88 // TrimWhitespace: tw.On,
89 CompactMode: tw.Off,
90 },
91 Symbols: tw.NewSymbols(tw.StyleLight),
92 },
93 },
94 }
95
96 for _, tt := range tests {
97 t.Run(tt.name, func(t *testing.T) {
98 r := renderer.NewBlueprint(tt.config)
99 got := r.Config()
100
101 // Compare Borders
102 if got.Borders != tt.expected.Borders {
103 t.Errorf("%s: Borders mismatch - expected %+v, got %+v", tt.name, tt.expected.Borders, got.Borders)
104 }
105 // Compare Settings.Lines
106 if got.Settings.Lines != tt.expected.Settings.Lines {
107 t.Errorf("%s: Settings.Lines mismatch - expected %+v, got %+v", tt.name, tt.expected.Settings.Lines, got.Settings.Lines)
108 }
109 // Compare Settings.Separators
110 if got.Settings.Separators != tt.expected.Settings.Separators {
111 t.Errorf("%s: Settings.Separators mismatch - expected %+v, got %+v", tt.name, tt.expected.Settings.Separators, got.Settings.Separators)
112 }
113 // Check Symbols (basic presence check)
114 if (tt.expected.Symbols == nil) != (got.Symbols == nil) {
115 t.Errorf("%s: Symbols mismatch - expected nil: %v, got nil: %v", tt.name, tt.expected.Symbols == nil, got.Symbols == nil)
116 }
117 })
118 }
119 }