Browse Source

Added TestTextShorterThanLimit

Piotr Czajkowski 1 year ago
parent
commit
f50698cab7
1 changed files with 29 additions and 0 deletions
  1. 29 0
      chunkOfSize_test.go

+ 29 - 0
chunkOfSize_test.go

@@ -48,4 +48,33 @@ func TestWordBiggerThanLimit(t *testing.T) {
 	if chunk.Success() || len(chunk.GetErrors()) == 0 {
 		t.Fatal("There should be errors!")
 	}
+}
+
+func TestTextShorterThanLimit(t *testing.T) {
+	size := 400
+  expectedChunks := 1
+  
+	chunk := NewChunkOfSize(testText, size)
+	count := 0
+
+	for {
+		text := chunk.Next()
+		if text == "" {
+			break
+		}
+
+		if utf8.RuneCountInString(text) > size {
+			t.Fatal(text, "\nis longer than", size)
+		}
+
+		count++
+	}
+  
+	if count != expectedChunks {
+		t.Fatal("There should be", expectedChunks, "chunks, but have", count)
+	}
+
+	if !chunk.Success() {
+		t.Fatal("There were errors:\n", strings.Join(chunk.GetErrors(), "\n"))
+	}
 }