|
6 | 6 | "testing"
|
7 | 7 |
|
8 | 8 | vimlparser "github.com/haya14busa/go-vimlparser"
|
| 9 | + "github.com/haya14busa/go-vimlparser/ast" |
| 10 | + "github.com/haya14busa/go-vimlparser/token" |
9 | 11 | )
|
10 | 12 |
|
11 | 13 | func TestFprint_expr(t *testing.T) {
|
@@ -48,3 +50,39 @@ func TestFprint_expr(t *testing.T) {
|
48 | 50 | }
|
49 | 51 | }
|
50 | 52 | }
|
| 53 | + |
| 54 | +func TestFprint_expr_insert_paren_to_binary(t *testing.T) { |
| 55 | + want := `(x + y) * z` |
| 56 | + buf := new(bytes.Buffer) |
| 57 | + left := &ast.BinaryExpr{ |
| 58 | + Left: &ast.Ident{Name: "x"}, |
| 59 | + Op: token.PLUS, |
| 60 | + Right: &ast.Ident{Name: "y"}, |
| 61 | + } |
| 62 | + node := &ast.BinaryExpr{ |
| 63 | + Left: left, |
| 64 | + Op: token.STAR, |
| 65 | + Right: &ast.Ident{Name: "z"}, |
| 66 | + } |
| 67 | + if err := Fprint(buf, node, nil); err != nil { |
| 68 | + t.Fatal(err) |
| 69 | + } |
| 70 | + if got := buf.String(); got != want { |
| 71 | + t.Errorf("got %q, want %q", got, want) |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +func TestFprint_expr_insert_paren_to_unary(t *testing.T) { |
| 76 | + want := `(-x)[y]` |
| 77 | + buf := new(bytes.Buffer) |
| 78 | + node := &ast.SubscriptExpr{ |
| 79 | + Left: &ast.UnaryExpr{Op: token.MINUS, X: &ast.Ident{Name: "x"}}, |
| 80 | + Right: &ast.Ident{Name: "y"}, |
| 81 | + } |
| 82 | + if err := Fprint(buf, node, nil); err != nil { |
| 83 | + t.Fatal(err) |
| 84 | + } |
| 85 | + if got := buf.String(); got != want { |
| 86 | + t.Errorf("got %q, want %q", got, want) |
| 87 | + } |
| 88 | +} |
0 commit comments