Parcourir la source

Added TestTextShorterThanLimit

Piotr Czajkowski il y a 1 an
Parent
commit
f50698cab7
1 fichiers modifiés avec 29 ajouts et 0 suppressions
  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"))
+	}
 }