1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-11-29 22:47:29 +02:00

feat: XML style definitions (#693)

Fixes #635.
This commit is contained in:
Alec Thomas
2022-11-02 15:23:14 +11:00
committed by GitHub
parent b2643973d2
commit c263f6fa19
132 changed files with 2595 additions and 2997 deletions

View File

@@ -1,6 +1,7 @@
package chroma
import (
"encoding/xml"
"testing"
assert "github.com/alecthomas/assert/v2"
@@ -101,3 +102,21 @@ func TestStyleBuilderTransform(t *testing.T) {
assert.Equal(t, "#ff0000", orig.Get(NameVariable).Colour.String())
assert.Equal(t, "#ff3300", deriv.Get(NameVariableGlobal).Colour.String())
}
func TestStyleMarshaller(t *testing.T) {
expected, err := NewStyle("test", StyleEntries{
Whitespace: "bg:#ffffff",
Text: "#000000 underline",
})
assert.NoError(t, err)
data, err := xml.MarshalIndent(expected, "", " ")
assert.NoError(t, err)
assert.Equal(t, `<style name="test">
<entry type="Text" style="underline #000000"></entry>
<entry type="TextWhitespace" style="bg:#ffffff"></entry>
</style>`, string(data))
actual := &Style{}
err = xml.Unmarshal(data, actual)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}