github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/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 func Fuzz_calcBounds(f *testing.F) { 29 f.Add(33, 16) 30 f.Fuzz(func(t *testing.T, a int, b int) { 31 if a < 0 || a > 1024*1024*10 { 32 return 33 } 34 src := strings.Repeat("a", a) 35 p, x, q, y := calcBounds(a, b) 36 if x < 0 { 37 t.Fatal("x < 0", x) 38 } 39 if y < 0 { 40 t.Fatal("y < 0", y) 41 } 42 if x > a { 43 t.Fatal("x > a", x) 44 } 45 if y > a { 46 t.Fatal("y > a", y) 47 } 48 if x > 31 { 49 t.Fatal("x > 31", x) 50 } 51 if y > 31 { 52 t.Fatal("y > 31", y) 53 } 54 if p < 0 { 55 t.Fatal("p < 0", p) 56 } 57 if q < 0 { 58 t.Fatal("q < 0", 0) 59 } 60 if p > a { 61 t.Fatal("p >= a", p) 62 } 63 if q > a { 64 t.Fatal("q >= a", q) 65 } 66 if p > q { 67 t.Fatal("p > q", q) 68 } 69 70 _ = fmt.Sprintf( 71 "%s\n\t%s^%s\n", 72 src[p:q], 73 strings.Repeat(".", x), 74 strings.Repeat(".", y), 75 ) 76 }) 77 }