chunkOfSize_test.go 569 B

123456789101112131415161718192021222324252627282930313233343536
  1. package cos
  2. import (
  3. "strings"
  4. "testing"
  5. "unicode/utf8"
  6. )
  7. func Test4ChunksOf100(t *testing.T) {
  8. size := 100
  9. expectedChunks := 4
  10. chunk := NewChunkOfSize(testText, size)
  11. count := 0
  12. for {
  13. text := chunk.Next()
  14. if text == "" {
  15. break
  16. }
  17. if utf8.RuneCountInString(text) > size {
  18. t.Fatal(text, "\nis longer than", size)
  19. }
  20. count++
  21. }
  22. if count != expectedChunks {
  23. t.Fatal("There should be", expectedChunks, "chunks, but have", count)
  24. }
  25. if !chunk.Success() {
  26. t.Fatal("There were errors:\n", strings.Join(chunk.GetErrors(), "\n"))
  27. }
  28. }