1package table_test
2
3import (
4	"strings"
5
6	. "github.com/onsi/ginkgo/extensions/table"
7
8	. "github.com/onsi/ginkgo"
9	. "github.com/onsi/gomega"
10)
11
12var _ = Describe("Table", func() {
13	DescribeTable("a simple table",
14		func(x int, y int, expected bool) {
15			Ω(x > y).Should(Equal(expected))
16		},
17		Entry("x > y", 1, 0, true),
18		Entry("x == y", 0, 0, false),
19		Entry("x < y", 0, 1, false),
20	)
21
22	type ComplicatedThings struct {
23		Superstructure string
24		Substructure   string
25		Count          int
26	}
27
28	DescribeTable("a more complicated table",
29		func(c ComplicatedThings) {
30			Ω(strings.Count(c.Superstructure, c.Substructure)).Should(BeNumerically("==", c.Count))
31		},
32		Entry("with no matching substructures", ComplicatedThings{
33			Superstructure: "the sixth sheikh's sixth sheep's sick",
34			Substructure:   "emir",
35			Count:          0,
36		}),
37		Entry("with one matching substructure", ComplicatedThings{
38			Superstructure: "the sixth sheikh's sixth sheep's sick",
39			Substructure:   "sheep",
40			Count:          1,
41		}),
42		Entry("with many matching substructures", ComplicatedThings{
43			Superstructure: "the sixth sheikh's sixth sheep's sick",
44			Substructure:   "si",
45			Count:          3,
46		}),
47	)
48
49	PDescribeTable("a failure",
50		func(value bool) {
51			Ω(value).Should(BeFalse())
52		},
53		Entry("when true", true),
54		Entry("when false", false),
55		Entry("when malformed", 2),
56	)
57
58	DescribeTable("an untyped nil as an entry",
59		func(x interface{}) {
60			Expect(x).To(BeNil())
61		},
62		Entry("nil", nil),
63	)
64})
65