chunkOfSize_test.go 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. }
  29. func TestWordBiggerThanLimit(t *testing.T) {
  30. size := 4
  31. chunk := NewChunkOfSize(testText, size)
  32. text := chunk.Next()
  33. if text != "" {
  34. t.Fatal("Chunk should be empty, but is:", text)
  35. }
  36. if chunk.Success() || len(chunk.GetErrors()) == 0 {
  37. t.Fatal("There should be errors!")
  38. }
  39. }