Browse Source

Change of concept

Piotr Czajkowski 1 year ago
parent
commit
c3bace3317
2 changed files with 7 additions and 13 deletions
  1. 4 0
      chunkOfSize.go
  2. 3 13
      chunkOfSize_test.go

+ 4 - 0
chunkOfSize.go

@@ -15,6 +15,10 @@ type chunkOfSize struct {
 
 // NewChunkOfSize returns new instance of ChunkOfSize initialized with given text and size
 func NewChunkOfSize(text string, size int) *chunkOfSize {
+	if utf8.RuneCountInString(text) < size {
+		return nil
+	}
+	
 	return &chunkOfSize{
 		current: 0,
 		limit:   size,

+ 3 - 13
chunkOfSize_test.go

@@ -61,19 +61,9 @@ func TestWordBiggerThanLimit(t *testing.T) {
 
 func TestTextShorterThanLimit(t *testing.T) {
 	size := 400
-  expectedChunks := 1
-
-  chunk, count, err := checkChunks(testText, size)
-  if err != nil {
-    t.Fatal(err)
-  }
-  
-	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"))
+  chunk := NewChunkOfSize(shorterText, size)
+	if chunk != nil {
+		t.Fatal("Chunk should be nil!")
 	}
 }