MCPcopy
hub / github.com/tidwall/gjson / TestJSONLines

Function TestJSONLines

gjson_test.go:1244–1283  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1242}
1243
1244func TestJSONLines(t *testing.T) {
1245 json := `
1246true
1247false
1248{"name":"tom"}
1249[1,2,3,4,5]
1250{"name":"janet"}
1251null
125212930.1203
1253 `
1254 paths := []string{"..#", "..0", "..2.name", "..#.name", "..6", "..7"}
1255 ress := []string{"7", "true", "tom", `["tom","janet"]`, "12930.1203", ""}
1256 for i, path := range paths {
1257 res := Get(json, path)
1258 if res.String() != ress[i] {
1259 t.Fatalf("expected '%v', got '%v'", ress[i], res.String())
1260 }
1261 }
1262
1263 json = `
1264{"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]}
1265{"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]}
1266{"name": "May", "wins": []}
1267{"name": "Deloise", "wins": [["three of a kind", "5♣"]]}
1268`
1269
1270 var i int
1271 lines := strings.Split(strings.TrimSpace(json), "\n")
1272 ForEachLine(json, func(line Result) bool {
1273 if line.Raw != lines[i] {
1274 t.Fatalf("expected '%v', got '%v'", lines[i], line.Raw)
1275 }
1276 i++
1277 return true
1278 })
1279 if i != 4 {
1280 t.Fatalf("expected '%v', got '%v'", 4, i)
1281 }
1282
1283}
1284
1285func TestNumUint64String(t *testing.T) {
1286 var i int64 = 9007199254740993 //2^53 + 1

Callers

nothing calls this directly

Calls 3

GetFunction · 0.85
ForEachLineFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…