gitea源码

attribute_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package attribute
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func Test_Attribute(t *testing.T) {
  9. assert.Empty(t, Attribute("").ToString().Value())
  10. assert.Empty(t, Attribute("unspecified").ToString().Value())
  11. assert.Equal(t, "python", Attribute("python").ToString().Value())
  12. assert.Equal(t, "Java", Attribute("Java").ToString().Value())
  13. attributes := Attributes{
  14. m: map[string]Attribute{
  15. LinguistGenerated: "true",
  16. LinguistDocumentation: "false",
  17. LinguistDetectable: "set",
  18. LinguistLanguage: "Python",
  19. GitlabLanguage: "Java",
  20. "filter": "unspecified",
  21. "test": "",
  22. },
  23. }
  24. assert.Empty(t, attributes.Get("test").ToString().Value())
  25. assert.Empty(t, attributes.Get("filter").ToString().Value())
  26. assert.Equal(t, "Python", attributes.Get(LinguistLanguage).ToString().Value())
  27. assert.Equal(t, "Java", attributes.Get(GitlabLanguage).ToString().Value())
  28. assert.True(t, attributes.Get(LinguistGenerated).ToBool().Value())
  29. assert.False(t, attributes.Get(LinguistDocumentation).ToBool().Value())
  30. assert.True(t, attributes.Get(LinguistDetectable).ToBool().Value())
  31. }