1. package formatters
    
  2. 
    
  3. import (
    
  4. 	"strings"
    
  5. 	"testing"
    
  6. 
    
  7. 	assert "github.com/alecthomas/assert/v2"
    
  8. 	"github.com/alecthomas/chroma/v2"
    
  9. )
    
  10. 
    
  11. func TestClosestColour(t *testing.T) {
    
  12. 	actual := findClosest(ttyTables[256], chroma.MustParseColour("#e06c75"))
    
  13. 	assert.Equal(t, chroma.MustParseColour("#d75f87"), actual)
    
  14. }
    
  15. 
    
  16. func TestNoneColour(t *testing.T) {
    
  17. 	formatter := TTY256
    
  18. 	tokenType := chroma.None
    
  19. 
    
  20. 	style, err := chroma.NewStyle("test", chroma.StyleEntries{
    
  21. 		chroma.Background: "#D0ab1e",
    
  22. 	})
    
  23. 	assert.NoError(t, err)
    
  24. 
    
  25. 	stringBuilder := strings.Builder{}
    
  26. 	err = formatter.Format(&stringBuilder, style, chroma.Literator(chroma.Token{
    
  27. 		Type:  tokenType,
    
  28. 		Value: "WORD",
    
  29. 	}))
    
  30. 	assert.NoError(t, err)
    
  31. 
    
  32. 	// "178" = #d7af00 approximates #d0ab1e
    
  33. 	//
    
  34. 	// 178 color ref: https://jonasjacek.github.io/colors/
    
  35. 	assert.Equal(t, "\033[38;5;178mWORD\033[0m", stringBuilder.String())
    
  36. }