예제 #1
0
// TestLineComments, using a simple test case, checks that consequtive line
// comments are properly terminated with a newline even if the AST position
// information is incorrect.
//
func TestLineComments(t *testing.T) {
	const src = `// comment 1
	// comment 2
	// comment 3
	package main
	`

	fset := token.NewFileSet()
	ast1, err1 := parser.ParseFile(fset, "", src, parser.ParseComments)
	if err1 != nil {
		panic(err1)
	}

	var buf bytes.Buffer
	fset = token.NewFileSet() // use the wrong file set
	printer.Fprint(&buf, fset, ast1)

	nlines := 0
	for _, ch := range buf.Bytes() {
		if ch == '\n' {
			nlines++
		}
	}

	const expected = 3
	if nlines < expected {
		t.Errorf("got %d, expected %d\n", nlines, expected)
	}
}
예제 #2
0
파일: main.go 프로젝트: serussell/kgc
func main() {

	goopt.Version = fmt.Sprintf("%d.%d", VER_MAJOR, VER_MINOR)
	goopt.Summary = PROG_NAME
	goopt.Parse(nil)

	if *ver {
		fmt.Printf("\n%s version %d.%d", PROG_NAME, VER_MAJOR, VER_MINOR)
		fmt.Printf("\nCopyright (c) 2011 Chanwit Kaewkasi / SUT\n\n")
		return
	}

	var filename string = ""
	if len(goopt.Args) == 1 {
		filename = goopt.Args[0]
	} else {
		fmt.Print(goopt.Usage())
		return
	}

	fset := token.NewFileSet()
	astf, err := parser.ParseFile(fset, filename, nil, 0)
	if err == nil {
		v := NewVisitor(astf)
		Walk(v, astf)
		tempfile, err := os.OpenFile(filename+"k", os.O_WRONLY|os.O_CREATE, 0665)
		if err == nil {
			printer.Fprint(tempfile, fset, astf)
			tempfile.Close()
			newArgs := make([]string, len(os.Args))
			copy(newArgs, os.Args)
			for i, v := range newArgs {
				if v == filename {
					newArgs[i] = filename + "k"
				}
			}
			gc := "8g"
			switch os.Getenv("GOARCH") {
			case "386":
				gc = "8g"
			case "amd64":
				gc = "6g"
			case "arm":
				gc = "5g"
			}
			newArgs[0] = os.Getenv("GOROOT") + "/bin/" + gc
			StdExecve(newArgs, true)
			os.Remove(filename + "k")
		}
	} else {
		fmt.Printf("%s\n", err)
	}
}