github.com/wrgl/wrgl@v0.14.0/pkg/widgets/table_column_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright © 2022 Wrangle Ltd 3 4 package widgets 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestTableColumn(t *testing.T) { 13 tc := newTableColumn() 14 tc.UpdateWidths(0, []int{10}) 15 tc.UpdateWidths(5, []int{20}) 16 tc.UpdateExpansions(0, []int{1}) 17 tc.UpdateWidths(11, []int{10, 30}) 18 tc.UpdateExpansions(11, []int{1, 2}) 19 tc.UpdateWidths(15, []int{20, 10, 10}) 20 tc.UpdateExpansions(15, []int{0, 0, 0}) 21 assert.Equal(t, []int{20}, tc.Widths(0)) 22 assert.Equal(t, []int{20}, tc.Widths(10)) 23 assert.Equal(t, []int{10, 30}, tc.Widths(11)) 24 assert.Equal(t, []int{10, 30}, tc.Widths(12)) 25 assert.Equal(t, []int{20, 10, 10}, tc.Widths(15)) 26 assert.Equal(t, []int{20, 10, 10}, tc.Widths(20)) 27 28 tc.DistributeWidth() 29 assert.Equal(t, 42, tc.Width) 30 assert.Equal(t, []int{42}, tc.Widths(0)) 31 assert.Equal(t, []int{10, 31}, tc.Widths(11)) 32 assert.Equal(t, []int{20, 10, 10}, tc.Widths(15)) 33 34 tc.DistributeExpansionWidth(30) 35 assert.Equal(t, 72, tc.Width) 36 assert.Equal(t, []int{72}, tc.Widths(0)) 37 assert.Equal(t, []int{20, 51}, tc.Widths(11)) 38 assert.Equal(t, []int{30, 20, 20}, tc.Widths(15)) 39 40 // tc.UpdateWidths([]int{7, 7}) 41 // tc.UpdateExpansions([]int{1, 1}) 42 // assert.Equal(t, []int{7, 7}, tc.Widths()) 43 // tc.DistributeWidth() 44 // assert.Equal(t, []int{9, 10}, tc.Widths()) 45 // assert.Equal(t, []int{-1}, tc.CellWidths(0)) 46 // assert.Equal(t, []int{20}, tc.CellWidths(1)) 47 // assert.Equal(t, []int{9, 10}, tc.CellWidths(2)) 48 // tc.DistributeExpansionWidth(4) 49 // assert.Equal(t, []int{11, 12}, tc.Widths()) 50 // tc.UpdateWidths([]int{14, 16}) 51 // tc.DistributeWidth() 52 // assert.Equal(t, 31, tc.Width) 53 }