Skip to content

Commit

Permalink
Add check's on final paragraph ends. Fix bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kibish committed Dec 1, 2019
1 parent ea306c6 commit 3adf669
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ipsum/ipsum.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (l *LoremIpsum) Generate() error {
return err
}
if l.limiter.limitReached() {
l.limiter.addParagraph()
if err := l.print("\n"); err != nil {
return err
}
return nil
}
}
Expand Down
28 changes: 28 additions & 0 deletions ipsum/ispum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func TestGeneration(t *testing.T) {
if stats.WordCount != wCount {
t.Errorf("Expected count of words to be %d, got: %d", expected, wCount)
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})

t.Run("three words", func(t *testing.T) {
Expand All @@ -32,6 +36,10 @@ func TestGeneration(t *testing.T) {
if stats.WordCount != wCount {
t.Errorf("Expected count of words to be %d, got: %d", expected, wCount)
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})

t.Run("start with lorem", func(t *testing.T) {
Expand All @@ -51,6 +59,10 @@ func TestGeneration(t *testing.T) {
if stats.ParagraphCount != realParagraphCount {
t.Errorf("Expected count of paragraphs to be %d, got: %d", expectedParagraphs, stats.ParagraphCount)
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})

t.Run("start with lorem and one word ahead", func(t *testing.T) {
Expand All @@ -70,6 +82,10 @@ func TestGeneration(t *testing.T) {
if stats.ParagraphCount != realParagraphCount {
t.Errorf("Expected count of paragraphs to be %d, got: %d", expectedParagraphs, stats.ParagraphCount)
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})

t.Run("generate 42 words", func(t *testing.T) {
Expand All @@ -90,6 +106,10 @@ func TestGeneration(t *testing.T) {
if stats.ByteCount != expectedBytes {
t.Errorf("Expected count of bytes to be %d, got: %d", expectedBytes, stats.ByteCount)
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})

t.Run("generate 5 paragraphs", func(t *testing.T) {
Expand All @@ -101,6 +121,10 @@ func TestGeneration(t *testing.T) {
if stats.ParagraphCount != realParag {
t.Errorf("Expected count of paragraphs to be %d, got: %d", expectedParagraphs, realParag)
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})

t.Run("generate >=404 bytes", func(t *testing.T) {
Expand All @@ -111,6 +135,10 @@ func TestGeneration(t *testing.T) {
if stats.ByteCount < expectedBytes {
t.Errorf("Expected count of bytes to be %d, got: %d", expectedBytes, len(str))
}

if !strings.HasSuffix(str, ".\n") {
t.Errorf("Last element should be %q", ".\n")
}
})
}

Expand Down

0 comments on commit 3adf669

Please sign in to comment.