1 | 1 |
|
2 | 2 |
import (
|
3 | 3 |
"fmt"
|
|
4 |
"strings"
|
|
5 |
|
4 | 6 |
. "github.com/onsi/ginkgo"
|
5 | 7 |
. "github.com/onsi/gomega"
|
6 | 8 |
. "github.com/onsi/gomega/format"
|
7 | 9 |
"github.com/onsi/gomega/types"
|
8 | |
"strings"
|
9 | 10 |
)
|
10 | 11 |
|
11 | 12 |
//recursive struct
|
|
161 | 162 |
})
|
162 | 163 |
|
163 | 164 |
Describe("formatting []byte slices", func() {
|
164 | |
Context("when the slice is made of printable bytes", func () {
|
165 | |
It("should present it as string", func() {
|
166 | |
b := []byte("a b c")
|
167 | |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:5, cap:\d+`, `a b c`))
|
168 | |
})
|
169 | |
})
|
170 | |
Context("when the slice contains non-printable bytes", func () {
|
171 | |
It("should present it as slice", func() {
|
172 | |
b := []byte("a b c\n\x01\x02\x03\xff\x1bH")
|
173 | |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:12, cap:\d+`, `\[97, 32, 98, 32, 99, 10, 1, 2, 3, 255, 27, 72\]`))
|
174 | |
})
|
175 | |
})
|
176 | |
})
|
|
165 |
Context("when the slice is made of printable bytes", func() {
|
|
166 |
It("should present it as string", func() {
|
|
167 |
b := []byte("a b c")
|
|
168 |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:5, cap:\d+`, `a b c`))
|
|
169 |
})
|
|
170 |
})
|
|
171 |
Context("when the slice contains non-printable bytes", func() {
|
|
172 |
It("should present it as slice", func() {
|
|
173 |
b := []byte("a b c\n\x01\x02\x03\xff\x1bH")
|
|
174 |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:12, cap:\d+`, `\[97, 32, 98, 32, 99, 10, 1, 2, 3, 255, 27, 72\]`))
|
|
175 |
})
|
|
176 |
})
|
|
177 |
})
|
177 | 178 |
|
178 | 179 |
Describe("formatting functions", func() {
|
179 | 180 |
It("should give the type and format values correctly", func() {
|
|
428 | 429 |
m["map"] = m
|
429 | 430 |
Ω(Object(m, 1)).Should(ContainSubstring("..."))
|
430 | 431 |
})
|
|
432 |
|
|
433 |
It("really should not go crazy...", func() {
|
|
434 |
type complexKey struct {
|
|
435 |
Value map[interface{}]int
|
|
436 |
}
|
|
437 |
|
|
438 |
complexObject := complexKey{}
|
|
439 |
complexObject.Value = make(map[interface{}]int)
|
|
440 |
|
|
441 |
complexObject.Value[&complexObject] = 2
|
|
442 |
Ω(Object(complexObject, 1)).Should(ContainSubstring("..."))
|
|
443 |
})
|
431 | 444 |
})
|
432 | 445 |
|
433 | 446 |
Describe("When instructed to use the Stringer representation", func() {
|