Remove dead code

This commit is contained in:
tidwall 2021-04-19 09:18:03 -07:00
parent 8ac92b3ad3
commit d6d786db3c
1 changed files with 2 additions and 191 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"strings"
"testing"
"time"
@ -142,7 +141,6 @@ var basicJSON = `{"age":100, "name":{"here":"B\\\"R"},
},
"lastly":{"yay":"final"}
}`
var basicJSONB = []byte(basicJSON)
func TestTimeResult(t *testing.T) {
assert(t, Get(basicJSON, "created").String() ==
@ -164,14 +162,11 @@ func TestManyVariousPathCounts(t *testing.T) {
expects := []string{"a", "b", "c"}
for _, count := range counts {
var gpaths []string
var gexpects []string
for i := 0; i < count; i++ {
if i < len(paths) {
gpaths = append(gpaths, paths[i])
gexpects = append(gexpects, expects[i])
} else {
gpaths = append(gpaths, fmt.Sprintf("not%d", i))
gexpects = append(gexpects, "null")
}
}
results := GetMany(json, gpaths...)
@ -738,7 +733,7 @@ func TestUnmarshalMap(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if bytes.Compare(b1, b2) != 0 {
if !bytes.Equal(b1, b2) {
t.Fatal("b1 != b2")
}
}
@ -784,14 +779,7 @@ var manyJSON = ` {
"name.first":"Cat",
}`
func combine(results []Result) string {
return fmt.Sprintf("%v", results)
}
var ( // used for testing
testWatchForFallback bool
testLastWasFallback bool
)
var testWatchForFallback bool
func TestManyBasic(t *testing.T) {
testWatchForFallback = true
@ -810,9 +798,6 @@ func TestManyBasic(t *testing.T) {
fmt.Printf("%v\n", paths)
t.Fatalf("expected %v, got %v", expect, results)
}
//if testLastWasFallback != shouldFallback {
// t.Fatalf("expected %v, got %v", shouldFallback, testLastWasFallback)
//}
}
testMany(false, "[Point]", "position.type")
testMany(false, `[emptya ["world peace"] 31]`, ".a", "loves", "age")
@ -923,49 +908,6 @@ func TestRandomMany(t *testing.T) {
}
}
type ComplicatedType struct {
unsettable int
Tagged string `json:"tagged"`
NotTagged bool
Nested struct {
Yellow string `json:"yellow"`
}
NestedTagged struct {
Green string
Map map[string]interface{}
Ints struct {
Int int `json:"int"`
Int8 int8
Int16 int16
Int32 int32
Int64 int64 `json:"int64"`
}
Uints struct {
Uint uint
Uint8 uint8
Uint16 uint16
Uint32 uint32
Uint64 uint64
}
Floats struct {
Float64 float64
Float32 float32
}
Byte byte
Bool bool
} `json:"nestedTagged"`
LeftOut string `json:"-"`
SelfPtr *ComplicatedType
SelfSlice []ComplicatedType
SelfSlicePtr []*ComplicatedType
SelfPtrSlice *[]ComplicatedType
Interface interface{} `json:"interface"`
Array [3]int
Time time.Time `json:"time"`
Binary []byte
NonBinary []byte
}
var complicatedJSON = `
{
"tagged": "OK",
@ -1189,50 +1131,6 @@ func TestNullArray(t *testing.T) {
}
}
// func TestRandomGetMany(t *testing.T) {
// start := time.Now()
// for time.Since(start) < time.Second*3 {
// testRandomGetMany(t)
// }
// }
func testRandomGetMany(t *testing.T) {
rand.Seed(time.Now().UnixNano())
json, keys := randomJSON()
for _, key := range keys {
r := Get(json, key)
if !r.Exists() {
t.Fatal("should exist")
}
}
rkeysi := rand.Perm(len(keys))
rkeysn := 1 + rand.Int()%32
if len(rkeysi) > rkeysn {
rkeysi = rkeysi[:rkeysn]
}
var rkeys []string
for i := 0; i < len(rkeysi); i++ {
rkeys = append(rkeys, keys[rkeysi[i]])
}
mres1 := GetMany(json, rkeys...)
var mres2 []Result
for _, rkey := range rkeys {
mres2 = append(mres2, Get(json, rkey))
}
if len(mres1) != len(mres2) {
t.Fatalf("expected %d, got %d", len(mres2), len(mres1))
}
for i := 0; i < len(mres1); i++ {
mres1[i].Index = 0
mres2[i].Index = 0
v1 := fmt.Sprintf("%#v", mres1[i])
v2 := fmt.Sprintf("%#v", mres2[i])
if v1 != v2 {
t.Fatalf("\nexpected %s\n"+
" got %s", v2, v1)
}
}
}
func TestIssue54(t *testing.T) {
var r []Result
json := `{"MarketName":null,"Nounce":6115}`
@ -1253,93 +1151,6 @@ func TestIssue54(t *testing.T) {
}
}
func randomString() string {
var key string
N := 1 + rand.Int()%16
for i := 0; i < N; i++ {
r := rand.Int() % 62
if r < 10 {
key += string(byte('0' + r))
} else if r-10 < 26 {
key += string(byte('a' + r - 10))
} else {
key += string(byte('A' + r - 10 - 26))
}
}
return `"` + key + `"`
}
func randomBool() string {
switch rand.Int() % 2 {
default:
return "false"
case 1:
return "true"
}
}
func randomNumber() string {
return strconv.FormatInt(int64(rand.Int()%1000000), 10)
}
func randomObjectOrArray(keys []string, prefix string, array bool, depth int) (
string, []string) {
N := 5 + rand.Int()%5
var json string
if array {
json = "["
} else {
json = "{"
}
for i := 0; i < N; i++ {
if i > 0 {
json += ","
}
var pkey string
if array {
pkey = prefix + "." + strconv.FormatInt(int64(i), 10)
} else {
key := randomString()
pkey = prefix + "." + key[1:len(key)-1]
json += key + `:`
}
keys = append(keys, pkey[1:])
var kind int
if depth == 5 {
kind = rand.Int() % 4
} else {
kind = rand.Int() % 6
}
switch kind {
case 0:
json += randomString()
case 1:
json += randomBool()
case 2:
json += "null"
case 3:
json += randomNumber()
case 4:
var njson string
njson, keys = randomObjectOrArray(keys, pkey, true, depth+1)
json += njson
case 5:
var njson string
njson, keys = randomObjectOrArray(keys, pkey, false, depth+1)
json += njson
}
}
if array {
json += "]"
} else {
json += "}"
}
return json, keys
}
func randomJSON() (json string, keys []string) {
return randomObjectOrArray(nil, "", false, 0)
}
func TestIssue55(t *testing.T) {
json := `{"one": {"two": 2, "three": 3}, "four": 4, "five": 5}`
results := GetMany(json, "four", "five", "one.two", "one.six")