mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 19:27:58 +08:00
67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package styled
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/elves/elvish/tt"
|
|
)
|
|
|
|
func TestTransform(t *testing.T) {
|
|
tt.Test(t, tt.Fn("Transform", Transform), tt.Table{
|
|
// Foreground color
|
|
tt.Args(Unstyled("foo"), "red").
|
|
Rets(Text{&Segment{Style{Foreground: "red"}, "foo"}}),
|
|
// Override existing foreground
|
|
tt.Args(Text{&Segment{Style{Foreground: "green"}, "foo"}}, "red").
|
|
Rets(Text{&Segment{Style{Foreground: "red"}, "foo"}}),
|
|
// Multiple segments
|
|
tt.Args(Text{
|
|
&Segment{Style{}, "foo"},
|
|
&Segment{Style{Foreground: "green"}, "bar"}}, "red").
|
|
Rets(Text{
|
|
&Segment{Style{Foreground: "red"}, "foo"},
|
|
&Segment{Style{Foreground: "red"}, "bar"},
|
|
}),
|
|
// Background color
|
|
tt.Args(Unstyled("foo"), "bg-red").
|
|
Rets(Text{&Segment{Style{Background: "red"}, "foo"}}),
|
|
// Bold, false -> true
|
|
tt.Args(Unstyled("foo"), "bold").
|
|
Rets(Text{&Segment{Style{Bold: true}, "foo"}}),
|
|
// Bold, true -> true
|
|
tt.Args(Text{&Segment{Style{Bold: true}, "foo"}}, "bold").
|
|
Rets(Text{&Segment{Style{Bold: true}, "foo"}}),
|
|
// No Bold, true -> false
|
|
tt.Args(Text{&Segment{Style{Bold: true}, "foo"}}, "no-bold").
|
|
Rets(Text{&Segment{Style{}, "foo"}}),
|
|
// No Bold, false -> false
|
|
tt.Args(Unstyled("foo"), "no-bold").Rets(Unstyled("foo")),
|
|
// Toggle Bold, true -> false
|
|
tt.Args(Text{&Segment{Style{Bold: true}, "foo"}}, "toggle-bold").
|
|
Rets(Text{&Segment{Style{}, "foo"}}),
|
|
// Toggle Bold, false -> true
|
|
tt.Args(Unstyled("foo"), "toggle-bold").
|
|
Rets(Text{&Segment{Style{Bold: true}, "foo"}}),
|
|
// For the remaining bool transformers, we only check one case; the rest
|
|
// should be similar to "bold".
|
|
// Dim.
|
|
tt.Args(Unstyled("foo"), "dim").
|
|
Rets(Text{&Segment{Style{Dim: true}, "foo"}}),
|
|
// Italic.
|
|
tt.Args(Unstyled("foo"), "italic").
|
|
Rets(Text{&Segment{Style{Italic: true}, "foo"}}),
|
|
// Underlined.
|
|
tt.Args(Unstyled("foo"), "underlined").
|
|
Rets(Text{&Segment{Style{Underlined: true}, "foo"}}),
|
|
// Blink.
|
|
tt.Args(Unstyled("foo"), "blink").
|
|
Rets(Text{&Segment{Style{Blink: true}, "foo"}}),
|
|
// Inverse.
|
|
tt.Args(Unstyled("foo"), "inverse").
|
|
Rets(Text{&Segment{Style{Inverse: true}, "foo"}}),
|
|
// Invalid transformer
|
|
tt.Args(Unstyled("foo"), "invalid").
|
|
Rets(Text{&Segment{Text: "foo"}}),
|
|
})
|
|
}
|