MCPcopy Index your code
hub / github.com/maruel/panicparse / TestTrimCurlyBrackets

Function TestTrimCurlyBrackets

stack/context_test.go:2143–2183  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2141}
2142
2143func TestTrimCurlyBrackets(t *testing.T) {
2144 t.Parallel()
2145 data := []struct {
2146 input []byte
2147 want []byte
2148 wantOpened, wantClosed int
2149 }{
2150 {nil, nil, 0, 0},
2151 {[]byte(""), []byte(""), 0, 0},
2152 {[]byte("a"), []byte("a"), 0, 0},
2153 {[]byte("{a"), []byte("a"), 1, 0},
2154 {[]byte("{{a"), []byte("a"), 2, 0},
2155 {[]byte("{{a}}"), []byte("a"), 2, 2},
2156 {[]byte("{a}}"), []byte("a"), 1, 2},
2157 {[]byte("a}}"), []byte("a"), 0, 2},
2158 {[]byte("{}"), []byte(""), 1, 1},
2159 {[]byte("{{}}"), []byte(""), 2, 2},
2160 // Not expected in practice.
2161 {[]byte("}{"), []byte("}{"), 0, 0},
2162 {[]byte("{{}}a{{}}"), []byte("}}a{{"), 2, 2},
2163 }
2164 for i, line := range data {
2165 line := line
2166 t.Run(fmt.Sprintf("%d-%s", i, line.input), func(t *testing.T) {
2167 gotOpened, got, gotClosed := trimCurlyBrackets(line.input)
2168 if !bytes.Equal(line.want, got) {
2169 t.Errorf("want %s, got %s", line.want, got)
2170 }
2171 equiv := bytes.TrimRight(bytes.TrimLeft(line.input, "{"), "}")
2172 if !bytes.Equal(line.want, equiv) {
2173 t.Errorf("want %s, got %s", line.want, got)
2174 }
2175 if line.wantOpened != gotOpened {
2176 t.Errorf("want %d opening curly brackets, got %d", line.wantOpened, gotOpened)
2177 }
2178 if line.wantClosed != gotClosed {
2179 t.Errorf("want %d closing curly brackets, got %d", line.wantClosed, gotClosed)
2180 }
2181 })
2182 }
2183}
2184
2185func BenchmarkScanSnapshot_Guess(b *testing.B) {
2186 b.ReportAllocs()

Callers

nothing calls this directly

Calls 1

trimCurlyBracketsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…