Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

31 linhas
834 B

  1. package colorable
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. // checkEncoding checks that colorable is output encoding agnostic as long as
  7. // the encoding is a superset of ASCII. This implies that one byte not part of
  8. // an ANSI sequence must give exactly one byte in output
  9. func checkEncoding(t *testing.T, data []byte) {
  10. // Send non-UTF8 data to colorable
  11. b := bytes.NewBuffer(make([]byte, 0, 10))
  12. if b.Len() != 0 {
  13. t.FailNow()
  14. }
  15. // TODO move colorable wrapping outside the test
  16. c := NewNonColorable(b)
  17. c.Write(data)
  18. if b.Len() != len(data) {
  19. t.Fatalf("%d bytes expected, got %d", len(data), b.Len())
  20. }
  21. }
  22. func TestEncoding(t *testing.T) {
  23. checkEncoding(t, []byte{}) // Empty
  24. checkEncoding(t, []byte(`abc`)) // "abc"
  25. checkEncoding(t, []byte(`é`)) // "é" in UTF-8
  26. checkEncoding(t, []byte{233}) // 'é' in Latin-1
  27. }