<commit_before>package tesls

import (
	"go/ast"
	"go/parser"
	"go/token"
	"os"
	"sort"
	"strings"
)

// Test describes a single test found in the *_test.go file
type Test struct {
	Name string `json:"name"`
	File string `json:"file"`
	Pkg  string `json:"pkg"`
}

// Format returns Test struct as a string in the given format.
// It can be any string in which %P will turn into package name,
// %T into test name, and %F into file path in which test was found.
// Note that it is not required to use all three placeholders.
func (t *Test) Format(format string) string {
	return strings.NewReplacer("%P", t.Pkg, "%T", t.Name, "%F", t.File).Replace(format)
}

// String returns a string representation of the Test
// in the form of 'package.Test filename'
func (t *Test) String() string {
	return t.Format("%P.%T %F")
}

// TestSlice attaches the methods of sort.Interface to []Test.
// Sorting in increasing order comparing package+testname.
type TestSlice []Test

func (s TestSlice) Len() int           { return len(s) }
func (s TestSlice) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s TestSlice) Less(i, j int) bool { return s[i].Pkg+s[i].Name < s[j].Pkg+s[j].Name }

// Sort is a convenience method.
func (s TestSlice) Sort() { sort.Sort(s) }

func filter(fi os.FileInfo) bool {
	return strings.HasSuffix(fi.Name(), "_test.go")
}

// Tests function searches for test function declarations in the given directory.
func Tests(dir string) (tests TestSlice, err error) {
	fset := token.NewFileSet()
	pkgs, err := parser.ParseDir(fset, dir, filter, parser.Mode(0))
	if err != nil {
		return nil, err
	}
	for _, pkg := range pkgs {
		for filename, file := range pkg.Files {
			for _, decl := range file.Decls {
				fdec, ok := decl.(*ast.FuncDecl)
				if ok && strings.HasPrefix(fdec.Name.String(), "Test") {
					tests = append(tests, Test{
						Name: fdec.Name.String(),
						File: filename,
						Pkg:  pkg.Name,
					})
				}
			}
		}
	}
	return tests, nil
}
<commit_msg>tesls: add function's parameters check<commit_after>package tesls

import (
	"go/ast"
	"go/parser"
	"go/token"
	"os"
	"sort"
	"strings"

	"golang.org/x/tools/go/types"
)

// Test describes a single test found in the *_test.go file
type Test struct {
	Name string `json:"name"`
	File string `json:"file"`
	Pkg  string `json:"pkg"`
}

// Format returns Test struct as a string in the given format.
// It can be any string in which %P will turn into package name,
// %T into test name, and %F into file path in which test was found.
// Note that it is not required to use all three placeholders.
func (t *Test) Format(format string) string {
	return strings.NewReplacer("%P", t.Pkg, "%T", t.Name, "%F", t.File).Replace(format)
}

// String returns a string representation of the Test
// in the form of 'package.Test filename'
func (t *Test) String() string {
	return t.Format("%P.%T %F")
}

// TestSlice attaches the methods of sort.Interface to []Test.
// Sorting in increasing order comparing package+testname.
type TestSlice []Test

func (s TestSlice) Len() int           { return len(s) }
func (s TestSlice) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s TestSlice) Less(i, j int) bool { return s[i].Pkg+s[i].Name < s[j].Pkg+s[j].Name }

// Sort is a convenience method.
func (s TestSlice) Sort() { sort.Sort(s) }

func filter(fi os.FileInfo) bool {
	return strings.HasSuffix(fi.Name(), "_test.go")
}

func isTest(fdecl *ast.FuncDecl) bool {
	return strings.HasPrefix(fdecl.Name.String(), "Test") &&
		fdecl.Type != nil &&
		fdecl.Type.Params != nil &&
		len(fdecl.Type.Params.List) == 1 &&
		types.ExprString(fdecl.Type.Params.List[0].Type) == "*testing.T"
}

// Tests function searches for test function declarations in the given directory.
func Tests(dir string) (tests TestSlice, err error) {
	fset := token.NewFileSet()
	pkgs, err := parser.ParseDir(fset, dir, filter, parser.Mode(0))
	if err != nil {
		return nil, err
	}
	for _, pkg := range pkgs {
		for filename, file := range pkg.Files {
			for _, decl := range file.Decls {
				fdecl, ok := decl.(*ast.FuncDecl)
				if ok && isTest(fdecl) {
					tests = append(tests, Test{
						Name: fdecl.Name.String(),
						File: filename,
						Pkg:  pkg.Name,
					})
				}
			}
		}
	}
	return tests, nil
}

{'fraction_non_alphanumeric': 0.14722483537158984, 'fraction_numerical': 0.0009407337723424271, 'mean_word_length': 3.375514403292181, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1474353', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1470, 'n_words': 499}