Exemple #1
0
func astFromInput(input string) (*token.FileSet, *ast.File) {
	fileSet := token.NewFileSet()
	astFile, err := parser.ParseFile(fileSet, "", input, parser.ParseComments)
	util.PanicOnError(err)

	return fileSet, astFile
}
Exemple #2
0
func astFromFile(filename string) (*token.FileSet, *ast.File) {
	fileSet := token.NewFileSet()
	astFile, err := parser.ParseFile(fileSet, filename, nil, parser.ParseComments)
	util.PanicOnError(err)

	return fileSet, astFile
}
Exemple #3
0
func toInt(s string) int {
	i, err := strconv.Atoi(s)
	util.PanicOnError(err)
	return i
}
Exemple #4
0
// This is a workaround for the current way of creating test cases.
// A better way could be to actually move the test cases back into this file
// instead of looping automatically through all test files.
var focusedTests = map[string]bool{
// "for_statement_withing_case_block": true,
}

var pendingTests = map[string]bool{
	"multiple_simple_statements_taking_parameters_declared_beforehand_changed_within_and_used_afterwards": true,
	"comments_in_statements":                true,
	"comments_outside_extracted_statements": true,
}

var _ = Describe("Goextract", func() {
	fileInfos, err := ioutil.ReadDir("test_data")
	util.PanicOnError(err)
	for _, fileInfo := range fileInfos {
		filename := fileInfo.Name()
		if !strings.HasSuffix(filename, ".go.input") {
			continue
		}
		prefix := strings.TrimSuffix(filename, ".go.input")

		it := It
		if pendingTests[filepath.Base(prefix)] {
			// TODO ideally this would use PIt to do better reporting, but it actually
			// has a differnt method signature.
			continue
		}
		if focusedTests[filepath.Base(prefix)] {
			it = FIt
Exemple #5
0
func stringFrom(fileSet *token.FileSet, astFile *ast.File) string {
	buf := new(bytes.Buffer)
	err := printer.Fprint(buf, fileSet, astFile)
	util.PanicOnError(err)
	return buf.String()
}
Exemple #6
0
func createAstFileDump(filename string, fileSet *token.FileSet, astFile *ast.File) {
	file, err := os.Create(filename)
	util.PanicOnError(err)
	defer file.Close()
	ast.Fprint(file, fileSet, astFile, ast.NotNilFilter)
}