From 4aadf44575c22e190cbd35875df0cb533908424b Mon Sep 17 00:00:00 2001 From: aoright <102943475+aoright@users.noreply.github.com> Date: Wed, 19 Aug 2026 22:01:05 +0800 Subject: [PATCH] test: add TestColorCustomStyle and fix doc comment typos Signed-off-by: aoright <102943475+aoright@users.noreply.github.com> --- pretty.go | 6 +++--- pretty_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pretty.go b/pretty.go index d705f9c..662174c 100644 --- a/pretty.go +++ b/pretty.go @@ -9,7 +9,7 @@ import ( // Options is Pretty options type Options struct { - // Width is an max column width for single line arrays + // Width is a max column width for single line arrays // Default is 80 Width int // Prefix is a prefix for all lines @@ -27,7 +27,7 @@ type Options struct { var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: " ", SortKeys: false} // Pretty converts the input json into a more human readable format where each -// element is on it's own line with clear indentation. +// element is on its own line with clear indentation. func Pretty(json []byte) []byte { return PrettyOptions(json, nil) } // PrettyOptions is like Pretty but with customized options. @@ -459,7 +459,7 @@ func init() { } } -// Color will colorize the json. The style parma is used for customizing +// Color will colorize the json. The style param is used for customizing // the colors. Passing nil to the style param will use the default // TerminalStyle. func Color(src []byte, style *Style) []byte { diff --git a/pretty_test.go b/pretty_test.go index f7cc898..1b7fddb 100644 --- a/pretty_test.go +++ b/pretty_test.go @@ -569,3 +569,17 @@ func TestNaN(t *testing.T) { } } } + +func TestColorCustomStyle(t *testing.T) { + customStyle := &Style{ + Key: [2]string{"", ""}, + String: [2]string{"", ""}, + Number: [2]string{"", ""}, + } + res := Color([]byte(`{"a":1,"b":"c"}`), customStyle) + expected := `{"a":1,"b":"c"}` + if string(res) != expected { + t.Fatalf("expected %q, got %q", expected, string(res)) + } +} +