MCPcopy Index your code
hub / github.com/tidwall/gjson / TestTypes

Function TestTypes

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

Source from the content-addressed store, hash-verified

360 Get(`["S3O PEDRO DO BUTI\udf93\u1345asd"]`, "0")
361}
362func TestTypes(t *testing.T) {
363 assert(t, (Result{Type: String}).Type.String() == "String")
364 assert(t, (Result{Type: Number}).Type.String() == "Number")
365 assert(t, (Result{Type: Null}).Type.String() == "Null")
366 assert(t, (Result{Type: False}).Type.String() == "False")
367 assert(t, (Result{Type: True}).Type.String() == "True")
368 assert(t, (Result{Type: JSON}).Type.String() == "JSON")
369 assert(t, (Result{Type: 100}).Type.String() == "")
370 // bool
371 assert(t, (Result{Type: True}).Bool() == true)
372 assert(t, (Result{Type: False}).Bool() == false)
373 assert(t, (Result{Type: Number, Num: 1}).Bool() == true)
374 assert(t, (Result{Type: Number, Num: 0}).Bool() == false)
375 assert(t, (Result{Type: String, Str: "1"}).Bool() == true)
376 assert(t, (Result{Type: String, Str: "T"}).Bool() == true)
377 assert(t, (Result{Type: String, Str: "t"}).Bool() == true)
378 assert(t, (Result{Type: String, Str: "true"}).Bool() == true)
379 assert(t, (Result{Type: String, Str: "True"}).Bool() == true)
380 assert(t, (Result{Type: String, Str: "TRUE"}).Bool() == true)
381 assert(t, (Result{Type: String, Str: "tRuE"}).Bool() == true)
382 assert(t, (Result{Type: String, Str: "0"}).Bool() == false)
383 assert(t, (Result{Type: String, Str: "f"}).Bool() == false)
384 assert(t, (Result{Type: String, Str: "F"}).Bool() == false)
385 assert(t, (Result{Type: String, Str: "false"}).Bool() == false)
386 assert(t, (Result{Type: String, Str: "False"}).Bool() == false)
387 assert(t, (Result{Type: String, Str: "FALSE"}).Bool() == false)
388 assert(t, (Result{Type: String, Str: "fAlSe"}).Bool() == false)
389 assert(t, (Result{Type: String, Str: "random"}).Bool() == false)
390
391 // int
392 assert(t, (Result{Type: String, Str: "1"}).Int() == 1)
393 assert(t, (Result{Type: True}).Int() == 1)
394 assert(t, (Result{Type: False}).Int() == 0)
395 assert(t, (Result{Type: Number, Num: 1}).Int() == 1)
396 // uint
397 assert(t, (Result{Type: String, Str: "1"}).Uint() == 1)
398 assert(t, (Result{Type: True}).Uint() == 1)
399 assert(t, (Result{Type: False}).Uint() == 0)
400 assert(t, (Result{Type: Number, Num: 1}).Uint() == 1)
401 // float
402 assert(t, (Result{Type: String, Str: "1"}).Float() == 1)
403 assert(t, (Result{Type: True}).Float() == 1)
404 assert(t, (Result{Type: False}).Float() == 0)
405 assert(t, (Result{Type: Number, Num: 1}).Float() == 1)
406}
407func TestForEach(t *testing.T) {
408 Result{}.ForEach(nil)
409 Result{Type: String, Str: "Hello"}.ForEach(func(_, value Result) bool {

Callers

nothing calls this directly

Calls 6

assertFunction · 0.85
BoolMethod · 0.80
IntMethod · 0.80
UintMethod · 0.80
FloatMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…