2018-04-15 06:06:57 +08:00
|
|
|
// Copyright 2018 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-03-29 02:34:20 +08:00
|
|
|
package cell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/kylelemons/godebug/pretty"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewOptions(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
opts []Option
|
|
|
|
want *Options
|
|
|
|
}{
|
|
|
|
{
|
2020-11-14 13:39:44 +08:00
|
|
|
|
2018-03-29 02:34:20 +08:00
|
|
|
desc: "no provided options",
|
|
|
|
want: &Options{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "setting foreground color",
|
|
|
|
opts: []Option{
|
|
|
|
FgColor(ColorBlack),
|
|
|
|
},
|
|
|
|
want: &Options{
|
|
|
|
FgColor: ColorBlack,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "setting background color",
|
|
|
|
opts: []Option{
|
|
|
|
BgColor(ColorRed),
|
|
|
|
},
|
|
|
|
want: &Options{
|
|
|
|
BgColor: ColorRed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "setting multiple options",
|
|
|
|
opts: []Option{
|
|
|
|
FgColor(ColorCyan),
|
|
|
|
BgColor(ColorMagenta),
|
|
|
|
},
|
|
|
|
want: &Options{
|
|
|
|
FgColor: ColorCyan,
|
|
|
|
BgColor: ColorMagenta,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-02-25 05:29:44 +08:00
|
|
|
desc: "setting options by passing the options struct",
|
2018-03-29 02:34:20 +08:00
|
|
|
opts: []Option{
|
2019-02-25 05:29:44 +08:00
|
|
|
&Options{
|
2018-03-29 02:34:20 +08:00
|
|
|
FgColor: ColorCyan,
|
|
|
|
BgColor: ColorMagenta,
|
|
|
|
},
|
|
|
|
},
|
2019-02-25 05:29:44 +08:00
|
|
|
want: &Options{
|
|
|
|
FgColor: ColorCyan,
|
|
|
|
BgColor: ColorMagenta,
|
2018-05-21 05:47:37 +08:00
|
|
|
},
|
|
|
|
},
|
2020-11-14 13:39:44 +08:00
|
|
|
{
|
|
|
|
desc: "setting font attributes",
|
|
|
|
opts: []Option{
|
|
|
|
Bold(),
|
|
|
|
Italic(),
|
|
|
|
Underline(),
|
|
|
|
Strikethrough(),
|
2020-11-17 21:33:36 +08:00
|
|
|
Inverse(),
|
|
|
|
Blink(),
|
2022-07-01 11:52:23 +08:00
|
|
|
Dim(),
|
2020-11-14 13:39:44 +08:00
|
|
|
},
|
|
|
|
want: &Options{
|
|
|
|
Bold: true,
|
|
|
|
Italic: true,
|
|
|
|
Underline: true,
|
|
|
|
Strikethrough: true,
|
2020-11-17 21:33:36 +08:00
|
|
|
Inverse: true,
|
|
|
|
Blink: true,
|
2022-07-01 11:52:23 +08:00
|
|
|
Dim: true,
|
2020-11-14 13:39:44 +08:00
|
|
|
},
|
|
|
|
},
|
2018-05-21 05:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
2019-02-25 05:29:44 +08:00
|
|
|
got := NewOptions(tc.opts...)
|
2018-05-21 05:47:37 +08:00
|
|
|
if diff := pretty.Compare(tc.want, got); diff != "" {
|
2019-02-25 05:29:44 +08:00
|
|
|
t.Errorf("NewOptions => unexpected diff (-want, +got):\n%s", diff)
|
2018-05-21 05:47:37 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|