| 510 | } |
| 511 | } |
| 512 | func TestBasic3(t *testing.T) { |
| 513 | var mtok Result |
| 514 | if Parse(basicJSON).Get("loggy.programmers").Get("1"). |
| 515 | Get("firstName").Str != "Jason" { |
| 516 | t.Fatalf("expected %v, got %v", "Jason", Parse(basicJSON). |
| 517 | Get("loggy.programmers").Get("1").Get("firstName").Str) |
| 518 | } |
| 519 | var token Result |
| 520 | if token = Parse("-102"); token.Num != -102 { |
| 521 | t.Fatalf("expected %v, got %v", -102, token.Num) |
| 522 | } |
| 523 | if token = Parse("102"); token.Num != 102 { |
| 524 | t.Fatalf("expected %v, got %v", 102, token.Num) |
| 525 | } |
| 526 | if token = Parse("102.2"); token.Num != 102.2 { |
| 527 | t.Fatalf("expected %v, got %v", 102.2, token.Num) |
| 528 | } |
| 529 | if token = Parse(`"hello"`); token.Str != "hello" { |
| 530 | t.Fatalf("expected %v, got %v", "hello", token.Str) |
| 531 | } |
| 532 | if token = Parse(`"\"he\nllo\""`); token.Str != "\"he\nllo\"" { |
| 533 | t.Fatalf("expected %v, got %v", "\"he\nllo\"", token.Str) |
| 534 | } |
| 535 | mtok = get(basicJSON, "loggy.programmers.#.firstName") |
| 536 | if len(mtok.Array()) != 4 { |
| 537 | t.Fatalf("expected 4, got %v", len(mtok.Array())) |
| 538 | } |
| 539 | for i, ex := range []string{"Brett", "Jason", "Elliotte", "1002.3"} { |
| 540 | if mtok.Array()[i].String() != ex { |
| 541 | t.Fatalf("expected '%v', got '%v'", ex, mtok.Array()[i].String()) |
| 542 | } |
| 543 | } |
| 544 | mtok = get(basicJSON, "loggy.programmers.#.asd") |
| 545 | if mtok.Type != JSON { |
| 546 | t.Fatalf("expected %v, got %v", JSON, mtok.Type) |
| 547 | } |
| 548 | if len(mtok.Array()) != 0 { |
| 549 | t.Fatalf("expected 0, got %v", len(mtok.Array())) |
| 550 | } |
| 551 | } |
| 552 | func TestBasic4(t *testing.T) { |
| 553 | if get(basicJSON, "items.3.tags.#").Num != 3 { |
| 554 | t.Fatalf("expected 3, got %v", get(basicJSON, "items.3.tags.#").Num) |