Skip to content

Commit

Permalink
Fix omitEmpty is not propagated (#90)
Browse files Browse the repository at this point in the history
* Fix omitEmpty is not propagated

* Fix test case
  • Loading branch information
apstndb authored Nov 27, 2024
1 parent 9feac88 commit fe205da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ func TestStructPrintingWithTags(t *testing.T) {
}

func TestStructPrintingWithOmitEmpty(t *testing.T) {
type Bar struct{ StringField string }
type Bar struct {
StringField string
IntField int
}

type Foo struct {
StringField string
StringPtr *string
Expand All @@ -182,7 +186,7 @@ func TestStructPrintingWithOmitEmpty(t *testing.T) {
want string
}{
{
name: "all set",
name: "set",
foo: Foo{
StringField: "foo",
StringPtr: &stringVal,
Expand Down
2 changes: 1 addition & 1 deletion printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (p *printer) colorize(text string, color uint16) string {
}

func (p *printer) format(object interface{}) string {
pp := newPrinter(object, p.currentScheme, p.maxDepth, p.coloringEnabled, p.decimalUint, p.exportedOnly, p.thousandsSeparator, false)
pp := newPrinter(object, p.currentScheme, p.maxDepth, p.coloringEnabled, p.decimalUint, p.exportedOnly, p.thousandsSeparator, p.omitEmpty)
pp.depth = p.depth
pp.visited = p.visited
if value, ok := object.(reflect.Value); ok {
Expand Down

0 comments on commit fe205da

Please sign in to comment.