github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/sqle/sqlfmt/schema_fmt_test.go (about) 1 // Copyright 2020 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sqlfmt 16 17 import ( 18 "github.com/dolthub/dolt/go/libraries/doltcore/schema" 19 "github.com/dolthub/dolt/go/store/types" 20 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestFmtCol(t *testing.T) { 27 tests := []struct { 28 Col schema.Column 29 Indent int 30 NameWidth int 31 TypeWidth int 32 Expected string 33 }{ 34 { 35 schema.NewColumn("first", 0, types.StringKind, true), 36 0, 37 0, 38 0, 39 "`first` LONGTEXT", 40 }, 41 { 42 schema.NewColumn("last", 123, types.IntKind, true), 43 2, 44 0, 45 0, 46 " `last` BIGINT", 47 }, 48 { 49 schema.NewColumn("title", 2, types.UintKind, true), 50 0, 51 10, 52 0, 53 " `title` BIGINT UNSIGNED", 54 }, 55 { 56 schema.NewColumn("aoeui", 52, types.UintKind, true), 57 0, 58 10, 59 15, 60 " `aoeui` BIGINT UNSIGNED", 61 }, 62 } 63 64 for _, test := range tests { 65 t.Run(test.Expected, func(t *testing.T) { 66 actual := FmtCol(test.Indent, test.NameWidth, test.TypeWidth, test.Col) 67 assert.Equal(t, test.Expected, actual) 68 }) 69 } 70 }