<commit_before>package srcscan

import (
	"github.com/kr/pretty"
	"reflect"
	"sort"
	"testing"
)

func TestScan(t *testing.T) {
	type scanTest struct {
		config *Config
		dir    string
		units  []Unit
	}
	tests := []scanTest{
		{
			dir: "testdata",
			units: []Unit{
				&GoPackage{DirUnit{"testdata/go/cmd/mycmd"}},
				&GoPackage{DirUnit{"testdata/go/qux"}},
				&GoPackage{DirUnit{"testdata/go"}},
				&NodeJSPackage{
					DirUnit:        DirUnit{Dir: "testdata/node.js"},
					PackageJSON:    []byte(`{"name": "mypkg"}` + "\n"),
					LibFiles:       []string{"a.js", "lib/a.js"},
					TestFiles:      []string{"a_test.js", "test/b.js", "test/c_test.js"},
					VendorFiles:    []string{"vendor/a.js"},
					GeneratedFiles: []string{"a.min.js", "dist/a.js"},
				},
				&NodeJSPackage{
					DirUnit:     DirUnit{Dir: "testdata/node.js/subpkg"},
					PackageJSON: []byte(`{"name": "subpkg"}` + "\n"),
					LibFiles:    []string{"a.js"},
				},
				&PythonPackage{DirUnit{"testdata/python/mypkg"}},
				&PythonPackage{DirUnit{"testdata/python/mypkg/qux"}},
			},
		},
	}
	for _, test := range tests {
		// Use default config if config is nil.
		var config Config
		if test.config != nil {
			config = *test.config
		} else {
			config = Default
		}

		units, err := config.Scan(test.dir)
		if err != nil {
			t.Errorf("got error %q", err)
			continue
		}

		sort.Sort(Units(units))
		sort.Sort(Units(test.units))
		if !reflect.DeepEqual(test.units, units) {
			t.Errorf("units:\n%v", pretty.Diff(test.units, units))
			if len(test.units) == len(units) {
				for i := range test.units {
					if !reflect.DeepEqual(test.units[i], units[i]) {
						t.Errorf("units[%d]:\n%v", i, pretty.Diff(test.units[i], units[i]))
					}
				}
			}
		}
	}
}<commit_msg>Show expectation diffs on separate line<commit_after>package srcscan

import (
	"github.com/kr/pretty"
	"reflect"
	"sort"
	"testing"
)

func TestScan(t *testing.T) {
	type scanTest struct {
		config *Config
		dir    string
		units  []Unit
	}
	tests := []scanTest{
		{
			dir: "testdata",
			units: []Unit{
				&GoPackage{DirUnit{"testdata/go/cmd/mycmd"}},
				&GoPackage{DirUnit{"testdata/go/qux"}},
				&GoPackage{DirUnit{"testdata/go"}},
				&NodeJSPackage{
					DirUnit:        DirUnit{Dir: "testdata/node.js"},
					PackageJSON:    []byte(`{"name": "mypkg"}` + "\n"),
					LibFiles:       []string{"a.js", "lib/a.js"},
					TestFiles:      []string{"a_test.js", "test/b.js", "test/c_test.js"},
					VendorFiles:    []string{"vendor/a.js"},
					GeneratedFiles: []string{"a.min.js", "dist/a.js"},
				},
				&NodeJSPackage{
					DirUnit:     DirUnit{Dir: "testdata/node.js/subpkg"},
					PackageJSON: []byte(`{"name": "subpkg"}` + "\n"),
					LibFiles:    []string{"a.js"},
				},
				&PythonPackage{DirUnit{"testdata/python/mypkg"}},
				&PythonPackage{DirUnit{"testdata/python/mypkg/qux"}},
			},
		},
	}
	for _, test := range tests {
		// Use default config if config is nil.
		var config Config
		if test.config != nil {
			config = *test.config
		} else {
			config = Default
		}

		units, err := config.Scan(test.dir)
		if err != nil {
			t.Errorf("got error %q", err)
			continue
		}

		sort.Sort(Units(units))
		sort.Sort(Units(test.units))
		if !reflect.DeepEqual(test.units, units) {
			t.Errorf("units:\n%v", pretty.Diff(test.units, units))
			if len(test.units) == len(units) {
				for i := range test.units {
					if !reflect.DeepEqual(test.units[i], units[i]) {
						t.Errorf("units[%d]:\n%v", i, strings.Join(pretty.Diff(test.units[i], units[i]), "\n"))
					}
				}
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.1973536036036036, 'fraction_numerical': 0.0, 'mean_word_length': 3.0420932878270763, 'pattern_counts': {'":': 4, '<': 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': '1949307', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1342, 'n_words': 236}