-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
041e46f
commit 57b5ea0
Showing
6 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package text_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestText(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Text Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package text_test | ||
|
||
import ( | ||
. "ticker-tape/internal/ui/util/text" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Text", func() { | ||
|
||
Describe("Line", func() { | ||
It("should output text with spaces filled to the width", func() { | ||
input := Line(10, Cell{ | ||
Text: "test", | ||
}) | ||
output := "test " | ||
Expect(input).To(Equal(output)) | ||
}) | ||
Context("when there are multiple cells", func() { | ||
It("should output text equally spaced apart", func() { | ||
input := Line(20, | ||
Cell{ | ||
Text: "test1", | ||
}, | ||
Cell{ | ||
Text: "test2", | ||
}, | ||
) | ||
output := "test1 test2 " | ||
Expect(input).To(Equal(output)) | ||
}) | ||
}) | ||
Context("when cell width is set", func() { | ||
It("should set the cell's width", func() { | ||
input := Line(20, | ||
Cell{ | ||
Text: "test1", | ||
Width: 7, | ||
}, | ||
Cell{ | ||
Text: "test2", | ||
}, | ||
) | ||
output := "test1 test2 " | ||
Expect(input).To(Equal(output)) | ||
}) | ||
|
||
It("should evenly distribute the remaining space across the other cells", func() { | ||
input := Line(23, | ||
Cell{ | ||
Text: "test1", | ||
Width: 10, | ||
}, | ||
Cell{ | ||
Text: "test2", | ||
}, | ||
Cell{ | ||
Text: "test3", | ||
}, | ||
) | ||
output := "test1 test2 test3 " | ||
Expect(input).To(Equal(output)) | ||
}) | ||
}) | ||
Context("when align is set to LeftAlign", func() { | ||
It("should add spaces to the end of the text up to the width", func() { | ||
input := Line(10, Cell{ | ||
Text: "test", | ||
Align: LeftAlign, | ||
}) | ||
output := "test " | ||
Expect(input).To(Equal(output)) | ||
}) | ||
}) | ||
Context("when align is set to RightAlign", func() { | ||
It("should add spaces to the beggining of the text up to the width", func() { | ||
input := Line(10, Cell{ | ||
Text: "test", | ||
Align: RightAlign, | ||
}) | ||
output := " test" | ||
Expect(input).To(Equal(output)) | ||
}) | ||
}) | ||
Context("when the text length exceeds the line width", func() { | ||
It("should truncate the text", func() { | ||
input := Line(2, Cell{ | ||
Text: "test", | ||
}) | ||
output := "te" | ||
Expect(input).To(Equal(output)) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("JoinLines", func() { | ||
It("should join text with a newline between", func() { | ||
Expect(JoinLines("a", "b", "c")).To(Equal("a\nb\nc")) | ||
}) | ||
}) | ||
}) |