Skip to content

Commit

Permalink
test: nil value panic
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-cn committed Dec 15, 2023
1 parent a043d24 commit 8e460b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ func main() {
// ExampleOmit()
//}

fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
//fmt.Println(filter.Omit("1", User{}))
TestNilValue()

}

Expand Down
27 changes: 27 additions & 0 deletions test/nil_value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"github.com/liu-cn/json-filter/filter"
)

func TestNilValue() {
var a *T
var c *T
var el = map[string]interface{}{
"a": a, // a: nil ptr
"b": 1,
"c": map[string]interface{}{
"bb": nil,
"dd": c, // dd: nil ptr
},
}

fmt.Println(filter.Select("test", el))
//{"a":null,"b":1,"c":{"bb":null,"dd":null}}

}

type T struct {
A string `json:"a,select(test)"`
}

0 comments on commit 8e460b1

Please sign in to comment.