github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/compile/internal/syntax/printer_test.go (about)

     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  	"strings"
    11  	"testing"
    12  )
    13  
    14  func TestPrint(t *testing.T) {
    15  	if testing.Short() {
    16  		t.Skip("skipping test in short mode")
    17  	}
    18  
    19  	// provide a dummy error handler so parsing doesn't stop after first error
    20  	ast, err := ParseFile(*src_, func(error) {}, nil, 0)
    21  	if err != nil {
    22  		t.Error(err)
    23  	}
    24  
    25  	if ast != nil {
    26  		Fprint(os.Stdout, ast, true)
    27  		fmt.Println()
    28  	}
    29  }
    30  
    31  func TestPrintString(t *testing.T) {
    32  	for _, want := range []string{
    33  		"package p",
    34  		"package p; type _ = int; type T1 = struct{}; type ( _ = *struct{}; T2 = float32 )",
    35  		// TODO(gri) expand
    36  	} {
    37  		ast, err := Parse(nil, strings.NewReader(want), nil, nil, nil, 0)
    38  		if err != nil {
    39  			t.Error(err)
    40  			continue
    41  		}
    42  		if got := String(ast); got != want {
    43  			t.Errorf("%q: got %q", want, got)
    44  		}
    45  	}
    46  }