github.com/segmentio/encoding@v0.4.0/json/golang_shim_test.go (about) 1 // This file is a shim for dependencies of golang_*_test.go files that are normally provided by the standard library. 2 // It helps importing those files with minimal changes. 3 package json 4 5 import ( 6 "bytes" 7 "reflect" 8 "sync" 9 "testing" 10 ) 11 12 // Field cache used in golang_bench_test.go 13 var fieldCache = sync.Map{} 14 15 func cachedTypeFields(reflect.Type) {} 16 17 // Fake test env for golang_bench_test.go 18 type testenvShim struct { 19 } 20 21 func (ts testenvShim) Builder() string { 22 return "" 23 } 24 25 var testenv testenvShim 26 27 // Fake scanner for golang_decode_test.go 28 type scanner struct { 29 } 30 31 func checkValid(in []byte, scan *scanner) error { 32 return nil 33 } 34 35 // Actual isSpace implementation 36 func isSpace(c byte) bool { 37 return c == ' ' || c == '\t' || c == '\r' || c == '\n' 38 } 39 40 // Fake encoder for golang_encode_test.go 41 type encodeState struct { 42 Buffer bytes.Buffer 43 } 44 45 func (es *encodeState) string(s string, escapeHTML bool) { 46 } 47 48 func (es *encodeState) stringBytes(b []byte, escapeHTML bool) { 49 } 50 51 // Fake number test 52 func isValidNumber(n string) bool { 53 return true 54 } 55 56 func assertErrorPresence(t *testing.T, expected error, actual error, prefixes ...interface{}) { 57 if expected != nil && actual == nil { 58 errorWithPrefixes(t, prefixes, "expected error, but did not get an error") 59 } else if expected == nil && actual != nil { 60 errorWithPrefixes(t, prefixes, "did not expect error but got %v", actual) 61 } 62 } 63 64 func errorWithPrefixes(t *testing.T, prefixes []interface{}, format string, elements ...interface{}) { 65 fullFormat := format 66 allElements := append(prefixes, elements...) 67 68 for range prefixes { 69 fullFormat = "%v: " + fullFormat 70 } 71 t.Errorf(fullFormat, allElements...) 72 }