addtional test

This commit is contained in:
Josh Baker 2016-08-22 08:25:33 -07:00
parent 696d68fd62
commit 16ecfe5970
2 changed files with 43 additions and 2 deletions

View File

@ -473,6 +473,9 @@ func Get(json string, path string) Result {
// alpha lowercase
continue
}
if path[i] >= 'A' && path[i] <= 'Z' {
continue
}
if path[i] == '.' {
// append a new part
parts = append(parts, part{wild: wild, key: path[s:i]})
@ -483,7 +486,7 @@ func Get(json string, path string) Result {
s = i + 1
continue
}
if (path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= '0' && path[i] <= '9') {
if (path[i] >= '0' && path[i] <= '9') || path[i] == '_' {
continue
}
if path[i] == '*' || path[i] == '?' {
@ -515,7 +518,9 @@ func Get(json string, path string) Result {
}
continue
} else if path[i] == '.' {
parts = append(parts, part{wild: wild, key: string(epart)})
parts = append(parts, part{
wild: wild, key: string(epart),
})
if wild {
wild = false
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math/rand"
"strings"
@ -299,6 +300,41 @@ func TestLess(t *testing.T) {
assert(t, stringLessInsensitive("124abcde", "125abcde"))
}
func TestIssue6(t *testing.T) {
data := `{
"code": 0,
"msg": "",
"data": {
"sz002024": {
"qfqday": [
[
"2014-01-02",
"8.93",
"9.03",
"9.17",
"8.88",
"621143.00"
],
[
"2014-01-03",
"9.03",
"9.30",
"9.47",
"8.98",
"1624438.00"
]
]
}
}
}`
var num []string
for _, v := range Get(data, "data.sz002024.qfqday.0").Array() {
num = append(num, v.String())
}
fmt.Printf("%v\n", num)
}
var exampleJSON = `{
"widget": {
"debug": "on",