|
| 1 | +package styles |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/alecthomas/assert/v2" |
| 8 | + "github.com/alecthomas/chroma/v2" |
| 9 | +) |
| 10 | + |
| 11 | +func TestStyleRegistryCaseInsensitivity(t *testing.T) { |
| 12 | + // Verify that all keys in the Registry are lowercase. |
| 13 | + for name := range Registry { |
| 14 | + assert.Equal(t, strings.ToLower(name), name) |
| 15 | + } |
| 16 | + |
| 17 | + // Verify that Get is case-insensitive. |
| 18 | + names := []string{"monokai", "Monokai", "MONOKAI"} |
| 19 | + |
| 20 | + for _, name := range names { |
| 21 | + t.Run(name, func(t *testing.T) { |
| 22 | + style := Get(name) |
| 23 | + |
| 24 | + assert.NotEqual(t, Fallback, style) |
| 25 | + assert.True(t, strings.EqualFold(style.Name, name)) |
| 26 | + }) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func TestGetUnknownStyleReturnsFallback(t *testing.T) { |
| 31 | + assert.Equal(t, Fallback, Get("non-existent-style")) |
| 32 | +} |
| 33 | + |
| 34 | +func TestRegisterCaseInsensitivity(t *testing.T) { |
| 35 | + custom := chroma.MustNewStyle("CustomStyle", chroma.StyleEntries{ |
| 36 | + chroma.Text: "#ffffff", |
| 37 | + }) |
| 38 | + Register(custom) |
| 39 | + |
| 40 | + assert.Equal(t, custom, Get("customstyle")) |
| 41 | + assert.Equal(t, custom, Get("CUSTOMSTYLE")) |
| 42 | + assert.Equal(t, custom, Get("CustomStyle")) |
| 43 | +} |
0 commit comments