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

Function TestBasic3

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

Source from the content-addressed store, hash-verified

510 }
511}
512func 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}
552func 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)

Callers

nothing calls this directly

Calls 5

ArrayMethod · 0.95
ParseFunction · 0.85
getFunction · 0.85
GetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…