<commit_before>package plugin

import (
	"fmt"
	"testing"
)

const (
	originalManifest = "call remote#host#RegisterPlugin('P', '0', [\n\\ {'type': 'function', 'name': 'Foo', 'sync': 1, 'opts': {}},\n\\ ])\n"
	updatedManifest  = "call remote#host#RegisterPlugin('P', '0', [\n\\ {'type': 'function', 'name': 'Bar', 'sync': 1, 'opts': {}},\n\\ ])\n"
)

var replaceManifestTests = []struct {
	what, original, expected string
}{
	{
		"Original at beginning of file",
		fmt.Sprintf("%sline A\nline B\n", originalManifest),
		fmt.Sprintf("%sline A\nline B\n", updatedManifest),
	},
	{
		"Original in middle of file",
		fmt.Sprintf("line A\n%sline B\n", originalManifest),
		fmt.Sprintf("line A\n%sline B\n", updatedManifest),
	},
	{
		"Original at end of file",
		fmt.Sprintf("line A\nline B\n%s", originalManifest),
		fmt.Sprintf("line A\nline B\n%s", updatedManifest),
	},
	{
		"Original at end of file, no trailing \\n",
		fmt.Sprintf("line A\nline B\n%s", originalManifest[:len(originalManifest)-1]),
		fmt.Sprintf("line A\nline B\n%s", updatedManifest),
	},
	{
		"No manifest",
		"line A\nline B\n",
		fmt.Sprintf("line A\nline B\n%s", updatedManifest),
	},
	{
		"Empty file",
		"",
		updatedManifest,
	},
	{
		"No manifest, no trailing \\n",
		"line A\nline B",
		fmt.Sprintf("line A\nline B\n%s", updatedManifest),
	},
	{
		"Extra \\ ])` in file", // ensure non-greedy match trailing ])
		fmt.Sprintf("line A\n%sline B\n\\ ])\nline C\n", originalManifest),
		fmt.Sprintf("line A\n%sline B\n\\ ])\nline C\n", updatedManifest),
	},
}

func TestReplaceManifest(t *testing.T) {
	for _, tt := range replaceManifestTests {
		actual := string(replaceManifest("P", []byte(tt.original), []byte(updatedManifest)))
		if actual != tt.expected {
			t.Errorf("%s\n got = %q\nwant = %q", tt.what, actual, tt.expected)
			continue
		}
		// Replace should be idempotent.
		actual = string(replaceManifest("P", []byte(tt.expected), []byte(updatedManifest)))
		if actual != tt.expected {
			t.Errorf("%s (no change expected)\n got = %q\nwant = %q", tt.what, actual, tt.expected)
		}
	}
}<commit_msg>nvim/plugin: use sub-tests<commit_after>package plugin

import (
	"fmt"
	"testing"
)

const (
	originalManifest = "call remote#host#RegisterPlugin('P', '0', [\n\\ {'type': 'function', 'name': 'Foo', 'sync': 1, 'opts': {}},\n\\ ])\n"
	updatedManifest  = "call remote#host#RegisterPlugin('P', '0', [\n\\ {'type': 'function', 'name': 'Bar', 'sync': 1, 'opts': {}},\n\\ ])\n"
)

func TestReplaceManifest(t *testing.T) {
	t.Parallel()

	var replaceManifestTests = []struct {
		name     string
		original string
		expected string
	}{
		{
			name:     "Original at beginning of file",
			original: fmt.Sprintf("%sline A\nline B\n", originalManifest),
			expected: fmt.Sprintf("%sline A\nline B\n", updatedManifest),
		},
		{
			name:     "Original in middle of file",
			original: fmt.Sprintf("line A\n%sline B\n", originalManifest),
			expected: fmt.Sprintf("line A\n%sline B\n", updatedManifest),
		},
		{
			name:     "Original at end of file",
			original: fmt.Sprintf("line A\nline B\n%s", originalManifest),
			expected: fmt.Sprintf("line A\nline B\n%s", updatedManifest),
		},
		{
			name:     "Original at end of file, no trailing \\n",
			original: fmt.Sprintf("line A\nline B\n%s", originalManifest[:len(originalManifest)-1]),
			expected: fmt.Sprintf("line A\nline B\n%s", updatedManifest),
		},
		{
			name:     "No manifest",
			original: "line A\nline B\n",
			expected: fmt.Sprintf("line A\nline B\n%s", updatedManifest),
		},
		{
			name:     "Empty file",
			original: "",
			expected: updatedManifest,
		},
		{
			name:     "No manifest, no trailing \\n",
			original: "line A\nline B",
			expected: fmt.Sprintf("line A\nline B\n%s", updatedManifest),
		},
		{
			name:     "Extra \\ ])` in file", // ensure non-greedy match trailing ])
			original: fmt.Sprintf("line A\n%sline B\n\\ ])\nline C\n", originalManifest),
			expected: fmt.Sprintf("line A\n%sline B\n\\ ])\nline C\n", updatedManifest),
		},
	}
	for _, tt := range replaceManifestTests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()

			actual := string(replaceManifest("P", []byte(tt.original), []byte(updatedManifest)))
			if actual != tt.expected {
				t.Fatalf("%s\n got = %q\nwant = %q", tt.name, actual, tt.expected)
			}

			// Replace should be idempotent.
			actual = string(replaceManifest("P", []byte(tt.expected), []byte(updatedManifest)))
			if actual != tt.expected {
				t.Fatalf("%s (no change expected)\n got = %q\nwant = %q", tt.name, actual, tt.expected)
			}
		})
	}
}
{'fraction_non_alphanumeric': 0.1956140350877193, 'fraction_numerical': 0.0021929824561403508, 'mean_word_length': 3.630456852791878, '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': '2106956', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1673, 'n_words': 398}