gitea源码

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package webtheme
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestParseThemeMetaInfo(t *testing.T) {
  9. m := parseThemeMetaInfoToMap(`gitea-theme-meta-info {
  10. --k1: "v1";
  11. --k2: "v\"2";
  12. --k3: 'v3';
  13. --k4: 'v\'4';
  14. --k5: v5;
  15. }`)
  16. assert.Equal(t, map[string]string{
  17. "--k1": "v1",
  18. "--k2": `v"2`,
  19. "--k3": "v3",
  20. "--k4": "v'4",
  21. "--k5": "v5",
  22. }, m)
  23. // if an auto theme imports others, the meta info should be extracted from the last one
  24. // the meta in imported themes should be ignored to avoid incorrect overriding
  25. m = parseThemeMetaInfoToMap(`
  26. @media (prefers-color-scheme: dark) { gitea-theme-meta-info { --k1: foo; } }
  27. @media (prefers-color-scheme: light) { gitea-theme-meta-info { --k1: bar; } }
  28. gitea-theme-meta-info {
  29. --k2: real;
  30. }`)
  31. assert.Equal(t, map[string]string{"--k2": "real"}, m)
  32. }