github.com/neilotoole/jsoncolor@v0.7.2-0.20231115150201-1637fae69be1/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 jsoncolor
     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  func (ts testenvShim) Builder() string {
    21  	return ""
    22  }
    23  
    24  var testenv testenvShim
    25  
    26  // Fake scanner for golang_decode_test.go
    27  type scanner struct{}
    28  
    29  func checkValid(in []byte, scan *scanner) error {
    30  	return nil
    31  }
    32  
    33  // Actual isSpace implementation
    34  func isSpace(c byte) bool {
    35  	return c == ' ' || c == '\t' || c == '\r' || c == '\n'
    36  }
    37  
    38  // Fake encoder for golang_encode_test.go
    39  type encodeState struct {
    40  	Buffer bytes.Buffer
    41  }
    42  
    43  func (es *encodeState) string(s string, escapeHTML bool) {
    44  }
    45  
    46  func (es *encodeState) stringBytes(b []byte, escapeHTML bool) {
    47  }
    48  
    49  // Fake number test
    50  func isValidNumber(n string) bool {
    51  	return true
    52  }
    53  
    54  func assertErrorPresence(t *testing.T, expected, actual error, prefixes ...interface{}) {
    55  	if expected != nil && actual == nil {
    56  		errorWithPrefixes(t, prefixes, "expected error, but did not get an error")
    57  	} else if expected == nil && actual != nil {
    58  		errorWithPrefixes(t, prefixes, "did not expect error but got %v", actual)
    59  	}
    60  }
    61  
    62  func errorWithPrefixes(t *testing.T, prefixes []interface{}, format string, elements ...interface{}) {
    63  	fullFormat := format
    64  	allElements := append(prefixes, elements...)
    65  
    66  	for range prefixes {
    67  		fullFormat = "%v: " + fullFormat
    68  	}
    69  	t.Errorf(fullFormat, allElements...)
    70  }