Home | History | Annotate | Download | only in syntax
      1 // Copyright 2016 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package syntax
      6 
      7 import (
      8 	"fmt"
      9 	"os"
     10 	"testing"
     11 )
     12 
     13 func TestPrint(t *testing.T) {
     14 	if testing.Short() {
     15 		t.Skip("skipping test in short mode")
     16 	}
     17 
     18 	ast, err := ParseFile(*src_, nil, nil, 0)
     19 	if err != nil {
     20 		t.Fatal(err)
     21 	}
     22 	Fprint(os.Stdout, ast, true)
     23 	fmt.Println()
     24 }
     25 
     26 func TestPrintString(t *testing.T) {
     27 	for _, want := range []string{
     28 		"package p",
     29 		"package p; type _ = int; type T1 = struct{}; type ( _ = *struct{}; T2 = float32 )",
     30 		// TODO(gri) expand
     31 	} {
     32 		ast, err := ParseBytes(nil, []byte(want), nil, nil, nil, 0)
     33 		if err != nil {
     34 			t.Error(err)
     35 			continue
     36 		}
     37 		if got := String(ast); got != want {
     38 			t.Errorf("%q: got %q", want, got)
     39 		}
     40 	}
     41 }
     42