1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
package grid_test
import (
. "github.com/achannarasappa/term-grid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Grid", func() {
It("should render a grid", func() {
output := Render(
Grid{
GutterVertical: 1,
GutterHorizontal: 2,
Rows: []Row{
{
Width: 70,
Cells: []Cell{
{
Width: 10,
Text: "test2 this is a long sentence that will need to be wrapped by word",
Overflow: WrapWord,
},
{
Width: 10,
Text: "test1a test1b test1c test1d",
Overflow: Wrap,
},
{
Width: 10,
Text: "test4a\ntest4b\ntest4c\ntest4d",
},
{
Text: "test3 this is another long sentence that will need to be wrapped but will overflow",
},
},
},
{
Width: 70,
Cells: []Cell{
{
Width: 50,
Text: "right aligned fixed width cell with word wrap. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do",
Align: Right,
Overflow: WrapWord,
},
{
Text: "flex width cell here",
},
},
},
{
Width: 70,
Cells: []Cell{
{
Width: 35,
Text: "fixed width cell that does not take up entire width of row",
Overflow: WrapWord,
},
{
Width: 20,
Text: "cell that is only visible on larger terminals",
VisibleMinWidth: Large.Size(),
},
{
Width: -1,
Text: "cell with invalid width",
},
},
},
{
Width: 70,
Cells: []Cell{
{
Width: 11,
Text: "fixed width",
},
{
Text: "flex width 1",
},
{
Text: "flex width 2",
},
{
Text: "flex width 3",
},
},
},
{
Width: 70,
Cells: []Cell{
{
Width: 50,
Text: "oversize 1",
},
{
Width: 50,
Text: "oversize 2",
},
{
Width: 50,
Text: "oversize 3",
},
{
Text: "flex width 4",
},
},
},
},
})
expected := `
test2 this test1a tes test4a test3 this is another long sentenc
is a long t1b test1c test4b
sentence test1d test4c
that will test4d
need to be
wrapped by
word
right aligned fixed width cell with word wrap. flex width cell he
Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do
fixed width cell that does not take
up entire width of row
fixed width flex width 1 flex width 2 flex width 3
oversize 1 oversize 2 `
Expect("\n\n" + output).To(BeIdenticalTo(expected))
})
Describe("TextAlign", func() {
When("left align is selected", func() {
It("returns the text for left align text", func() {
input := Left.String()
output := "Left"
Expect(input).To(Equal(output))
})
})
})
Describe("Overflow", func() {
When("hidden is selected", func() {
It("returns the text for hidden overflow text", func() {
input := Hidden.String()
output := "Hidden"
Expect(input).To(Equal(output))
})
})
})
Describe("Breakpoint", func() {
When("hidden is selected", func() {
It("returns the breakpoint text", func() {
input := Small.String()
output := "Small"
Expect(input).To(Equal(output))
})
})
})
})
|