summaryrefslogtreecommitdiff
path: root/ui/style_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ui/style_test.go')
-rw-r--r--ui/style_test.go103
1 files changed, 87 insertions, 16 deletions
diff --git a/ui/style_test.go b/ui/style_test.go
index ae478ab..4ba2e9d 100644
--- a/ui/style_test.go
+++ b/ui/style_test.go
@@ -1,25 +1,96 @@
package ui
-import "testing"
+import (
+ "testing"
-func assertStringWidth(t *testing.T, input string, expected int) {
- actual := StringWidth(input)
- if actual != expected {
- t.Errorf("%q: expected width of %d got %d", input, expected, actual)
+ "github.com/gdamore/tcell/v2"
+)
+
+func assertIRCString(t *testing.T, input string, expected StyledString) {
+ actual := IRCString(input)
+ if actual.string != expected.string {
+ t.Errorf("%q: expected string %q, got %q", input, expected.string, actual.string)
+ }
+ if len(actual.styles) != len(expected.styles) {
+ t.Errorf("%q: expected %d styles, got %d", input, len(expected.styles), len(actual.styles))
+ return
+ }
+ for i := range actual.styles {
+ if actual.styles[i] != expected.styles[i] {
+ t.Errorf("%q: style #%d expected to be %+v, got %+v", input, i, expected.styles[i], actual.styles[i])
+ }
}
}
-func TestStringWidth(t *testing.T) {
- assertStringWidth(t, "", 0)
+func TestIRCString(t *testing.T) {
+ assertIRCString(t, "", StyledString{
+ string: "",
+ styles: nil,
+ })
- assertStringWidth(t, "hello", 5)
- assertStringWidth(t, "\x02hello", 5)
- assertStringWidth(t, "\x035hello", 5)
- assertStringWidth(t, "\x0305hello", 5)
- assertStringWidth(t, "\x0305,0hello", 5)
- assertStringWidth(t, "\x0305,09hello", 5)
+ assertIRCString(t, "hello", StyledString{
+ string: "hello",
+ styles: nil,
+ })
+ assertIRCString(t, "\x02hello", StyledString{
+ string: "hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Bold(true)},
+ },
+ })
+ assertIRCString(t, "\x035hello", StyledString{
+ string: "hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown)},
+ },
+ })
+ assertIRCString(t, "\x0305hello", StyledString{
+ string: "hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown)},
+ },
+ })
+ assertIRCString(t, "\x0305,0hello", StyledString{
+ string: "hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown).Background(tcell.ColorWhite)},
+ },
+ })
+ assertIRCString(t, "\x035,00hello", StyledString{
+ string: "hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown).Background(tcell.ColorWhite)},
+ },
+ })
+ assertIRCString(t, "\x0305,00hello", StyledString{
+ string: "hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown).Background(tcell.ColorWhite)},
+ },
+ })
- assertStringWidth(t, "\x0305,hello", 6)
- assertStringWidth(t, "\x03050hello", 6)
- assertStringWidth(t, "\x0305,090hello", 6)
+ assertIRCString(t, "\x035,hello", StyledString{
+ string: ",hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown)},
+ },
+ })
+ assertIRCString(t, "\x0305,hello", StyledString{
+ string: ",hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown)},
+ },
+ })
+ assertIRCString(t, "\x03050hello", StyledString{
+ string: "0hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown)},
+ },
+ })
+ assertIRCString(t, "\x0305,000hello", StyledString{
+ string: "0hello",
+ styles: []rangedStyle{
+ rangedStyle{Start: 0, Style: tcell.StyleDefault.Foreground(tcell.ColorBrown).Background(tcell.ColorWhite)},
+ },
+ })
}