From 3adf669e84cdae9997e1cb1b5db3cd96ba9fef8a Mon Sep 17 00:00:00 2001 From: Sergey Kibish Date: Sun, 1 Dec 2019 22:18:02 +0200 Subject: [PATCH] Add check's on final paragraph ends. Fix bug. --- ipsum/ipsum.go | 4 ++++ ipsum/ispum_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ipsum/ipsum.go b/ipsum/ipsum.go index 5292c87..e68004e 100644 --- a/ipsum/ipsum.go +++ b/ipsum/ipsum.go @@ -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 } } diff --git a/ipsum/ispum_test.go b/ipsum/ispum_test.go index 3bb6491..4f20850 100644 --- a/ipsum/ispum_test.go +++ b/ipsum/ispum_test.go @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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") + } }) }