diff --git a/parse/parse_test.go b/parse/parse_test.go index 679ff971..e757ff90 100644 --- a/parse/parse_test.go +++ b/parse/parse_test.go @@ -245,13 +245,13 @@ func TestParse(t *testing.T) { if err != nil { t.Errorf("Parse(%q) returns bad parse tree: %v", tc.src, err) fmt.Fprintf(os.Stderr, "Parse tree of %q:\n", tc.src) - PPrintParseTreeTo(bn, os.Stderr) + PPrintParseTree(bn, os.Stderr) } err = checkAST(bn, tc.ast) if err != nil { t.Errorf("Parse(%q) returns bad AST: %v", tc.src, err) fmt.Fprintf(os.Stderr, "AST of %q:\n", tc.src) - PPrintASTTo(bn, os.Stderr) + PPrintAST(bn, os.Stderr) } } } diff --git a/parse/pprint.go b/parse/pprint.go index a6020bbf..2d69446f 100644 --- a/parse/pprint.go +++ b/parse/pprint.go @@ -1,7 +1,6 @@ package parse import ( - "bytes" "fmt" "io" "reflect" @@ -14,16 +13,9 @@ const ( indentInc = 2 ) -// PPrintAST pretty-prints the AST part of a Node. -func PPrintAST(n Node) string { - var b bytes.Buffer - PPrintASTTo(n, &b) - return b.String() -} - -// PPrintASTTo pretty-prints the AST part of a Node to a Writer. -func PPrintASTTo(n Node, wr io.Writer) { - pprintAST(n, wr, 0, "") +// PPrintAST pretty-prints the AST part of a Node to a Writer. +func PPrintAST(n Node, w io.Writer) { + pprintAST(n, w, 0, "") } type field struct { @@ -114,16 +106,9 @@ func pprintAST(n Node, wr io.Writer, indent int, leading string) { } } -// PPrintParseTree pretty-prints the parse tree part of a Node. -func PPrintParseTree(n Node) string { - var b bytes.Buffer - PPrintParseTreeTo(n, &b) - return b.String() -} - -// PPrintParseTreeTo pretty-prints the parse tree part of a Node to a Writer. -func PPrintParseTreeTo(n Node, wr io.Writer) { - pprintParseTree(n, wr, 0) +// PPrintParseTree pretty-prints the parse tree part of a Node to a Writer. +func PPrintParseTree(n Node, w io.Writer) { + pprintParseTree(n, w, 0) } func pprintParseTree(n Node, wr io.Writer, indent int) { diff --git a/parse/pprint_test.go b/parse/pprint_test.go index 4851abf6..0f62005e 100644 --- a/parse/pprint_test.go +++ b/parse/pprint_test.go @@ -1,6 +1,7 @@ package parse import ( + "strings" "testing" "github.com/elves/elvish/tt" @@ -25,7 +26,11 @@ var pprintASTTests = tt.Table{ } func TestPPrintAST(t *testing.T) { - tt.Test(t, tt.Fn("PPrintAST", PPrintAST), pprintASTTests) + tt.Test(t, tt.Fn("PPrintAST (to string)", func(n Node) string { + var b strings.Builder + PPrintAST(n, &b) + return b.String() + }), pprintASTTests) } var pprintParseTreeTests = tt.Table{ @@ -51,7 +56,11 @@ var pprintParseTreeTests = tt.Table{ } func TestPprintParseTree(t *testing.T) { - tt.Test(t, tt.Fn("PPrintParseTree", PPrintParseTree), pprintParseTreeTests) + tt.Test(t, tt.Fn("PPrintParseTree (to string)", func(n Node) string { + var b strings.Builder + PPrintParseTree(n, &b) + return b.String() + }), pprintParseTreeTests) } func mustParse(src string) Node {