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