<commit_before>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package parser

import (
	"go/ast";
	"go/parser";
	"os";
	"testing";
)


var illegalInputs = []interface{} {
	nil,
	3.14,
	[]byte(nil),
	"foo!",
}


func TestParseIllegalInputs(t *testing.T) {
	for _, src := range illegalInputs {
		prog, err := ParseFile("", src, 0);
		if err == nil {
			t.Errorf("ParseFile(%v) should have failed", src);
		}
	}
}


var validPrograms = []interface{} {
	`package main`,
	`package main import "fmt" func main() { fmt.Println("Hello, World!") }`,
}


func TestParseValidPrograms(t *testing.T) {
	for _, src := range validPrograms {
		prog, err := ParseFile("", src, 0);
		if err != nil {
			t.Errorf("ParseFile(%q): %v", src, err);
		}
	}
}


var validFiles = []string {
	"parser.go",
	"parser_test.go",
}


func TestParse3(t *testing.T) {
	for _, filename := range validFiles {
		prog, err := ParseFile(filename, nil, 0);
		if err != nil {
			t.Errorf("ParseFile(%s): %v", filename, err);
		}
	}
}


func filter(filename string) bool {
	switch filename {
	case "parser.go":
	case "interface.go":
	case "parser_test.go":
	default:
		return false;
	}
	return true;
}


func TestParse4(t *testing.T) {
	path := ".";
	pkg, err := ParsePackage(path, filter, 0);
	if err != nil {
		t.Errorf("ParsePackage(%s): %v", path, err);
	}
	if pkg.Name != "parser" {
		t.Errorf("incorrect package name: %s", pkg.Name);
	}
	for filename, _ := range pkg.Files {
		if !filter(filename) {
			t.Errorf("unexpected package file: %s", filename);
		}
	}
}<commit_msg>If we can't parse the package, call Fatalf so that the test fails without crashing.<commit_after>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package parser

import (
	"go/ast";
	"go/parser";
	"os";
	"testing";
)


var illegalInputs = []interface{} {
	nil,
	3.14,
	[]byte(nil),
	"foo!",
}


func TestParseIllegalInputs(t *testing.T) {
	for _, src := range illegalInputs {
		prog, err := ParseFile("", src, 0);
		if err == nil {
			t.Errorf("ParseFile(%v) should have failed", src);
		}
	}
}


var validPrograms = []interface{} {
	`package main`,
	`package main import "fmt" func main() { fmt.Println("Hello, World!") }`,
}


func TestParseValidPrograms(t *testing.T) {
	for _, src := range validPrograms {
		prog, err := ParseFile("", src, 0);
		if err != nil {
			t.Errorf("ParseFile(%q): %v", src, err);
		}
	}
}


var validFiles = []string {
	"parser.go",
	"parser_test.go",
}


func TestParse3(t *testing.T) {
	for _, filename := range validFiles {
		prog, err := ParseFile(filename, nil, 0);
		if err != nil {
			t.Errorf("ParseFile(%s): %v", filename, err);
		}
	}
}


func filter(filename string) bool {
	switch filename {
	case "parser.go":
	case "interface.go":
	case "parser_test.go":
	default:
		return false;
	}
	return true;
}


func TestParse4(t *testing.T) {
	path := ".";
	pkg, err := ParsePackage(path, filter, 0);
	if err != nil {
		t.Fatalf("ParsePackage(%s): %v", path, err);
	}
	if pkg.Name != "parser" {
		t.Errorf("incorrect package name: %s", pkg.Name);
	}
	for filename, _ := range pkg.Files {
		if !filter(filename) {
			t.Errorf("unexpected package file: %s", filename);
		}
	}
}
{'fraction_non_alphanumeric': 0.17348754448398576, 'fraction_numerical': 0.00771055753262159, 'mean_word_length': 3.595367847411444, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2625744', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1231, 'n_words': 354}