<commit_before>package context

import (
	"io"
	"strings"
	"testing"

	"github.com/spf13/afero"
	"github.com/stretchr/testify/assert"
)

type testFile struct {
	Path    string
	Content io.Reader
}

func TestAcquireMainLanguageForFile(t *testing.T) {
	testCases := []struct {
		name           string
		withFile       testFile
		expectLanguage string
	}{
		{
			name: "Should work with golang files",
			withFile: testFile{
				Path:    "/main.go",
				Content: strings.NewReader("package main\nfunc main() {}"),
			},
			expectLanguage: "golang",
		},
		{
			name: "Should work with java files",
			withFile: testFile{
				Path:    "/main.java",
				Content: strings.NewReader("public static void main() {}"),
			},
			expectLanguage: "java",
		},
	}

	for _, tc := range testCases {
		tc := tc

		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()

			fs := &afero.Afero{Fs: afero.NewMemMapFs()}

			fs.WriteReader(tc.withFile.Path, tc.withFile.Content)

			language, err := acquireMainLanguageForFile(fs, tc.withFile.Path)
			assert.NoError(t, err)

			assert.Equal(t, tc.expectLanguage, language)
		})
	}
}
<commit_msg>✅ Add failing main language for dir tests<commit_after>package context

import (
	"io"
	"strings"
	"testing"

	"github.com/spf13/afero"
	"github.com/stretchr/testify/assert"
)

type testFile struct {
	Path    string
	Content io.Reader
}

func TestAcquireMainLanguageForFile(t *testing.T) {
	testCases := []struct {
		name           string
		withFile       testFile
		expectLanguage string
	}{
		{
			name: "Should work with golang files",
			withFile: testFile{
				Path:    "/main.go",
				Content: strings.NewReader("package main\nfunc main() {}"),
			},
			expectLanguage: "golang",
		},
		{
			name: "Should work with java files",
			withFile: testFile{
				Path:    "/main.java",
				Content: strings.NewReader("public static void main() {}"),
			},
			expectLanguage: "java",
		},
	}

	for _, tc := range testCases {
		tc := tc

		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()

			fs := &afero.Afero{Fs: afero.NewMemMapFs()}

			fs.WriteReader(tc.withFile.Path, tc.withFile.Content)

			language, err := acquireMainLanguageForFile(fs, tc.withFile.Path)
			assert.NoError(t, err)

			assert.Equal(t, tc.expectLanguage, language)
		})
	}
}

func TestAcquireMainLanguageForDir(t *testing.T) {
	testCases := []struct {
		name           string
		withFiles      []testFile
		expectLanguage string
	}{
		{
			name: "Should return golang with only golang files",
			withFiles: []testFile{
				{
					Path:    "/main.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/tests.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/types.go",
					Content: strings.NewReader("package main"),
				},
			},
			expectLanguage: "golang",
		},
		{
			name: "Should return golang with mostly golang files",
			withFiles: []testFile{
				{
					Path:    "/main.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/tests.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/Makefile",
					Content: strings.NewReader(".PHONY: all"),
				},
			},
			expectLanguage: "golang",
		},
		{
			name: "Should return golang with 3/5 files being golang",
			withFiles: []testFile{
				{
					Path:    "/monitor.java",
					Content: strings.NewReader("public static void main() {}"),
				},
				{
					Path:    "/main.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/tests.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/types.go",
					Content: strings.NewReader("package main"),
				},
				{
					Path:    "/lib.java",
					Content: strings.NewReader("public static void main() {}"),
				},
			},
			expectLanguage: "golang",
		},
	}

	for _, tc := range testCases {
		tc := tc

		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()

			fs := &afero.Afero{Fs: afero.NewMemMapFs()}

			for _, item := range tc.withFiles {
				err := fs.WriteReader(item.Path, item.Content)
				assert.NoError(t, err)
			}

			language, err := acquireMainLanguageForDir(fs, "/")
			assert.NoError(t, err)

			assert.Equal(t, tc.expectLanguage, language)
		})
	}
}

{'fraction_non_alphanumeric': 0.15192262326020287, 'fraction_numerical': 0.0014154281670205238, 'mean_word_length': 2.752212389380531, 'pattern_counts': {'":': 0, '<': 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': '2637814', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1484, 'n_words': 310}