github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/internal/decoder/fuzz_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 /** 5 * Copyright 2023 ByteDance Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package decoder 21 22 import ( 23 `fmt` 24 `strings` 25 `testing` 26 ) 27 28 29 func Fuzz_calcBounds(f *testing.F) { 30 f.Add(33, 16) 31 f.Fuzz(func(t *testing.T, a int, b int){ 32 if a < 0 || a > 1024*1024*10 { 33 return 34 } 35 src := strings.Repeat("a", a) 36 p, x, q, y := calcBounds(a, b) 37 if x < 0 { 38 t.Fatal("x < 0", x) 39 } 40 if y < 0 { 41 t.Fatal("y < 0", y) 42 } 43 if x > a { 44 t.Fatal("x > a", x) 45 } 46 if y > a { 47 t.Fatal("y > a", y) 48 } 49 if x > 31 { 50 t.Fatal("x > 31", x) 51 } 52 if y > 31 { 53 t.Fatal("y > 31", y) 54 } 55 if p < 0 { 56 t.Fatal("p < 0", p) 57 } 58 if q < 0 { 59 t.Fatal("q < 0", 0) 60 } 61 if p > a { 62 t.Fatal("p >= a", p) 63 } 64 if q > a { 65 t.Fatal("q >= a", q) 66 } 67 if p > q { 68 t.Fatal("p > q", q) 69 } 70 71 _ = fmt.Sprintf( 72 "%s\n\t%s^%s\n", 73 src[p:q], 74 strings.Repeat(".", x), 75 strings.Repeat(".", y), 76 ) 77 }) 78 }