(t *testing.T)
| 1242 | } |
| 1243 | |
| 1244 | func TestJSONLines(t *testing.T) { |
| 1245 | json := ` |
| 1246 | true |
| 1247 | false |
| 1248 | {"name":"tom"} |
| 1249 | [1,2,3,4,5] |
| 1250 | {"name":"janet"} |
| 1251 | null |
| 1252 | 12930.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 | |
| 1285 | func TestNumUint64String(t *testing.T) { |
| 1286 | var i int64 = 9007199254740993 //2^53 + 1 |
nothing calls this directly
no test coverage detected
searching dependent graphs…