96 lines
2.9 KiB
Go
96 lines
2.9 KiB
Go
package theme
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadEmbeddedThemesJSON_LoadsExpectedThemes(t *testing.T) {
|
|
themesJSON, err := LoadEmbeddedThemesJSON()
|
|
if err != nil {
|
|
t.Fatalf("LoadEmbeddedThemesJSON returned error: %v", err)
|
|
}
|
|
|
|
want := []string{"kanagawa", "kanagawa-dragon", "kanagawa-lotus"}
|
|
for _, name := range want {
|
|
th, ok := themesJSON[name]
|
|
if !ok {
|
|
t.Fatalf("expected embedded theme %q to be loaded", name)
|
|
}
|
|
if th.Name == "" {
|
|
t.Fatalf("expected embedded theme %q to have a name", name)
|
|
}
|
|
if th.Line.BG == "" {
|
|
t.Fatalf("expected embedded theme %q to include line background", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMapEmbeddedThemeToEditorTheme_MapsStylesAndNormalizesSyntaxKeys(t *testing.T) {
|
|
in := map[string]ThemeJSON{
|
|
"custom": {
|
|
Name: "custom",
|
|
Line: ColorStyleJSON{FG: "#dddddd", BG: "#101010"},
|
|
Background: ColorStyleJSON{BG: "#101010"},
|
|
VisualHighlight: ColorStyleJSON{BG: "#202020"},
|
|
Cursors: CursorJSON{
|
|
Normal: ColorStyleJSON{FG: "#101010", BG: "#dddddd"},
|
|
Insert: ColorStyleJSON{FG: "#101010", BG: "#cccccc"},
|
|
Command: ColorStyleJSON{FG: "#101010", BG: "#bbbbbb"},
|
|
Replace: ColorStyleJSON{FG: "#101010", BG: "#aaaaaa"},
|
|
},
|
|
Gutter: GutterJSON{
|
|
Default: ColorStyleJSON{FG: "#666666", BG: "#0a0a0a"},
|
|
CurrentLine: ColorStyleJSON{FG: "#eeeeee", BG: "#0a0a0a"},
|
|
},
|
|
StatusBar: StatusBarJSON{
|
|
Default: ColorStyleJSON{FG: "#cccccc", BG: "#0a0a0a"},
|
|
},
|
|
CommandLine: CommandLineJSON{
|
|
Error: ColorStyleJSON{FG: "#ff0000", BG: "#101010"},
|
|
OutputBorder: ColorStyleJSON{FG: "#dddddd", BG: "#0a0a0a"},
|
|
ContinueMessage: ColorStyleJSON{FG: "#00aaff", BG: "#101010"},
|
|
},
|
|
Syntax: SyntaxJSON{
|
|
Group: map[string]string{
|
|
" String ": "#00ff00",
|
|
},
|
|
Exact: map[string]string{
|
|
" @KEYWORD.Return ": "#ff00ff",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
out := MapEmbeddedThemeToEditorTheme(in)
|
|
th, ok := out["custom"]
|
|
if !ok {
|
|
t.Fatalf("expected mapped theme with key %q", "custom")
|
|
}
|
|
|
|
if got := colorHex(th.Line.GetForeground()); got != "#dddddd" {
|
|
t.Fatalf("line fg mismatch: got %q want %q", got, "#dddddd")
|
|
}
|
|
if got := colorHex(th.Line.GetBackground()); got != "#101010" {
|
|
t.Fatalf("line bg mismatch: got %q want %q", got, "#101010")
|
|
}
|
|
|
|
if got := colorHex(th.Syntax.Exact["keyword.return"].GetForeground()); got != "#ff00ff" {
|
|
t.Fatalf("exact capture fg mismatch: got %q want %q", got, "#ff00ff")
|
|
}
|
|
if got := colorHex(th.Syntax.Exact["keyword.return"].GetBackground()); got != "#101010" {
|
|
t.Fatalf("exact capture bg mismatch: got %q want %q", got, "#101010")
|
|
}
|
|
if got := colorHex(th.Syntax.Group["string"].GetForeground()); got != "#00ff00" {
|
|
t.Fatalf("group capture fg mismatch: got %q want %q", got, "#00ff00")
|
|
}
|
|
|
|
if got := colorHex(th.CommandLine.Error.GetForeground()); got != "#ff0000" {
|
|
t.Fatalf("command error fg mismatch: got %q want %q", got, "#ff0000")
|
|
}
|
|
}
|
|
|
|
func colorHex(c any) string {
|
|
return fmt.Sprint(c)
|
|
}
|