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

Function TestBasic5

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

Source from the content-addressed store, hash-verified

594 }
595}
596func TestBasic5(t *testing.T) {
597 token := get(basicJSON, "age")
598 if token.String() != "100" {
599 t.Fatal("expecting '100'", "got", token.String())
600 }
601 _ = token.Value().(float64)
602 token = get(basicJSON, "happy")
603 if token.String() != "true" {
604 t.Fatal("expecting 'true'", "got", token.String())
605 }
606 _ = token.Value().(bool)
607 token = get(basicJSON, "immortal")
608 if token.String() != "false" {
609 t.Fatal("expecting 'false'", "got", token.String())
610 }
611 _ = token.Value().(bool)
612 token = get(basicJSON, "noop")
613 if token.String() != `{"what is a wren?":"a bird"}` {
614 t.Fatal("expecting '"+`{"what is a wren?":"a bird"}`+"'", "got",
615 token.String())
616 }
617 _ = token.Value().(map[string]interface{})
618
619 if get(basicJSON, "").Value() != nil {
620 t.Fatal("should be nil")
621 }
622
623 get(basicJSON, "vals.hello")
624
625 type msi = map[string]interface{}
626 type fi = []interface{}
627 mm := Parse(basicJSON).Value().(msi)
628 fn := mm["loggy"].(msi)["programmers"].(fi)[1].(msi)["firstName"].(string)
629 if fn != "Jason" {
630 t.Fatalf("expecting %v, got %v", "Jason", fn)
631 }
632}
633func TestUnicode(t *testing.T) {
634 var json = `{"key":0,"的情况下解":{"key":1,"的情况":2}}`
635 if Get(json, "的情况下解.key").Num != 1 {

Callers

nothing calls this directly

Calls 4

getFunction · 0.85
ParseFunction · 0.85
ValueMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…