You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
995 B

  1. package common
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestStringInSlice(t *testing.T) {
  7. assert.True(t, StringInSlice("a", []string{"a", "b", "c"}))
  8. assert.False(t, StringInSlice("d", []string{"a", "b", "c"}))
  9. assert.True(t, StringInSlice("", []string{""}))
  10. assert.False(t, StringInSlice("", []string{}))
  11. }
  12. func TestIsASCIIText(t *testing.T) {
  13. notASCIIText := []string{
  14. "", "\xC2", "\xC2\xA2", "\xFF", "\x80", "\xF0", "\n", "\t",
  15. }
  16. for _, v := range notASCIIText {
  17. assert.False(t, IsASCIIText(v), "%q is not ascii-text", v)
  18. }
  19. asciiText := []string{
  20. " ", ".", "x", "$", "_", "abcdefg;", "-", "0x00", "0", "123",
  21. }
  22. for _, v := range asciiText {
  23. assert.True(t, IsASCIIText(v), "%q is ascii-text", v)
  24. }
  25. }
  26. func TestASCIITrim(t *testing.T) {
  27. assert.Equal(t, ASCIITrim(" "), "")
  28. assert.Equal(t, ASCIITrim(" a"), "a")
  29. assert.Equal(t, ASCIITrim("a "), "a")
  30. assert.Equal(t, ASCIITrim(" a "), "a")
  31. assert.Panics(t, func() { ASCIITrim("\xC2\xA2") })
  32. }