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

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"math/rand" "math/rand"
"strings" "strings"
@ -299,6 +300,41 @@ func TestLess(t *testing.T) {
assert(t, stringLessInsensitive("124abcde", "125abcde")) 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 = `{ var exampleJSON = `{
"widget": { "widget": {
"debug": "on", "debug": "on",